Add a expansion functionality 59/20859/12
authorliyuenan <liyuenan@huawei.com>
Mon, 12 Sep 2016 04:13:39 +0000 (12:13 +0800)
committerYuenan Li <liyuenan@huawei.com>
Sun, 18 Sep 2016 09:26:02 +0000 (09:26 +0000)
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>
add.sh [new file with mode: 0755]
deploy/client.py
deploy/conf/base.conf
deploy/conf/hardware_environment/expansion-sample/hardware_cluster_expansion.yml [new file with mode: 0644]
deploy/conf/virtual.conf
deploy/conf/vm_environment/virtual_cluster_expansion.yml [new file with mode: 0644]
deploy/deploy_host.sh
deploy/host_baremetal.sh
deploy/host_virtual.sh
deploy/launch.sh

diff --git a/add.sh b/add.sh
new file mode 100755 (executable)
index 0000000..cf537fc
--- /dev/null
+++ b/add.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+##############################################################################
+# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# ISO_URL is your iso's absolute path
+# export ISO_URL=file:///home/compass/compass4nfv.iso
+# or
+# export ISO_URL=http://artifacts.opnfv.org/compass4nfv/colorado/opnfv-colorado.1.0.iso
+export ISO_URL=
+
+# DHA is your dha.yml's path
+# export DHA=/home/compass4nfv/deploy/conf/vm_environment/os-nosdn-nofeature-ha.yml
+export DHA=
+
+# NETWORK is your network.yml's path
+# export NETWORK=/home/compass4nfv/deploy/conf/vm_environment/huawei-virtual1/network.yml
+export NETWORK=
+
+# node number when you virtual deploy
+# export VIRT_NUMBER=5
+
+########## Ubuntu14.04 Mitaka ##########
+export OS_VERSION=trusty
+export OPENSTACK_VERSION=mitaka
+
+########## Ubuntu16.04 Mitaka ##########
+# export OS_VERSION=xenial
+# export OPENSTACK_VERSION=mitaka_xenial
+
+########## Centos7 Mitaka ##########
+# export OS_VERSION=centos7
+# export OPENSTACK_VERSION=mitaka
+
+##########Deploy or Expansion##########
+export EXPANSION="true"
+export MANAGEMENT_IP_START="10.1.0.55"
+export VIRT_NUMBER=1
+
+########## Hardware Deploy Jumpserver PXE NIC ##########
+# you need comment out it when virtual deploy
+# export INSTALL_NIC=eth1
+
+########## Deploy or Redeploy ##########
+# export DEPLOY_HOST="true"
+export DEPLOY_FIRST_TIME="false"
+
+./deploy.sh
index e5623c8..f6a07a7 100644 (file)
@@ -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()
index 24eb703..d60e68b 100644 (file)
@@ -25,6 +25,8 @@ export ENABLE_SECGROUP=${ENABLE_SECGROUP:-"true"}
 export ENABLE_VPNAAS="false"
 export ENABLE_FWAAS="false"
 
