add default_floating_pool configuration for nova-api 07/30507/3
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 15 Mar 2017 06:31:36 +0000 (14:31 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 15 Mar 2017 07:55:09 +0000 (15:55 +0800)
Change-Id: I9db5509667e9c10a9c07b55531c6d78fb95cc223
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
ci/deploy/deploy.sh
deploy/common/__init__.py [new file with mode: 0644]
deploy/common/query.py [new file with mode: 0644]
deploy/config/__init__.py [new file with mode: 0644]
deploy/config/network.py [new file with mode: 0644]
deploy/config/vm_environment/zte-virtual1/network.yml
deploy/prepare.sh [new file with mode: 0644]
deploy/prepare/__init__.py [new file with mode: 0644]
deploy/prepare/execute.py [new file with mode: 0644]

index efae838..edbc67c 100755 (executable)
@@ -301,6 +301,8 @@ if [ $IS_BARE == 0 ];then
     echo "====== add relate config of kolla==========="
     ssh $SSH_PARAS $DAISY_IP "mkdir -p /etc/kolla/config/nova"
     ssh $SSH_PARAS $DAISY_IP "echo -e '[libvirt]\nvirt_type=qemu\ncpu_mode=none' >> /etc/kolla/config/nova/nova-compute.conf"
+    NETWORK_CONF="$REMOTE_SPACE/deploy/config/vm_environment/$LAB_NAME-$POD_NAME/network.yml"
+    ssh $SSH_PARAS $DAISY_IP "bash $REMOTE_SPACE/deploy/prepare.sh -n $NETWORK_CONF"
 fi
 
 echo "===prepare cluster and pxe==="
diff --git a/deploy/common/__init__.py b/deploy/common/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/deploy/common/query.py b/deploy/common/query.py
new file mode 100644 (file)
index 0000000..9b1adc2
--- /dev/null
@@ -0,0 +1,5 @@
+def find(function, sequence, default=None):
+    for s in sequence:
+        if function(s):
+            return s
+    return default
diff --git a/deploy/config/__init__.py b/deploy/config/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/deploy/config/network.py b/deploy/config/network.py
new file mode 100644 (file)
index 0000000..ed14f95
--- /dev/null
@@ -0,0 +1,20 @@
+import yaml
+
+from deploy.common import query
+
+
+class NetworkConfig(object):
+    def __init__(self, network_file):
+        self._file = network_file
+        self._get_config()
+
+    def _get_config(self):
+        self.config = yaml.safe_load(file(self._file))
+
+    def _get_network(self, name):
+        return query.find(lambda item: item['name'] == name,
+                          self.config['networks'])
+
+    @property
+    def external_network(self):
+        return self._get_network('EXTERNAL')
index 7d746be..6c8a282 100644 (file)
@@ -17,8 +17,8 @@ networks:
   - cidr: '10.20.11.0/24'\r
     gateway: '10.20.11.1'\r
     ip_ranges:\r
-    - 'start': '10.20.11.3'\r
-      'end': '10.20.11.10'\r
+    - start: '10.20.11.3'\r
+      end: '10.20.11.10'\r
     name: 'MANAGEMENT'\r
   - cidr: '10.20.11.0/24'\r
     gateway: '10.20.11.1'\r
@@ -27,22 +27,23 @@ networks:
       end: '10.20.11.10'\r
     name: 'STORAGE'\r
   - cidr: '172.10.101.0/24'\r
-    gateway: '172.10.101.0'\r
+    gateway: '172.10.101.1'\r
     ip_ranges:\r
-    - 'start': '172.10.101.1'\r
-      'end': '172.10.101.10'\r
-    'name': 'EXTERNAL'\r
+    - start: 172.10.101.2\r
+      end: 172.10.101.20\r
+    name: EXTERNAL\r
+    network_name: admin_external\r
   - cidr: '10.20.11.0/24'\r
     gateway: '10.20.11.1'\r
     ip_ranges:\r
-    - 'start': '10.20.11.3'\r
-      'end': '10.20.11.10'\r
+    - start: '10.20.11.3'\r
+      end: '10.20.11.10'\r
     name: 'PUBLICAPI'\r
   - cidr: '10.20.11.0/24'\r
     gateway: '10.20.11.1'\r
     ip_ranges:\r
-    - 'start': '10.20.11.3'\r
-      'end': '10.20.11.10'\r
+    - start: '10.20.11.3'\r
+      end: '10.20.11.10'\r
     name: 'TENANT'\r
 interfaces:\r
   - name: 'EXTERNAL'\r
diff --git a/deploy/prepare.sh b/deploy/prepare.sh
new file mode 100644 (file)
index 0000000..58d5a08
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+SCRIPT_PATH=$(readlink -f $(dirname $0))
+
+export PYTHONPATH=$SCRIPT_PATH/..
+
+usage ()
+{
+cat << EOF
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+`basename $0`: make preparation for daisy deployment
+
+usage: `basename $0` -n network_config_file
+
+OPTIONS:
+  -nw  network configuration path, necessary
+  -h  Print this message and exit
+
+Description:
+  prepare configuration
+
+Examples:
+sudo `basename $0` -n /home/daisy/config/vm_environment/zte-virtual1/network.yml
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+EOF
+}
+
+NETWORK_CONF=''
+
+while getopts "n:h" OPTION
+do
+    case $OPTION in
+        n)
+            NETWORK_CONF=${OPTARG}
+            ;;
+        h)
+            usage
+            exit 0
+            ;;
+        *)
+            echo "${OPTION} is not a valid argument"
+            usage
+            exit 0
+            ;;
+    esac
+done
+
+python $PYTHONPATH/deploy/prepare/execute.py -nw $NETWORK_CONF
diff --git a/deploy/prepare/__init__.py b/deploy/prepare/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/deploy/prepare/execute.py b/deploy/prepare/execute.py
new file mode 100644 (file)
index 0000000..a50d9d9
--- /dev/null
@@ -0,0 +1,32 @@
+import argparse
+import os
+
+from deploy.config.network import NetworkConfig
+
+NOVA_CONF_PATH = '/etc/kolla/config/nova'
+NOVA_API_CONF = '{}/nova-api.conf'.format(NOVA_CONF_PATH)
+
+
+def _config_nova_api(network_file):
+    xnet = NetworkConfig(network_file=network_file).external_network
+    if not os.path.isdir(NOVA_CONF_PATH):
+        os.makedirs(NOVA_CONF_PATH, mode=0644)
+
+    with open(NOVA_API_CONF, 'w') as f:
+        f.write('[DEFAULT]\n'
+                'default_floating_pool={}\n'.format(xnet['network_name']))
+        f.close()
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-nw', '--network-file',
+                        type=str,
+                        required=True,
+                        help='network configuration file')
+    args = parser.parse_args()
+    _config_nova_api(args.network_file)
+
+
+if __name__ == '__main__':
+    main()