aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/client.py
diff options
context:
space:
mode:
authorliyuenan <liyuenan@huawei.com>2016-09-12 12:13:39 +0800
committerYuenan Li <liyuenan@huawei.com>2016-09-18 09:26:02 +0000
commite9c6204c777d4d5169d6678a868782a7835d1350 (patch)
treefb7ad04d58d7da5c4693e05af5f5299743ed0a37 /deploy/client.py
parent17092c09eea12270fe3c4878adc7f70ff7d98fbc (diff)
Add a expansion functionality
Through modify the virtual_cluster_expansion.yml, include host's name and mac, you can decide to how many compute nodes you need to add. And you also need to modify network.yml. Note that external subnet's ip_range should be changed as the first 6 IPs are already taken by the first deployment. Edit ``add.sh``, check the environment variable. Note that the OS version and OpenStack version should be same as the first deployment. Run ``add.sh``. JIRA:COMPASS-481 Change-Id: Id85f02518667e0ff80c2475e70856cd30cf1b9b7 Signed-off-by: liyuenan <liyuenan@huawei.com>
Diffstat (limited to 'deploy/client.py')
-rw-r--r--deploy/client.py90
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()