+export EXPANSION=${EXPANSION:-"false"}
+
 function next_ip {
     ip_addr=$1
     ip_base="$(echo $ip_addr | cut -d. -f'1 2 3')"
diff --git a/deploy/conf/hardware_environment/expansion-sample/hardware_cluster_expansion.yml b/deploy/conf/hardware_environment/expansion-sample/hardware_cluster_expansion.yml
new file mode 100644 (file)
index 0000000..b160b32
--- /dev/null
@@ -0,0 +1,15 @@
+TYPE: baremetal
+FLAVOR: cluster
+POWER_TOOL: ipmitool
+
+ipmiUser: root
+ipmiPass: Huawei@123
+
+hosts:
+  - name: host6
+     mac: 'E8:4D:D0:BA:60:45'
+     interfaces:
+        - eth1: '08:4D:D0:BA:60:44'
+     ipmiIp: 172.16.131.23
+     roles:
+       - compute
index 0475ee9..7f4fcf0 100644 (file)
@@ -1,7 +1,7 @@
-export VIRT_NUMBER=5
-export VIRT_CPUS=4
-export VIRT_MEM=16384
-export VIRT_DISK=200G
+export VIRT_NUMBER=${VIRT_NUMBER:-5}
+export VIRT_CPUS=${VIRT_CPU:-4}
+export VIRT_MEM=${VIRT_MEM:-16384}
+export VIRT_DISK=${VIRT_DISK:-200G}
 
 export SWITCH_IPS="1.1.1.1"
 export SWITCH_CREDENTIAL="version=2c,community=public"
diff --git a/deploy/conf/vm_environment/virtual_cluster_expansion.yml b/deploy/conf/vm_environment/virtual_cluster_expansion.yml
new file mode 100644 (file)
index 0000000..3d3298d
--- /dev/null
@@ -0,0 +1,7 @@
+TYPE: virtual
+FLAVOR: cluster
+
+hosts:
+  - name: host6
+    roles:
+      - compute
index b38f420..031b56a 100755 (executable)
@@ -44,7 +44,7 @@ function deploy_host(){
     --machines=${machines//\'} --switch_credential="${SWITCH_CREDENTIAL}" --deploy_type="${TYPE}" \
     --deployment_timeout="${DEPLOYMENT_TIMEOUT}" --${POLL_SWITCHES_FLAG} --dashboard_url="${DASHBOARD_URL}" \
     --cluster_vip="${VIP}" --network_cfg="$NETWORK" --neutron_cfg="$NEUTRON" \
-    --enable_secgroup="${ENABLE_SECGROUP}" --enable_fwaas="${ENABLE_FWAAS}" \
+    --enable_secgroup="${ENABLE_SECGROUP}" --enable_fwaas="${ENABLE_FWAAS}" --expansion="${EXPANSION}" \
     --rsa_file="$rsa_file" --enable_vpnaas="${ENABLE_VPNAAS}" --odl_l3_agent="${odl_l3_agent}" --moon="${moon}" --onos_sfc="${onos_sfc}"
 
     RET=$?
index fc02875..4c63f82 100755 (executable)
@@ -15,6 +15,14 @@ function reboot_hosts() {
 }
 
 function get_host_macs() {
-    machines=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+    if [[ "$EXPANSION" == "false" ]]; then
+        machines=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+        echo $machines > $WORK_DIR/switch_machines
+    else
+        machines_old=`cat $WORK_DIR/switch_machines`
+        machines_add=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+        echo $machines_add $machines_old > $WORK_DIR/switch_machines
+        machines=`echo $machines_add $machines_old|sed 's/ /,/g'`
+    fi
     echo $machines
 }
index 97896bf..2fab2c9 100755 (executable)
@@ -60,14 +60,32 @@ function get_host_macs() {
 
     if [[ $REDEPLOY_HOST == "true" ]]; then
         mac_array=`cat $WORK_DIR/switch_machines`
+        machines=`echo $mac_array|sed 's/ /,/g'`
     else
-        chmod +x $mac_generator
-        mac_array=`$mac_generator $VIRT_NUMBER`
-        echo $mac_array > $WORK_DIR/switch_machines
+        if [[ -z $HOST_MACS ]]; then
+            if [[ "$EXPANSION" == "false" ]]; then
+                chmod +x $mac_generator
+                mac_array=`$mac_generator $VIRT_NUMBER`
+                echo $mac_array > $WORK_DIR/switch_machines
+                machines=`echo $mac_array|sed 's/ /,/g'`
+            else
+                machines_old=`cat $WORK_DIR/switch_machines`
+                chmod +x $mac_generator
+                machines_add=`$mac_generator $VIRT_NUMBER`
+                echo $machines_add $machines_old > $WORK_DIR/switch_machines
+                machines=`echo $machines_add $machines_old|sed 's/ /,/g'`
+            fi
+        else
+            if [[ "$EXPANSION" == "false" ]]; then
+                machines=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+            else
+                machines_old=`cat $WORK_DIR/switch_machines`
+                machines_add=`echo $HOST_MACS | sed -e 's/,/'\',\''/g' -e 's/^/'\''/g' -e 's/$/'\''/g'`
+                echo $machines_add $machines_old > $WORK_DIR/switch_machines
+                machines=`echo $machines_add $machines_old|sed 's/ /,/g'`
+            fi
+        fi
     fi
-
-    machines=`echo $mac_array|sed 's/ /,/g'`
-
     echo $machines
 }
 
index 488e0fd..ed65f40 100755 (executable)
@@ -30,39 +30,52 @@ source ${COMPASS_DIR}/deploy/compass_vm.sh
 source ${COMPASS_DIR}/deploy/deploy_host.sh
 
 ######################### main process
-print_logo
+if [[ "$EXPANSION" == "false" ]]
+then
 
-if [[ ! -z $VIRT_NUMBER ]];then
-    tear_down_machines
-fi
-
-log_info "########## get host mac begin #############"
-machines=`get_host_macs`
-if [[ -z $machines ]]; then
-    log_error "get_host_macs failed"
-    exit 1
-fi
+    print_logo
 
-export machines
-
-if [[ "$DEPLOY_COMPASS" == "true" ]]; then
-    if ! prepare_env;then
-        echo "prepare_env failed"
-        exit 1
+    if [[ ! -z $VIRT_NUMBER ]];then
+        tear_down_machines
     fi
 
-    log_info "########## set up network begin #############"
-    if ! create_nets;then
-        log_error "create_nets failed"
+    log_info "########## get host mac begin #############"
+    machines=`get_host_macs`
+    if [[ -z $machines ]]; then
+        log_error "get_host_macs failed"
         exit 1
     fi
 
-    if ! launch_compass;then
-        log_error "launch_compass failed"
+    export machines
+
+    if [[ "$DEPLOY_COMPASS" == "true" ]]; then
+        if ! prepare_env;then
+            echo "prepare_env failed"
+            exit 1
+        fi
+
+        log_info "########## set up network begin #############"
+        if ! create_nets;then
+            log_error "create_nets failed"
+            exit 1
+        fi
+
+        if ! launch_compass;then
+            log_error "launch_compass failed"
+            exit 1
+        fi
+    fi
+else
+    machines=`get_host_macs`
+    if [[ -z $machines ]];then
+        log_error "get_host_macs failed"
         exit 1
     fi
+
+    log_info "deploy host macs: $machines"
 fi
 
+
 if [[ -z "$REDEPLOY_HOST" || "$REDEPLOY_HOST" == "false" ]]; then
     if ! set_compass_machine; then
         log_error "set_compass_machine fail"