add framework of post deploy process 15/29715/2
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Fri, 3 Mar 2017 10:34:16 +0000 (18:34 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Mon, 6 Mar 2017 01:12:58 +0000 (09:12 +0800)
Change-Id: I3f5a067a6359be482a853b164fd7effdfad8fc8f
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
ci/__init__.py [new file with mode: 0644]
ci/deploy/deploy.sh
deploy/__init__.py [new file with mode: 0644]
deploy/post/__init__.py [new file with mode: 0644]
deploy/post/execute.py [new file with mode: 0644]
deploy/post/keystoneauth.py [new file with mode: 0644]
deploy/post/neutron.py [new file with mode: 0644]

diff --git a/ci/__init__.py b/ci/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index c3b7805..f6fae37 100755 (executable)
@@ -327,6 +327,12 @@ if [ $IS_BARE == 0 ];then
 fi
 ssh $SSH_PARAS $DAISY_IP "${REMOTE_SPACE}/deploy/check_openstack_progress.sh"
 
+
+if [ $IS_BARE == 0 ];then
+    echo "============post deploy====================="
+    ssh $SSH_PARAS $DAISY_IP "python ${REMOTE_SPACE}/deploy/post/execute.py"
+fi
+
 exit 0
 
 #
diff --git a/deploy/__init__.py b/deploy/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/deploy/post/__init__.py b/deploy/post/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
new file mode 100644 (file)
index 0000000..8758b40
--- /dev/null
@@ -0,0 +1,17 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# feng.xiaowei@zte.com.cn
+# 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
+##############################################################################
+import neutron
+
+
+def main():
+    neutron.Neutron().list_networks()
+
+
+if __name__ == '__main__':
+    main()
diff --git a/deploy/post/keystoneauth.py b/deploy/post/keystoneauth.py
new file mode 100644 (file)
index 0000000..664a794
--- /dev/null
@@ -0,0 +1,66 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# feng.xiaowei@zte.com.cn
+# 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
+##############################################################################
+from collections import defaultdict
+import re
+
+from keystoneauth1 import loading
+from keystoneauth1 import session
+
+
+class Keystoneauth(object):
+    def __init__(self, openrc=None):
+        self.openrc = openrc if openrc else '/etc/kolla/admin-openrc.sh'
+
+    @property
+    def session(self):
+        auth = self._get_auth()
+        return session.Session(auth=auth)
+
+    def _get_auth(self):
+        loader = loading.get_plugin_loader('password')
+        creds = self._parse_credentials(self._parse_openrc())
+        return loader.load_from_options(**creds)
+
+    def _parse_openrc(self):
+
+        def parse_line(creds, line):
+            var = line.rstrip('"\n').replace('export ', '').split("=")
+            # The two next lines should be modified as soon as rc_file
+            # conforms with common rules. Be aware that it could induce
+            # issues if value starts with '
+            key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
+            value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
+            creds[key] = value
+            return creds
+
+        with open(self.openrc, "r") as f:
+            return reduce(parse_line, f.readlines(), defaultdict(dict))
+
+    @staticmethod
+    def _parse_credentials(raws):
+        maps = {
+            'OS_USERNAME': 'username',
+            'OS_PASSWORD': 'password',
+            'OS_AUTH_URL': 'auth_url',
+            'OS_TENANT_NAME': 'tenant_name',
+            'OS_USER_DOMAIN_NAME': 'user_domain_name',
+            'OS_PROJECT_DOMAIN_NAME': 'project_domain_name',
+            'OS_PROJECT_NAME': 'project_name',
+            'OS_ENDPOINT_TYPE': 'endpoint_type',
+            'OS_REGION_NAME': 'region_name'
+        }
+
+        def parse_credential(creds, kv):
+            (cred_k, cred_v) = kv
+            creds[maps[cred_k]] = cred_v
+            return creds
+
+        return reduce(parse_credential,
+                      [(k, v) for (k, v) in raws.iteritems() if k in maps],
+                      defaultdict(dict))
diff --git a/deploy/post/neutron.py b/deploy/post/neutron.py
new file mode 100644 (file)
index 0000000..0dffdfc
--- /dev/null
@@ -0,0 +1,25 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# feng.xiaowei@zte.com.cn
+# 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
+##############################################################################
+from neutronclient.neutron import client as neutronclient
+
+import keystoneauth
+
+
+class Neutron(object):
+    def __init__(self, api_v='2', openrc=None):
+        session = keystoneauth.Keystoneauth(openrc).session
+        self.client = neutronclient.Client(api_v, session=session)
+
+    def list_networks(self):
+        networks = self.client.list_networks()['networks']
+        for network in networks:
+            print network
+
+    def create_admin_ext_net(self):
+        pass