diff options
Diffstat (limited to 'deploy/client.py')
-rw-r--r-- | deploy/client.py | 90 |
1 files changed, 64 insertions, 26 deletions
diff --git a/deploy/client.py b/deploy/client.py index e5623c8b..f6a07a77 100644 --- a/deploy/client.py +++ b/deploy/client.py @@ -49,6 +49,9 @@ def byteify(input): return input opts = [ + cfg.StrOpt('expansion', + help='is this an expansion?', + default='false'), cfg.StrOpt('compass_server', help='compass server url', default='http://127.0.0.1/api'), @@ -365,19 +368,24 @@ class CompassClient(object): assert(subnets) subnet_mapping = {} + _, subnets_in_db = self.client.list_subnets() for subnet in subnets: try: netaddr.IPNetwork(subnet) except: raise RuntimeError('subnet %s format is invalid' % subnet) - status, resp = self.client.add_subnet(subnet) - LOG.info('add subnet %s status %s response %s', - subnet, status, resp) - if not self.is_ok(status): - raise RuntimeError('failed to add subnet %s' % subnet) - - subnet_mapping[resp['subnet']] = resp['id'] + if CONF.expansion == "false": + status, resp = self.client.add_subnet(subnet) + LOG.info('add subnet %s status %s response %s', + subnet, status, resp) + if not self.is_ok(status): + raise RuntimeError('failed to add subnet %s' % subnet) + subnet_mapping[resp['subnet']] = resp['id'] + else: + for subnet_in_db in subnets_in_db: + if subnet == subnet_in_db['subnet']: + subnet_mapping[subnet] = subnet_in_db['id'] self.subnet_mapping = subnet_mapping @@ -418,6 +426,7 @@ class CompassClient(object): if hostname ] + machines = machines[-len(hostnames):] assert(len(machines) == len(hostnames)) machines_dict = [] @@ -439,9 +448,11 @@ class CompassClient(object): raise RuntimeError("add host to cluster failed") for host in resp['hosts']: - self.host_mapping[host['hostname']] = host['id'] + if host['hostname'] in hostnames: + self.host_mapping[host['hostname']] = host['id'] - assert(len(self.host_mapping) == len(machines)) + if CONF.expansion == "false": + assert(len(self.host_mapping) == len(machines)) def set_cluster_os_config(self, cluster_id): """set cluster os config.""" @@ -620,7 +631,7 @@ class CompassClient(object): ]) LOG.info( - 'add host %s interface %s ip %s network proprties %s', + 'add host %s interface %s ip %s network properties %s', hostname, interface, ip_str, properties) status, response = self.client.add_host_network( @@ -932,29 +943,56 @@ def kill_print_proc(): os.system("ps aux|grep -v grep|grep -E 'ssh.+root@192.168.200.2'|awk '{print $2}'|xargs kill -9") def deploy(): - client = CompassClient() - machines = client.get_machines() + if CONF.expansion == "false": + client = CompassClient() + machines = client.get_machines() - LOG.info('machines are %s', machines) + LOG.info('machines are %s', machines) - client.add_subnets() - adapter_id, os_id, flavor_id = client.get_adapter() - cluster_id = client.add_cluster(adapter_id, os_id, flavor_id) + client.add_subnets() + 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) + client.add_cluster_hosts(cluster_id, machines) + client.set_host_networking() + client.set_cluster_os_config(cluster_id) + + if flavor_id: + client.set_cluster_package_config(cluster_id) + + client.set_all_hosts_roles(cluster_id) + client.deploy_clusters(cluster_id) + + LOG.info("compass OS installtion is begin") + threading.Thread(target=print_ansible_log).start() + client.get_installing_progress(cluster_id) + client.check_dashboard_links(cluster_id) + + else: + client = CompassClient() + machines = client.get_machines() + + LOG.info('machines are %s', machines) + + client.add_subnets() + + status, response = client.client.list_clusters() + cluster_id = 1 + for cluster in response: + if cluster['name'] == CONF.cluster_name: + cluster_id = cluster['id'] + + client.add_cluster_hosts(cluster_id, machines) + client.set_host_networking() + client.set_cluster_os_config(cluster_id) - if flavor_id: client.set_cluster_package_config(cluster_id) - client.set_all_hosts_roles(cluster_id) - client.deploy_clusters(cluster_id) + client.set_all_hosts_roles(cluster_id) + client.deploy_clusters(cluster_id) - LOG.info("compass OS installtion is begin") - threading.Thread(target=print_ansible_log).start() - client.get_installing_progress(cluster_id) - client.check_dashboard_links(cluster_id) + threading.Thread(target=print_ansible_log).start() + client.get_installing_progress(cluster_id) def redeploy(): client = CompassClient() |