aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/client.py')
-rw-r--r--deploy/client.py65
1 files changed, 52 insertions, 13 deletions
diff --git a/deploy/client.py b/deploy/client.py
index 15f1ba8d..b9cfd7fe 100644
--- a/deploy/client.py
+++ b/deploy/client.py
@@ -228,6 +228,9 @@ opts = [
cfg.StrOpt('deploy_type',
help='deploy type',
default='virtual'),
+ cfg.StrOpt('deploy_flag',
+ help='deploy flag',
+ default='deploy'),
]
CONF.register_cli_opts(opts)
@@ -279,9 +282,9 @@ class CompassClient(object):
def get_machines(self):
status, resp = self.client.list_machines()
- LOG.info(
- 'get all machines status: %s, resp: %s', status, resp)
if not self.is_ok(status):
+ LOG.error(
+ 'get all machines status: %s, resp: %s', status, resp)
raise RuntimeError('failed to get machines')
machines_to_add = list(set([
@@ -289,12 +292,21 @@ class CompassClient(object):
if machine
]))
- LOG.info('machines to add: %s', machines_to_add)
machines_db = [str(m["mac"]) for m in resp]
- LOG.info('machines in db: %s', machines_db)
- assert(set(machines_db) == set(machines_to_add))
+ LOG.info('machines in db: %s\n to add: %s', machines_db, machines_to_add)
+ if not set(machines_to_add).issubset(set(machines_db)):
+ raise RuntimeError('unidentify machine to add')
+
+ return [m["id"] for m in resp if str(m["mac"]) in machines_to_add]
+
+ def list_clusters(self):
+ status, resp = self.client.list_clusters(name=CONF.cluster_name)
+ if not self.is_ok(status) or not resp:
+ raise RuntimeError('failed to list cluster')
+
+ cluster = resp[0]
- return [m["id"] for m in resp]
+ return cluster['id']
def get_adapter(self):
"""get adapter."""
@@ -307,19 +319,16 @@ class CompassClient(object):
if not self.is_ok(status) or not resp:
raise RuntimeError('failed to get adapters')
- adapter_name = CONF.adapter_name
os_re = re.compile(CONF.adapter_os_pattern)
flavor_re = re.compile(CONF.adapter_flavor_pattern)
adapter_id = None
os_id = None
- distributed_system_id = None
flavor_id = None
adapter = None
adapter = resp[0]
adapter_id = adapter['id']
- distributed_system_id = adapter['distributed_system_id']
for supported_os in adapter['supported_oses']:
if not os_re or os_re.match(supported_os['name']):
os_id = supported_os['os_id']
@@ -332,7 +341,7 @@ class CompassClient(object):
break
assert(os_id and flavor_id)
- return (adapter_id, os_id, distributed_system_id, flavor_id)
+ return (adapter_id, os_id, flavor_id)
def add_subnets(self):
subnets = [
@@ -809,6 +818,18 @@ class CompassClient(object):
if not self.is_ok(status):
raise RuntimeError("deploy cluster failed")
+ def redeploy_clusters(self, cluster_id):
+ status, response = self.client.redeploy_cluster(
+ cluster_id
+ )
+
+ if not self.is_ok(status):
+ LOG.info(
+ 'deploy cluster %s status %s: %s',
+ cluster_id, status, response
+ )
+ raise RuntimeError("redeploy cluster failed")
+
def get_installing_progress(self, cluster_id):
"""get intalling progress."""
action_timeout = time.time() + 60 * float(CONF.action_timeout)
@@ -865,21 +886,22 @@ class CompassClient(object):
raise Exception(msg)
-def main():
+
+def deploy():
client = CompassClient()
machines = client.get_machines()
LOG.info('machines are %s', machines)
client.add_subnets()
- adapter_id, os_id, distributed_system_id, flavor_id = client.get_adapter()
+ adapter_id, os_id, flavor_id = client.get_adapter()
cluster_id = client.add_cluster(adapter_id, os_id, flavor_id)
client.add_cluster_hosts(cluster_id, machines)
client.set_host_networking()
client.set_cluster_os_config(cluster_id)
- if distributed_system_id:
+ if flavor_id:
client.set_cluster_package_config(cluster_id)
client.set_all_hosts_roles(cluster_id)
@@ -888,6 +910,23 @@ def main():
client.get_installing_progress(cluster_id)
client.check_dashboard_links(cluster_id)
+def redeploy():
+ client = CompassClient()
+
+ cluster_id = client.list_clusters()
+
+ client.redeploy_clusters(cluster_id)
+
+ client.get_installing_progress(cluster_id)
+ client.check_dashboard_links(cluster_id)
+
+def main():
+ if CONF.deploy_flag == "redeploy":
+ redeploy()
+ else:
+ deploy()
+
+
if __name__ == "__main__":
CONF(args=sys.argv[1:])
main()