Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Boxiang Sun
slapos.toolbox
Commits
31532fac
Commit
31532fac
authored
Aug 02, 2019
by
Bryton Lacquement
🚪
Committed by
Julien Muchembled
Aug 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove slapos.cloudmgr
parent
eaad8c02
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
0 additions
and
395 deletions
+0
-395
setup.py
setup.py
+0
-9
slapos/README.cloudmgr.rst
slapos/README.cloudmgr.rst
+0
-2
slapos/cloudmgr/__init__.py
slapos/cloudmgr/__init__.py
+0
-7
slapos/cloudmgr/cloudinterface.py
slapos/cloudmgr/cloudinterface.py
+0
-38
slapos/cloudmgr/cloudmgr.py
slapos/cloudmgr/cloudmgr.py
+0
-71
slapos/cloudmgr/destroy.py
slapos/cloudmgr/destroy.py
+0
-15
slapos/cloudmgr/getprivatekey.py
slapos/cloudmgr/getprivatekey.py
+0
-11
slapos/cloudmgr/getpubliciplist.py
slapos/cloudmgr/getpubliciplist.py
+0
-26
slapos/cloudmgr/lib.py
slapos/cloudmgr/lib.py
+0
-43
slapos/cloudmgr/list.py
slapos/cloudmgr/list.py
+0
-17
slapos/cloudmgr/start.py
slapos/cloudmgr/start.py
+0
-18
slapos/cloudmgr/stop.py
slapos/cloudmgr/stop.py
+0
-36
slapos/cloudmgr/update.py
slapos/cloudmgr/update.py
+0
-102
No files found.
setup.py
View file @
31532fac
...
...
@@ -37,10 +37,8 @@ setup(name=name,
'Flask'
,
# needed by servers
'atomize'
,
# needed by pubsub
'feedparser'
,
# needed by pubsub
'apache_libcloud>=0.4.0'
,
# needed by cloudmgr
'lockfile'
,
# used by equeue
'lxml'
,
# needed for xml parsing
'paramiko'
,
# needed by cloudmgr
'psutil'
,
# needed for playing with processes in portable way
'setuptools'
,
# namespaces
'slapos.core'
,
# as it provides library for slap
...
...
@@ -79,13 +77,6 @@ setup(name=name,
'check-feed-as-promise = slapos.checkfeedaspromise:main'
,
'check-apachedex-result = slapos.promise.check_apachedex_result:main'
,
'check-slow-queries-digest-result = slapos.promise.check_slow_queries_digest_result:main'
,
'clouddestroy = slapos.cloudmgr.destroy:main'
,
'cloudgetprivatekey = slapos.cloudmgr.getprivatekey:main'
,
'cloudgetpubliciplist = slapos.cloudmgr.getpubliciplist:main'
,
'cloudlist = slapos.cloudmgr.list:main'
,
'cloudmgr = slapos.cloudmgr.cloudmgr:main'
,
'cloudstart = slapos.cloudmgr.start:main'
,
'cloudstop = slapos.cloudmgr.stop:main'
,
'equeue = slapos.equeue:main'
,
'generatefeed = slapos.generatefeed:main'
,
'htpasswd = slapos.htpasswd:main'
,
...
...
slapos/README.cloudmgr.rst
deleted
100644 → 0
View file @
eaad8c02
cloudmgr
========
slapos/cloudmgr/__init__.py
deleted
100644 → 0
View file @
eaad8c02
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try
:
__import__
(
'pkg_resources'
).
declare_namespace
(
__name__
)
except
ImportError
:
from
pkgutil
import
extend_path
__path__
=
extend_path
(
__path__
,
__name__
)
slapos/cloudmgr/cloudinterface.py
deleted
100644 → 0
View file @
eaad8c02
from
update
import
update
from
destroy
import
destroy
from
start
import
start
from
stop
import
stop
from
list
import
uuidlist
from
getpubliciplist
import
getpubliciplist
class
NodeInterface
:
def
__init__
(
self
,
key
,
secret
,
service
,
location
,
node_uuid
=
None
,
ssh_key
=
None
):
self
.
key
=
key
self
.
location
=
location
self
.
node_uuid
=
node_uuid
self
.
ssh_key
=
ssh_key
self
.
secret
=
secret
self
.
service
=
service
def
update
(
self
,
image
,
size
,
security_group
):
result
=
update
(
self
.
key
,
self
.
secret
,
self
.
service
,
self
.
location
,
self
.
node_uuid
,
self
.
ssh_key
,
image
,
size
,
security_group
)
self
.
node_uuid
=
result
[
'node_uuid'
]
self
.
ssh_key
=
result
[
'ssh_key'
]
return
result
def
stop
(
self
):
stop
(
self
.
key
,
self
.
secret
,
self
.
service
,
self
.
node_uuid
,
self
.
ssh_key
)
def
start
(
self
):
start
(
self
.
key
,
self
.
secret
,
self
.
service
,
self
.
node_uuid
)
def
destroy
(
self
):
destroy
(
self
.
key
,
self
.
secret
,
self
.
service
,
self
.
node_uuid
)
def
getPublicIpList
(
self
):
return
getpubliciplist
(
self
.
key
,
self
.
secret
,
self
.
service
,
self
.
node_uuid
)
def
getNodeUuidList
(
self
):
return
uuidlist
(
self
.
key
,
self
.
secret
,
self
.
service
)
slapos/cloudmgr/cloudmgr.py
deleted
100644 → 0
View file @
eaad8c02
import
sys
import
time
from
cloudinterface
import
NodeInterface
class
CloudManager
:
def
__init__
(
self
,
configuration_file
):
self
.
configuration_file
=
configuration_file
self
.
initialiseConfiguration
()
def
initialiseConfiguration
(
self
):
self
.
configuration_dict
=
{}
try
:
external_eval
=
file
(
self
.
configuration_file
).
read
()
except
IOError
:
pass
else
:
try
:
self
.
configuration_dict
=
eval
(
external_eval
)
except
:
pass
if
type
(
self
.
configuration_dict
)
!=
type
({}):
self
.
configuration_dict
=
{}
for
k
in
'key'
,
'secret'
:
if
k
not
in
self
.
configuration_dict
:
self
.
configuration_dict
[
k
]
=
''
elif
type
(
self
.
configuration_dict
[
k
])
!=
type
(
''
):
self
.
configuration_dict
[
k
]
=
''
if
'node_list'
not
in
self
.
configuration_dict
:
self
.
configuration_dict
[
'node_list'
]
=
[]
if
type
(
self
.
configuration_dict
[
'node_list'
])
!=
type
([]):
self
.
configuration_dict
[
'node_list'
]
=
[]
def
run
(
self
):
print
'Run begin...'
started
=
stopped
=
destroyed
=
unsupported
=
0
self
.
key
=
self
.
configuration_dict
[
'key'
]
self
.
secret
=
self
.
configuration_dict
[
'secret'
]
for
node
in
self
.
configuration_dict
[
'node_list'
]:
node_object
=
NodeInterface
(
self
.
key
,
self
.
secret
,
node
[
'service'
],
node
[
'location'
],
node
[
'node_uuid'
],
node
[
'ssh_key'
])
if
node
[
'requested_state'
]
==
'started'
:
print
'Starting %r'
%
node
[
'node_uuid'
]
if
node_object
.
start
():
started
+=
1
else
:
unsupported
+=
1
elif
node
[
'requested_state'
]
==
'stopped'
:
print
'Stopping %r'
%
node
[
'node_uuid'
]
if
node_object
.
stop
():
stopped
+=
1
else
:
unsupported
+=
1
elif
node
[
'requested_state'
]
==
'destroyed'
:
print
'Destroying %r'
%
node
[
'node_uuid'
]
if
node_object
.
destroy
():
destroyed
+=
1
else
:
unsupported
+=
1
else
:
print
'Unsupported state %r for node %r'
%
(
node
[
'requested_state'
],
node
[
'node_uuid'
])
unsupported
+=
1
print
'Run finished'
,
dict
(
started
=
started
,
stopped
=
stopped
,
destroyed
=
destroyed
,
unsupported
=
unsupported
)
def
main
():
while
True
:
CloudManager
(
sys
.
argv
[
1
]).
run
()
time
.
sleep
(
5
)
slapos/cloudmgr/destroy.py
deleted
100644 → 0
View file @
eaad8c02
from
slapos.cloudmgr.lib
import
getDriverInstance
,
getNode
from
libcloud.types
import
NodeState
import
sys
def
destroy
(
key
,
secret
,
service
,
node_uuid
):
driver
=
getDriverInstance
(
service
,
key
,
secret
)
node
=
getNode
(
driver
,
node_uuid
)
if
node
is
None
:
return
False
if
node
.
state
in
[
NodeState
.
RUNNING
,
NodeState
.
REBOOTING
,
NodeState
.
PENDING
]:
return
node
.
destroy
()
else
:
return
False
def
main
():
print
destroy
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
slapos/cloudmgr/getprivatekey.py
deleted
100644 → 0
View file @
eaad8c02
import
sys
def
getprivatekey
(
key
,
secret
,
service
,
node_uuid
):
"""Fetches private key of node"""
raise
NotImplementedError
(
'Cedric implement'
)
return
dict
(
ssh_key
=
ssh_key
,
)
def
main
():
getprivatekey
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
slapos/cloudmgr/getpubliciplist.py
deleted
100644 → 0
View file @
eaad8c02
from
slapos.cloudmgr.lib
import
getDriverInstance
,
getNode
from
libcloud.types
import
NodeState
import
time
import
sys
def
getpubliciplist
(
key
,
secret
,
service
,
node_uuid
):
"""Gets public ip(s), can wait for the first IP to appear"""
public_ip_list
=
[]
for
i
in
range
(
100
):
driver
=
getDriverInstance
(
service
,
key
,
secret
)
node
=
getNode
(
driver
,
node_uuid
)
if
node
.
state
not
in
[
NodeState
.
RUNNING
,
NodeState
.
REBOOTING
,
NodeState
.
PENDING
]:
break
if
node
.
public_ip
[
0
]:
public_ip_list
=
node
.
public_ip
break
else
:
time
.
sleep
(
5
)
return
dict
(
public_ip_list
=
public_ip_list
)
def
main
():
print
getpubliciplist
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
slapos/cloudmgr/lib.py
deleted
100644 → 0
View file @
eaad8c02
from
libcloud.types
import
Provider
from
libcloud.providers
import
get_driver
import
paramiko
import
StringIO
driver_list
=
{
'DUMMY'
:
get_driver
(
Provider
.
DUMMY
),
'EC2_US_EAST'
:
get_driver
(
Provider
.
EC2_US_EAST
),
'EC2_US_WEST'
:
get_driver
(
Provider
.
EC2_US_WEST
),
'EC2_EU_WEST'
:
get_driver
(
Provider
.
EC2_EU_WEST
),
'RACKSPACE'
:
get_driver
(
Provider
.
RACKSPACE
),
'SLICEHOST'
:
get_driver
(
Provider
.
SLICEHOST
),
'GOGRID'
:
get_driver
(
Provider
.
GOGRID
),
'VPSNET'
:
get_driver
(
Provider
.
VPSNET
),
'LINODE'
:
get_driver
(
Provider
.
LINODE
),
'VCLOUD'
:
get_driver
(
Provider
.
VCLOUD
),
'RIMUHOSTING'
:
get_driver
(
Provider
.
RIMUHOSTING
),
'ECP'
:
get_driver
(
Provider
.
ECP
),
'IBM'
:
get_driver
(
Provider
.
IBM
),
'OPENNEBULA'
:
get_driver
(
Provider
.
OPENNEBULA
),
'DREAMHOST'
:
get_driver
(
Provider
.
DREAMHOST
),
}
def
getDriverInstance
(
driverName
,
key
,
secret
=
None
,
secure
=
True
,
host
=
None
,
port
=
None
):
return
driver_list
.
get
(
driverName
)(
key
,
secret
,
secure
,
host
,
port
)
def
getSSHConnection
(
driver
,
hostname
,
private_key
):
client
=
paramiko
.
SSHClient
()
client
.
load_system_host_keys
()
client
.
set_missing_host_key_policy
(
paramiko
.
WarningPolicy
())
#TODO if exception : try DSSKey
pkey
=
paramiko
.
RSAKey
.
from_private_key
(
StringIO
.
StringIO
(
private_key
))
client
.
connect
(
hostname
=
hostname
,
username
=
'root'
,
pkey
=
pkey
,
look_for_keys
=
False
)
return
client
def
getNode
(
driver
,
node_uuid
):
node_list
=
[
node
for
node
in
driver
.
list_nodes
()
if
node_uuid
in
node
.
uuid
]
if
len
(
node_list
)
==
0
:
return
None
if
len
(
node_list
)
!=
1
:
raise
IndexError
(
'Several nodes with the uuid %r exist.'
%
node_uuid
)
return
node_list
[
0
]
slapos/cloudmgr/list.py
deleted
100644 → 0
View file @
eaad8c02
# Original work by Cedric de Saint Martin, adapted by Lukasz Nowak
import
sys
from
slapos.cloudmgr.lib
import
getDriverInstance
def
nodelist
(
key
,
secret
,
service
):
driver
=
getDriverInstance
(
service
,
key
,
secret
)
node_list
=
driver
.
list_nodes
()
return
node_list
def
uuidlist
(
key
,
secret
,
service
):
return
[
q
.
uuid
for
q
in
nodelist
(
key
,
secret
,
service
)]
def
main
():
node_list
=
nodelist
(
*
sys
.
argv
[
1
:])
print
'Available nodes (%s):'
%
len
(
node_list
)
for
node
in
node_list
:
print
node
slapos/cloudmgr/start.py
deleted
100644 → 0
View file @
eaad8c02
from
slapos.cloudmgr.lib
import
getDriverInstance
,
getNode
import
sys
def
start
(
key
,
secret
,
service
,
node_uuid
):
"""Starts node"""
driver
=
getDriverInstance
(
service
,
key
,
secret
)
node
=
getNode
(
driver
,
node_uuid
)
if
node
is
None
:
return
False
if
node
.
state
in
[
0
,
1
]:
return
True
elif
node
.
state
==
3
:
return
node
.
reboot
()
else
:
return
False
return
True
def
main
():
print
start
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
slapos/cloudmgr/stop.py
deleted
100644 → 0
View file @
eaad8c02
from
getprivatekey
import
getprivatekey
from
libcloud.types
import
NodeState
from
slapos.cloudmgr.lib
import
getDriverInstance
,
getSSHConnection
,
getNode
from
paramiko
import
SSHException
import
sys
def
stop
(
key
,
secret
,
service
,
node_uuid
,
ssh_key
=
None
):
"""Stops node"""
driver
=
getDriverInstance
(
service
,
key
,
secret
)
node
=
getNode
(
driver
,
node_uuid
)
# Checks state
if
node
.
state
not
in
[
NodeState
.
RUNNING
,
NodeState
.
REBOOTING
,
NodeState
.
PENDING
]:
return
False
# Good state : connects
if
ssh_key
is
None
:
ssh_key
=
getprivatekey
(
key
,
secret
,
service
,
node_uuid
)
public_ip
=
node
.
public_ip
[
0
]
if
not
public_ip
:
raise
Exception
(
'Node is started but has no IP.'
)
try
:
ssh
=
getSSHConnection
(
driver
,
public_ip
,
ssh_key
)
print
(
'Stopping instance...'
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
'halt'
)
except
SSHException
,
e
:
print
(
'unable to stop'
)
raise
e
error_log
=
stderr
.
read
()
if
error_log
:
raise
Exception
(
'''Unable to stop : error log is :
%r
output is : %r'''
%
(
error_log
,
stdout
.
read
()))
return
True
def
main
():
print
stop
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
slapos/cloudmgr/update.py
deleted
100644 → 0
View file @
eaad8c02
from
slapos.cloudmgr.lib
import
getDriverInstance
import
sys
import
uuid
from
libcloud.types
import
NodeState
def
update
(
key
,
secret
,
service
,
location
,
node_uuid
=
None
,
ssh_key
=
None
,
image
=
None
,
size
=
None
,
security_group
=
None
):
"""Update or create node"""
if
node_uuid
is
not
None
:
driver
=
getDriverInstance
(
service
,
key
,
secret
)
found_node_list
=
[
node
for
node
in
driver
.
list_nodes
()
if
node
.
uuid
==
node_uuid
]
if
len
(
found_node_list
)
==
0
:
# node_uuid relates to not available one, recreate
node_uuid
=
None
elif
len
(
found_node_list
)
==
1
:
node
=
found_node_list
[
0
]
if
node
.
state
not
in
[
NodeState
.
RUNNING
,
NodeState
.
REBOOTING
,
NodeState
.
PENDING
]:
# node_uuid relates to destroyed one, recreate
node_uuid
=
None
if
not
node_uuid
:
if
not
image
or
not
size
or
not
location
:
raise
Exception
(
"Node can not be created because of lacking informations"
)
# XXX-Cedric : what exception?
# Creates node
return
install
(
key
,
secret
,
service
,
image
,
size
,
location
,
security_group
)
else
:
return
dict
(
ssh_key
=
ssh_key
,
node_uuid
=
node_uuid
)
def
install
(
key
,
secret
,
service
,
image_id
,
size_id
,
location_id
,
security_group
):
driver
=
getDriverInstance
(
service
,
key
,
secret
)
# Defines a dict that will be used to create our node(s)
argument_list
=
dict
()
argument_list
[
'image'
]
=
[
image
for
image
in
driver
.
list_images
()
if
image_id
in
image
.
id
][
0
]
argument_list
[
'size'
]
=
[
size
for
size
in
driver
.
list_sizes
()
if
size_id
in
size
.
id
][
0
]
# We can create uour own images and sizes
#image = NodeImage(id=self.options['image_id'],
# name=self.options['image_name'],
# driver=driver)
#size = NodeSize(self.options['size_id'], self.options['size_name'], None,
# None, None, None, driver=driver)
argument_list
[
'location'
]
=
[
location
for
location
in
driver
.
list_locations
()
if
location_id
in
location
.
id
][
0
]
# If we are in ec2 : adding ssh key manually
if
'EC2'
in
service
:
try
:
unique_keyname
=
str
(
uuid
.
uuid1
())
keypair
=
driver
.
ex_create_keypair
(
unique_keyname
)
ssh_key
=
keypair
[
'keyMaterial'
]
argument_list
[
'ex_keyname'
]
=
unique_keyname
except
Exception
,
e
:
# XX-Cedric : what to do here?
if
e
.
args
[
0
].
find
(
"InvalidKeyPair.Duplicate"
)
==
-
1
:
# XXX-Cedric : our unique key was not so unique...Do something
raise
e
else
:
raise
e
# Prepares ssh key deployment and/or postflight script
# NOT IMPLEMENTED
#if self.options.get('ssh_key') or self.options.get('script'):
# deployment_argument_list = []
# if self.options.get('ssh_key'):
# deployment_argument_list.append(SSHKeyDeployment(
# self.options['ssh_key']))
# if self.options.get('script'):
# script_to_run = ScriptDeployment(self.options['script'])
# deployment_argument_list.append(script_to_run)
# argument_list['deploy'] = MultiStepDeployment(deployment_argument_list)
# If ec2, creates group, adds rules to it.
if
'EC2'
in
service
:
try
:
driver
.
ex_create_security_group
(
security_group
,
security_group
)
except
Exception
,
e
:
if
e
.
args
[
0
].
find
(
"InvalidPermission.Duplicate"
)
==
-
1
:
pass
#It's okay, don't worry.
driver
.
ex_authorize_security_group_permissive
(
security_group
)
argument_list
[
'ex_securitygroup'
]
=
security_group
# Installs node
node
=
driver
.
create_node
(
**
argument_list
)
#deploy_node(**argument_list)
node_uuid
=
node
.
uuid
return
{
'node_uuid'
:
node_uuid
,
'ssh_key'
:
ssh_key
}
def
main
():
try
:
node_uuid
=
sys
.
argv
[
4
]
except
IndexError
:
node_uuid
=
None
update
(
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
],
node_uuid
)
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