Commit 1bfd2ee1 authored by Marco Mariani's avatar Marco Mariani

avoid hardcoded strings

parent 260b0069
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import logging import logging
import time import time
from slapos import slap as slapmodule
import slapos import slapos
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -30,15 +29,14 @@ class Renamer(object): ...@@ -30,15 +29,14 @@ class Renamer(object):
- retrieve the broken computer partition - retrieve the broken computer partition
- change its reference to 'broken-...' and its software type to 'frozen' - change its reference to 'broken-...' and its software type to 'frozen'
- retrieve the winner computer partition (attached to this process) - retrieve the winner computer partition (attached to this process)
- change its reference and software type to replace the broken one - change its reference to replace the broken one.
later, slapgrid will change its software_type as well.
Then, after running slapgrid-cp a few times, the winner takes over and Then, after running slapgrid-cp a few times, the winner takes over and
a new cp is created to replace it as an importer. a new cp is created to replace it as an importer.
""" """
# TODO: replace hardcoded strings with values from the API slap = slapos.slap.slap()
slap = slapmodule.slap()
slap.initializeConnection(self.server_url, self.key_file, self.cert_file) slap.initializeConnection(self.server_url, self.key_file, self.cert_file)
# partition that will take over. # partition that will take over.
...@@ -47,22 +45,16 @@ class Renamer(object): ...@@ -47,22 +45,16 @@ class Renamer(object):
# XXX although we can already rename cp_winner, to change its software type we need to # XXX although we can already rename cp_winner, to change its software type we need to
# get hold of the root cp as well # get hold of the root cp as well
root_partition_id = 'slappart0' # XXX hardcoded. what's the API for this?
cp_root = slap.registerComputerPartition(computer_guid=self.computer_guid,
partition_id=root_partition_id)
cp_exporter_ref = self.namebase + '0' # this is ok. the boss is always number zero. cp_exporter_ref = self.namebase + '0' # this is ok. the boss is always number zero.
# partition to be deactivated # partition to be deactivated
cp_broken = cp_root.request(software_release=self.software_release, cp_broken = cp_winner.request(software_release=self.software_release,
software_type='frozen', software_type='frozen',
state='stopped', state='stopped',
partition_reference=cp_exporter_ref) partition_reference=cp_exporter_ref)
broken_new_ref = 'broken-{}'.format(time.strftime("%d-%b_%H:%M:%S", time.gmtime())) broken_new_ref = 'broken-{}'.format(time.strftime("%d-%b_%H:%M:%S", time.gmtime()))
# XXX can we retrieve and log the old reference name?
log.debug("Renaming {}: {}".format(cp_broken.getId(), broken_new_ref)) log.debug("Renaming {}: {}".format(cp_broken.getId(), broken_new_ref))
cp_broken.rename(new_name=broken_new_ref) cp_broken.rename(new_name=broken_new_ref)
...@@ -71,13 +63,10 @@ class Renamer(object): ...@@ -71,13 +63,10 @@ class Renamer(object):
log.debug("Renaming {}: {}".format(cp_broken.getId(), cp_exporter_ref)) log.debug("Renaming {}: {}".format(cp_broken.getId(), cp_exporter_ref))
# update software type and name for the partition that will take over # update name (and later, software type) for the partition that will take over
cp_winner_ref = self.namebase + '2' # XXX hardcoded. what's the API for this?
cp_root.request(software_release=self.software_release, cp_winner.rename(new_name=cp_exporter_ref)
software_type=self.namebase+'-export', cp_winner.bang(message='partitions have been renamed!')
partition_reference=cp_winner_ref).rename(new_name=cp_exporter_ref)
...@@ -85,6 +74,6 @@ class Renamer(object): ...@@ -85,6 +74,6 @@ class Renamer(object):
try: try:
self._failover() self._failover()
log.info('Renaming done') log.info('Renaming done')
except slapos.slap.slap.ServerError: except slapos.slap.ServerError:
log.info('Internal server error') log.info('Internal server error')
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