Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Łukasz Nowak
slapos.core
Commits
a1f378f7
Commit
a1f378f7
authored
Jun 14, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some whitespace/indent changes to please pep8
parent
314fd21e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
54 deletions
+56
-54
slapos/client.py
slapos/client.py
+9
-7
slapos/format.py
slapos/format.py
+39
-41
slapos/util.py
slapos/util.py
+8
-5
slapos/version.py
slapos/version.py
+0
-1
No files found.
slapos/client.py
View file @
a1f378f7
...
@@ -80,6 +80,7 @@ class ClientConfig(object):
...
@@ -80,6 +80,7 @@ class ClientConfig(object):
if
self
.
cert_file
:
if
self
.
cert_file
:
self
.
cert_file
=
os
.
path
.
expanduser
(
self
.
cert_file
)
self
.
cert_file
=
os
.
path
.
expanduser
(
self
.
cert_file
)
def
init
(
conf
):
def
init
(
conf
):
"""Initialize Slap instance, connect to server and create
"""Initialize Slap instance, connect to server and create
aliases to common software releases"""
aliases to common software releases"""
...
@@ -122,13 +123,13 @@ def do_request(conf, local):
...
@@ -122,13 +123,13 @@ def do_request(conf, local):
conf
.
software_url
=
local
[
conf
.
software_url
]
conf
.
software_url
=
local
[
conf
.
software_url
]
try
:
try
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
conf
.
software_url
,
software_release
=
conf
.
software_url
,
partition_reference
=
conf
.
reference
,
partition_reference
=
conf
.
reference
,
partition_parameter_kw
=
conf
.
parameters
,
partition_parameter_kw
=
conf
.
parameters
,
software_type
=
conf
.
type
,
software_type
=
conf
.
type
,
filter_kw
=
conf
.
node
,
filter_kw
=
conf
.
node
,
state
=
conf
.
state
,
state
=
conf
.
state
,
shared
=
conf
.
slave
shared
=
conf
.
slave
)
)
print
"Instance requested.
\
n
State is : %s."
%
partition
.
getState
()
print
"Instance requested.
\
n
State is : %s."
%
partition
.
getState
()
print
"Connection parameters of instance are:"
print
"Connection parameters of instance are:"
...
@@ -185,6 +186,7 @@ def do_console(local):
...
@@ -185,6 +186,7 @@ def do_console(local):
readline
.
parse_and_bind
(
"tab: complete"
)
readline
.
parse_and_bind
(
"tab: complete"
)
historyPath
=
os
.
path
.
expanduser
(
"~/.slapconsolehistory"
)
historyPath
=
os
.
path
.
expanduser
(
"~/.slapconsolehistory"
)
def
save_history
(
historyPath
=
historyPath
):
def
save_history
(
historyPath
=
historyPath
):
readline
.
write_history_file
(
historyPath
)
readline
.
write_history_file
(
historyPath
)
if
os
.
path
.
exists
(
historyPath
):
if
os
.
path
.
exists
(
historyPath
):
...
...
slapos/format.py
View file @
a1f378f7
...
@@ -79,8 +79,8 @@ class OS(object):
...
@@ -79,8 +79,8 @@ class OS(object):
def
_addWrapper
(
self
,
name
):
def
_addWrapper
(
self
,
name
):
def
wrapper
(
*
args
,
**
kw
):
def
wrapper
(
*
args
,
**
kw
):
arg_list
=
[
repr
(
x
)
for
x
in
args
]
+
[
arg_list
=
[
repr
(
x
)
for
x
in
args
]
+
[
'%s=%r'
%
(
x
,
y
)
for
x
,
y
in
kw
.
iteritems
()
'%s=%r'
%
(
x
,
y
)
for
x
,
y
in
kw
.
iteritems
()
]
]
self
.
_logger
.
debug
(
'%s(%s)'
%
(
name
,
', '
.
join
(
arg_list
)))
self
.
_logger
.
debug
(
'%s(%s)'
%
(
name
,
', '
.
join
(
arg_list
)))
if
not
self
.
_dry_run
:
if
not
self
.
_dry_run
:
getattr
(
self
.
_os
,
name
)(
*
args
,
**
kw
)
getattr
(
self
.
_os
,
name
)(
*
args
,
**
kw
)
...
@@ -177,11 +177,11 @@ def _getDict(obj):
...
@@ -177,11 +177,11 @@ def _getDict(obj):
return
obj
return
obj
return
{
return
{
key
:
_getDict
(
value
)
key
:
_getDict
(
value
)
for
key
,
value
in
dikt
.
iteritems
()
for
key
,
value
in
dikt
.
iteritems
()
# do not attempt to serialize logger: it is both useless and recursive.
# do not attempt to serialize logger: it is both useless and recursive.
if
not
isinstance
(
value
,
logging
.
Logger
)
if
not
isinstance
(
value
,
logging
.
Logger
)
}
}
class
Computer
(
object
):
class
Computer
(
object
):
...
@@ -307,7 +307,6 @@ class Computer(object):
...
@@ -307,7 +307,6 @@ class Computer(object):
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
fout
.
write
(
new_pretty_xml
)
fout
.
write
(
new_pretty_xml
)
def
backup_xml
(
self
,
path_to_archive
,
path_to_xml
):
def
backup_xml
(
self
,
path_to_archive
,
path_to_xml
):
"""
"""
Stores a copy of the current xml file to an historical archive.
Stores a copy of the current xml file to an historical archive.
...
@@ -318,7 +317,6 @@ class Computer(object):
...
@@ -318,7 +317,6 @@ class Computer(object):
with
zipfile
.
ZipFile
(
path_to_archive
,
'a'
)
as
archive
:
with
zipfile
.
ZipFile
(
path_to_archive
,
'a'
)
as
archive
:
archive
.
writestr
(
saved_filename
,
xml_content
,
zipfile
.
ZIP_DEFLATED
)
archive
.
writestr
(
saved_filename
,
xml_content
,
zipfile
.
ZIP_DEFLATED
)
@
classmethod
@
classmethod
def
load
(
cls
,
path_to_xml
,
reference
,
ipv6_interface
):
def
load
(
cls
,
path_to_xml
,
reference
,
ipv6_interface
):
"""
"""
...
@@ -336,11 +334,11 @@ class Computer(object):
...
@@ -336,11 +334,11 @@ class Computer(object):
# Reconstructing the computer object from the xml
# Reconstructing the computer object from the xml
computer
=
Computer
(
computer
=
Computer
(
reference
=
reference
,
reference
=
reference
,
addr
=
dumped_dict
[
'address'
],
addr
=
dumped_dict
[
'address'
],
netmask
=
dumped_dict
[
'netmask'
],
netmask
=
dumped_dict
[
'netmask'
],
ipv6_interface
=
ipv6_interface
,
ipv6_interface
=
ipv6_interface
,
software_user
=
dumped_dict
.
get
(
'software_user'
,
'slapsoft'
),
software_user
=
dumped_dict
.
get
(
'software_user'
,
'slapsoft'
),
)
)
for
partition_dict
in
dumped_dict
[
'partition_list'
]:
for
partition_dict
in
dumped_dict
[
'partition_list'
]:
...
@@ -358,11 +356,11 @@ class Computer(object):
...
@@ -358,11 +356,11 @@ class Computer(object):
address_list
=
partition_dict
[
'address_list'
]
address_list
=
partition_dict
[
'address_list'
]
partition
=
Partition
(
partition
=
Partition
(
reference
=
partition_dict
[
'reference'
],
reference
=
partition_dict
[
'reference'
],
path
=
partition_dict
[
'path'
],
path
=
partition_dict
[
'path'
],
user
=
user
,
user
=
user
,
address_list
=
address_list
,
address_list
=
address_list
,
tap
=
tap
,
tap
=
tap
,
)
)
computer
.
partition_list
.
append
(
partition
)
computer
.
partition_list
.
append
(
partition
)
...
@@ -725,12 +723,12 @@ class Interface(object):
...
@@ -725,12 +723,12 @@ class Interface(object):
interface_name
=
self
.
name
interface_name
=
self
.
name
try
:
try
:
address_list
=
[
address_list
=
[
q
q
for
q
in
netifaces
.
ifaddresses
(
interface_name
)[
socket
.
AF_INET6
]
for
q
in
netifaces
.
ifaddresses
(
interface_name
)[
socket
.
AF_INET6
]
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
]
]
except
KeyError
:
except
KeyError
:
raise
ValueError
(
"%s must have at least one IPv6 address assigned"
%
\
raise
ValueError
(
"%s must have at least one IPv6 address assigned"
%
interface_name
)
interface_name
)
if
sys
.
platform
==
'cygwin'
:
if
sys
.
platform
==
'cygwin'
:
for
q
in
address_list
:
for
q
in
address_list
:
...
@@ -838,8 +836,8 @@ class Interface(object):
...
@@ -838,8 +836,8 @@ class Interface(object):
while
try_num
>
0
:
while
try_num
>
0
:
addr
=
random
.
choice
([
q
for
q
in
netaddr
.
glob_to_iprange
(
addr
=
random
.
choice
([
q
for
q
in
netaddr
.
glob_to_iprange
(
netaddr
.
cidr_to_glob
(
self
.
ipv4_local_network
))]).
format
()
netaddr
.
cidr_to_glob
(
self
.
ipv4_local_network
))]).
format
()
if
dict
(
addr
=
addr
,
netmask
=
netmask
)
not
in
\
if
(
dict
(
addr
=
addr
,
netmask
=
netmask
)
not
in
self
.
getIPv4LocalAddressList
(
):
self
.
getIPv4LocalAddressList
()
):
# Checking the validity of the IPv6 address
# Checking the validity of the IPv6 address
if
self
.
_addSystemAddress
(
addr
,
netmask
,
False
):
if
self
.
_addSystemAddress
(
addr
,
netmask
,
False
):
return
dict
(
addr
=
addr
,
netmask
=
netmask
)
return
dict
(
addr
=
addr
,
netmask
=
netmask
)
...
@@ -926,8 +924,8 @@ class Interface(object):
...
@@ -926,8 +924,8 @@ class Interface(object):
addr
=
':'
.
join
(
address_dict
[
'addr'
].
split
(
':'
)[:
-
1
]
+
[
'%x'
%
(
addr
=
':'
.
join
(
address_dict
[
'addr'
].
split
(
':'
)[:
-
1
]
+
[
'%x'
%
(
random
.
randint
(
1
,
65000
),
)])
random
.
randint
(
1
,
65000
),
)])
socket
.
inet_pton
(
socket
.
AF_INET6
,
addr
)
socket
.
inet_pton
(
socket
.
AF_INET6
,
addr
)
if
dict
(
addr
=
addr
,
netmask
=
netmask
)
not
in
\
if
(
dict
(
addr
=
addr
,
netmask
=
netmask
)
not
in
self
.
getGlobalScopeAddressList
(
):
self
.
getGlobalScopeAddressList
()
):
# Checking the validity of the IPv6 address
# Checking the validity of the IPv6 address
if
self
.
_addSystemAddress
(
addr
,
netmask
):
if
self
.
_addSystemAddress
(
addr
,
netmask
):
return
dict
(
addr
=
addr
,
netmask
=
netmask
)
return
dict
(
addr
=
addr
,
netmask
=
netmask
)
...
@@ -947,8 +945,8 @@ def parse_computer_definition(conf, definition_path):
...
@@ -947,8 +945,8 @@ def parse_computer_definition(conf, definition_path):
netmask
=
None
netmask
=
None
if
computer_definition
.
has_option
(
'computer'
,
'address'
):
if
computer_definition
.
has_option
(
'computer'
,
'address'
):
address
,
netmask
=
computer_definition
.
get
(
'computer'
,
'address'
).
split
(
'/'
)
address
,
netmask
=
computer_definition
.
get
(
'computer'
,
'address'
).
split
(
'/'
)
if
conf
.
alter_network
and
conf
.
interface_name
is
not
None
\
if
(
conf
.
alter_network
and
conf
.
interface_name
is
not
None
and
conf
.
ipv4_local_network
is
not
None
:
and
conf
.
ipv4_local_network
is
not
None
)
:
interface
=
Interface
(
logger
=
conf
.
logger
,
interface
=
Interface
(
logger
=
conf
.
logger
,
name
=
conf
.
interface_name
,
name
=
conf
.
interface_name
,
ipv4_local_network
=
conf
.
ipv4_local_network
,
ipv4_local_network
=
conf
.
ipv4_local_network
,
...
@@ -960,7 +958,7 @@ def parse_computer_definition(conf, definition_path):
...
@@ -960,7 +958,7 @@ def parse_computer_definition(conf, definition_path):
netmask
=
netmask
,
netmask
=
netmask
,
ipv6_interface
=
conf
.
ipv6_interface
,
ipv6_interface
=
conf
.
ipv6_interface
,
software_user
=
computer_definition
.
get
(
'computer'
,
'software_user'
),
software_user
=
computer_definition
.
get
(
'computer'
,
'software_user'
),
)
)
partition_list
=
[]
partition_list
=
[]
for
partition_number
in
range
(
int
(
conf
.
partition_amount
)):
for
partition_number
in
range
(
int
(
conf
.
partition_amount
)):
section
=
'partition_%s'
%
partition_number
section
=
'partition_%s'
%
partition_number
...
@@ -1019,13 +1017,13 @@ def parse_computer_xml(conf, xml_path):
...
@@ -1019,13 +1017,13 @@ def parse_computer_xml(conf, xml_path):
for
i
in
range
(
existing_partition_amount
,
partition_amount
):
for
i
in
range
(
existing_partition_amount
,
partition_amount
):
# add new partitions
# add new partitions
partition
=
Partition
(
partition
=
Partition
(
reference
=
'%s%s'
%
(
conf
.
partition_base_name
,
i
),
reference
=
'%s%s'
%
(
conf
.
partition_base_name
,
i
),
path
=
os
.
path
.
join
(
conf
.
instance_root
,
'%s%s'
%
(
path
=
os
.
path
.
join
(
conf
.
instance_root
,
'%s%s'
%
(
conf
.
partition_base_name
,
i
)),
conf
.
partition_base_name
,
i
)),
user
=
User
(
'%s%s'
%
(
conf
.
user_base_name
,
i
)),
user
=
User
(
'%s%s'
%
(
conf
.
user_base_name
,
i
)),
address_list
=
None
,
address_list
=
None
,
tap
=
Tap
(
'%s%s'
%
(
conf
.
tap_base_name
,
i
))
tap
=
Tap
(
'%s%s'
%
(
conf
.
tap_base_name
,
i
))
)
)
computer
.
partition_list
.
append
(
partition
)
computer
.
partition_list
.
append
(
partition
)
return
computer
return
computer
...
@@ -1153,18 +1151,18 @@ class FormatConfig(object):
...
@@ -1153,18 +1151,18 @@ class FormatConfig(object):
def
setConfig
(
self
):
def
setConfig
(
self
):
# setup some nones
# setup some nones
for
parameter
in
[
'interface_name'
,
'partition_base_name'
,
'user_base_name'
,
for
parameter
in
[
'interface_name'
,
'partition_base_name'
,
'user_base_name'
,
'tap_base_name'
,
'ipv4_local_network'
,
'ipv6_interface'
]:
'tap_base_name'
,
'ipv4_local_network'
,
'ipv6_interface'
]:
if
getattr
(
self
,
parameter
,
None
)
is
None
:
if
getattr
(
self
,
parameter
,
None
)
is
None
:
setattr
(
self
,
parameter
,
None
)
setattr
(
self
,
parameter
,
None
)
# Backward compatibility
# Backward compatibility
if
not
getattr
(
self
,
"interface_name"
,
None
)
\
if
not
getattr
(
self
,
"interface_name"
,
None
)
\
and
getattr
(
self
,
"bridge_name"
,
None
):
and
getattr
(
self
,
"bridge_name"
,
None
):
setattr
(
self
,
"interface_name"
,
self
.
bridge_name
)
setattr
(
self
,
"interface_name"
,
self
.
bridge_name
)
self
.
logger
.
warning
(
'bridge_name option is deprecated and should be '
self
.
logger
.
warning
(
'bridge_name option is deprecated and should be '
'replaced by interface_name.'
)
'replaced by interface_name.'
)
if
not
getattr
(
self
,
"create_tap"
,
None
)
\
if
not
getattr
(
self
,
"create_tap"
,
None
)
\
and
getattr
(
self
,
"no_bridge"
,
None
):
and
getattr
(
self
,
"no_bridge"
,
None
):
setattr
(
self
,
"create_tap"
,
not
self
.
no_bridge
)
setattr
(
self
,
"create_tap"
,
not
self
.
no_bridge
)
self
.
logger
.
warning
(
'no_bridge option is deprecated and should be '
self
.
logger
.
warning
(
'no_bridge option is deprecated and should be '
'replaced by create_tap.'
)
'replaced by create_tap.'
)
...
...
slapos/util.py
View file @
a1f378f7
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
os
,
errno
import
errno
import
os
def
mkdir_p
(
path
,
mode
=
0o777
):
def
mkdir_p
(
path
,
mode
=
0o777
):
"""
\
"""
\
...
@@ -17,10 +19,11 @@ def mkdir_p(path, mode=0o777):
...
@@ -17,10 +19,11 @@ def mkdir_p(path, mode=0o777):
else
:
else
:
raise
raise
def
chownDirectory
(
path
,
uid
,
gid
):
def
chownDirectory
(
path
,
uid
,
gid
):
os
.
chown
(
path
,
uid
,
gid
)
os
.
chown
(
path
,
uid
,
gid
)
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
items
in
dirs
,
files
:
for
items
in
dirs
,
files
:
for
item
in
items
:
for
item
in
items
:
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
uid
,
gid
)
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
uid
,
gid
)
slapos/version.py
View file @
a1f378f7
version
=
'0.35.2-dev'
version
=
'0.35.2-dev'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment