diff options
author | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2017-03-07 01:43:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-07 01:43:27 +0000 |
commit | d222c03bc58c79d918001773639d0f81a57c86a8 (patch) | |
tree | 34ed1d7ca0ae2916c124bbcd1611343375305f0f | |
parent | fad85bb5ecb07240f909ad812bf58c194bc10453 (diff) | |
parent | d4b8505d4fef4a0ff650653a3056327f866d70fd (diff) |
Merge "add framework of post deploy process"
-rw-r--r-- | ci/__init__.py | 0 | ||||
-rwxr-xr-x | ci/deploy/deploy.sh | 6 | ||||
-rw-r--r-- | deploy/__init__.py | 0 | ||||
-rw-r--r-- | deploy/post/__init__.py | 0 | ||||
-rw-r--r-- | deploy/post/execute.py | 17 | ||||
-rw-r--r-- | deploy/post/keystoneauth.py | 66 | ||||
-rw-r--r-- | deploy/post/neutron.py | 25 |
7 files changed, 114 insertions, 0 deletions
diff --git a/ci/__init__.py b/ci/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ci/__init__.py diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh index e7aba37b..8c13776c 100755 --- a/ci/deploy/deploy.sh +++ b/ci/deploy/deploy.sh @@ -336,6 +336,12 @@ if [ $? -ne 0 ]; then exit 1; fi + +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 index 00000000..e69de29b --- /dev/null +++ b/deploy/__init__.py diff --git a/deploy/post/__init__.py b/deploy/post/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/deploy/post/__init__.py diff --git a/deploy/post/execute.py b/deploy/post/execute.py new file mode 100644 index 00000000..8758b401 --- /dev/null +++ b/deploy/post/execute.py @@ -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 index 00000000..664a794b --- /dev/null +++ b/deploy/post/keystoneauth.py @@ -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 index 00000000..0dffdfc3 --- /dev/null +++ b/deploy/post/neutron.py @@ -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 |