summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xci/deploy/deploy.sh11
-rw-r--r--deploy/post/execute.py40
-rw-r--r--deploy/post/glance.py37
-rw-r--r--deploy/prepare/execute.py47
4 files changed, 116 insertions, 19 deletions
diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh
index 0317d0ba..f81afe95 100755
--- a/ci/deploy/deploy.sh
+++ b/ci/deploy/deploy.sh
@@ -26,7 +26,7 @@ cat << EOF
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
`basename $0`: Deploys the Daisy4NFV
-usage: `basename $0` -d dha_conf -n network_con -l lab_name -p pod_name
+usage: `basename $0` -d dha_conf -l lab_name -p pod_name
-r remote_workspace -w workdir
OPTIONS:
@@ -34,7 +34,6 @@ OPTIONS:
-B PXE Bridge for booting Daisy Master, optional
-d Configuration yaml file of DHA, optional, will be deleted later
-D Dry-run, does not perform deployment, will be deleted later
- -n Configuration yaml file of network, optional
-l LAB name, necessary
-p POD name, necessary
-r Remote workspace in target server, optional
@@ -48,7 +47,6 @@ Examples:
sudo `basename $0` -b base_path
-l zte -p pod2 -B pxebr
-d ./deploy/config/vm_environment/zte-virtual1/deploy.yml
- -n ./deploy/config/vm_environment/zte-virtual1/network.yml
-r /opt/daisy -w /opt/daisy
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EOF
@@ -66,7 +64,6 @@ SCRIPT_PATH=$(readlink -f $(dirname $0))
WORKSPACE=$(cd ${SCRIPT_PATH}/../..; pwd)
VM_STORAGE=/home/qemu/vms
DHA_CONF=''
-NETWORK_CONF=''
LAB_NAME=''
POD_NAME=''
TARGET_HOSTS_NUM=0
@@ -94,9 +91,6 @@ do
D)
DRY_RUN=1
;;
- n)
- NETWORK_CONF=${OPTARG}
- ;;
l)
LAB_NAME=${OPTARG}
;;
@@ -301,8 +295,7 @@ 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"
+ ssh $SSH_PARAS $DAISY_IP "bash $REMOTE_SPACE/deploy/prepare.sh -n $NETWORK"
fi
echo "===prepare cluster and pxe==="
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index d54b2df5..b9665e10 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -6,6 +6,9 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import os
+
+import glance
import neutron
import nova
@@ -57,11 +60,48 @@ def _create_flavor_m1_micro():
print ('Use existing m1.micro flavor')
+def _prepare_cirros():
+ url = 'http://download.cirros-cloud.net'
+ version = '0.3.5'
+ name = 'cirros-{}-x86_64-disk.img'.format(version)
+ img = os.path.join(os.path.abspath(os.path.dirname(__file__)), name)
+ if not os.path.isfile(img):
+ cmd = "wget %(url)s/%(version)s/%(name)s -O %(path)s" % {
+ 'url': url,
+ 'version': version,
+ 'name': name,
+ 'path': img}
+ try:
+ print ('Downloading cirros: {}'.format(cmd))
+ os.system(cmd)
+ except Exception as error:
+ print ('Download cirros failed: {}'.format(str(error)))
+ img = None
+
+ return img
+
+
+def _create_image_TestVM():
+ glanceclient = glance.Glance()
+ image = 'TestVM'
+ if not glanceclient.get_by_name(image):
+ img = _prepare_cirros()
+ if img:
+ try:
+ glanceclient.create(image, img)
+ except Exception as error:
+ print ('Create image failed: {}'.format(str(error)))
+ else:
+ print ('Use existing TestVM image')
+
+
def main():
neutronclient = neutron.Neutron()
nid = neutronclient.create_network(*(_config_admin_external_network()))
neutronclient.create_subnet(_config_admin_external_subnet(nid))
_create_flavor_m1_micro()
+ _create_image_TestVM()
+
if __name__ == '__main__':
main()
diff --git a/deploy/post/glance.py b/deploy/post/glance.py
new file mode 100644
index 00000000..2422c7a4
--- /dev/null
+++ b/deploy/post/glance.py
@@ -0,0 +1,37 @@
+import os
+
+import glanceclient
+
+import keystoneauth
+
+
+class Glance(keystoneauth.Keystoneauth):
+ def __init__(self, version='2', openrc=None):
+ super(Glance, self).__init__(openrc)
+ self.client = glanceclient.Client(version, session=self.session)
+ self.controller = self.client.images
+
+ def create(self, name, path,
+ disk_format="qcow2",
+ container_format="bare",
+ visibility="public"):
+ if not os.path.isfile(path):
+ raise Exception('Error: file {} not exist'.format(path))
+ image = self.controller.create(name=name,
+ visibility=visibility,
+ disk_format=disk_format,
+ container_format=container_format)
+ id = image.id
+ with open(path) as data:
+ self.controller.upload(id, data)
+ return id
+
+ def get_by_name(self, name):
+ for image in self.list():
+ if image.name == name:
+ return image.id
+
+ return None
+
+ def list(self):
+ return self.controller.list()
diff --git a/deploy/prepare/execute.py b/deploy/prepare/execute.py
index a50d9d9a..c59d10ae 100644
--- a/deploy/prepare/execute.py
+++ b/deploy/prepare/execute.py
@@ -3,21 +3,47 @@ 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)
+KOLLA_CONF_PATH = '/etc/kolla/config'
-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)
+def _make_dirs(path):
+ if not os.path.isdir(path):
+ os.makedirs(path, mode=0644)
+
- with open(NOVA_API_CONF, 'w') as f:
- f.write('[DEFAULT]\n'
- 'default_floating_pool={}\n'.format(xnet['network_name']))
+def _write_conf_file(conf_file, conf):
+ with open(conf_file, 'w') as f:
+ f.write(conf)
f.close()
+def _config_service(service, subs):
+ def _wrap(func):
+ def _config(*args):
+ conf_path = os.path.join(KOLLA_CONF_PATH, service)
+ _make_dirs(conf_path)
+ for sub in subs:
+ conf_file = os.path.join(conf_path,
+ '{}-{}.conf'.format(service, sub))
+ _write_conf_file(conf_file, func(*args))
+ return _config
+ return _wrap
+
+
+@_config_service('nova', ['api'])
+def _set_default_floating_pool(network_file):
+ xnet = NetworkConfig(network_file=network_file).external_network
+ return '[DEFAULT]\n' \
+ 'default_floating_pool = {}\n'.format(xnet['network_name'])
+
+
+@_config_service('heat', ['api', 'engine'])
+def _set_trusts_auth():
+ return '[DEFAULT]\n' \
+ 'deferred_auth_method = trusts\n' \
+ 'trusts_delegated_roles =\n'
+
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-nw', '--network-file',
@@ -25,7 +51,8 @@ def main():
required=True,
help='network configuration file')
args = parser.parse_args()
- _config_nova_api(args.network_file)
+ _set_default_floating_pool(args.network_file)
+ _set_trusts_auth()
if __name__ == '__main__':