Commit 90a7f4a7 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos: Update slapgrid to use new API

parent 8652fba3
......@@ -423,6 +423,7 @@ class Partition(object):
instance_storage_home='',
ipv4_global_network='',
buildout_debug=False,
api_backward_compatibility=False,
):
"""Initialisation of class parameters"""
self.buildout = buildout
......@@ -443,6 +444,7 @@ class Partition(object):
self.software_release_url = software_release_url
self.instance_storage_home = instance_storage_home
self.ipv4_global_network = ipv4_global_network
self.api_backward_compatibility = api_backward_compatibility
self.key_file = ''
self.cert_file = ''
......@@ -489,8 +491,12 @@ class Partition(object):
# Certificate files are unset, skip.
return
if self.api_backward_compatibility:
try:
partition_certificate = self.computer_partition.getCertificate()
partition_certificate = self.computer_partition["slap_partition"].getCertificate()
self.computer_partition["X509"] = {}
self.computer_partition["X509"]["certificate"] = partition_certificate["certificate"]
self.computer_partition["X509"]["key"] = partition_certificate["key"]
except NotFoundError:
raise NotFoundError('Partition %s is not known by SlapOS Master.' %
self.partition_id)
......@@ -498,7 +504,7 @@ class Partition(object):
uid, gid = self.getUserGroupId()
for name, path in [('certificate', self.cert_file), ('key', self.key_file)]:
new_content = partition_certificate[name]
new_content = self.computer_partition["X509"][name]
old_content = None
if os.path.exists(path):
old_content = open(path).read()
......@@ -582,7 +588,7 @@ class Partition(object):
installs the software partition with the help of buildout
"""
self.logger.info("Installing Computer Partition %s..."
% self.computer_partition.getId())
% self.computer_partition.get("compute_partition_id"))
self.check_free_space()
......@@ -731,7 +737,7 @@ class Partition(object):
if os.path.exists(self.supervisord_partition_configuration_path):
os.unlink(self.supervisord_partition_configuration_path)
else:
partition_id = self.computer_partition.getId()
partition_id = self.computer_partition.get("compute_partition_id")
group_partition_template = bytes2str(pkg_resources.resource_string(__name__,
'templates/group_partition_supervisord.conf.in'))
self.supervisor_configuration_group = group_partition_template % {
......@@ -766,22 +772,22 @@ class Partition(object):
"""Asks supervisord to start the instance. If this instance is not
installed, we install it.
"""
partition_id = self.computer_partition.getId()
partition_id = self.computer_partition.get("compute_partition_id")
try:
with self.getSupervisorRPC() as supervisor:
supervisor.startProcessGroup(partition_id, False)
except xmlrpclib.Fault as exc:
if exc.faultString.startswith('BAD_NAME:'):
self.logger.info("Nothing to start on %s..." %
self.computer_partition.getId())
self.computer_partition.get("compute_partition_id"))
else:
raise
else:
self.logger.info("Requested start of %s..." % self.computer_partition.getId())
self.logger.info("Requested start of %s..." % self.computer_partition.get("compute_partition_id"))
def stop(self):
"""Asks supervisord to stop the instance."""
partition_id = self.computer_partition.getId()
partition_id = self.computer_partition.get("compute_partition_id")
try:
with self.getSupervisorRPC() as supervisor:
supervisor.stopProcessGroup(partition_id, False)
......@@ -791,13 +797,13 @@ class Partition(object):
else:
raise
else:
self.logger.info("Requested stop of %s..." % self.computer_partition.getId())
self.logger.info("Requested stop of %s..." % self.computer_partition.get("compute_partition_id"))
def destroy(self):
"""Destroys the partition and makes it available for subsequent use."
"""
self.logger.info("Destroying Computer Partition %s..."
% self.computer_partition.getId())
% self.computer_partition.get("compute_partition_id"))
self.createRetentionLockDate()
if not self.checkRetentionIsAuthorized():
......
This diff is collapsed.
......@@ -82,9 +82,8 @@ class Manager(object):
# Get partitions IPv6 address
computer_partition = partition.computer_partition
parameter_dict = computer_partition.getInstanceParameterDict()
partition_ip_list = parameter_dict['ip_list'] + parameter_dict.get(
partition_ip_list = computer_partition['ip_list'] + computer_partition.get(
'full_ip_list', [])
partition_ip_list = [tup[1] for tup in partition_ip_list]
......
......@@ -741,6 +741,36 @@ class SlapConnectionHelper(ConnectionHelper):
return loads(xml)
# https://stackoverflow.com/a/33571117
def _byteify(data, ignore_dicts = False):
if isinstance(data, str):
return data
# if this is a list of values, return list of byteified values
if isinstance(data, list):
return [ _byteify(item, ignore_dicts=True) for item in data ]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if isinstance(data, dict) and not ignore_dicts:
return {
_byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True)
for key, value in data.items() # changed to .items() for python 2.7/3
}
# python 3 compatible duck-typing
# if this is a unicode string, return its string representation
if str(type(data)) == "<type 'unicode'>":
return data.encode('utf-8')
# if it's anything else, return it in its original form
return data
def json_loads_byteified(json_text):
return _byteify(
json.loads(json_text, object_hook=_byteify),
ignore_dicts=True
)
class JioAPIConnectionHelper(ConnectionHelper):
def apiCall(self, path, data):
......@@ -749,7 +779,7 @@ class JioAPIConnectionHelper(ConnectionHelper):
data=json.dumps(data),
headers={'Content-type': 'application/json'},
expect_json_error=True)
return req.json()
return json_loads_byteified(req.text)
def get(self, data):
return self.apiCall(path="get/",
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment