1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 import common as op_utils
12 from glanceclient.client import Client as GlanceClient
13 from novaclient.client import Client as NovaClient
14 from neutronclient.v2_0.client import Client as NeutronClient
17 def _get_glance_client():
18 sess = op_utils.get_session()
20 op_utils.get_glance_api_version(),
24 def _get_nova_client():
25 sess = op_utils.get_session()
28 op_utils.get_nova_api_version(),
32 def _get_neutron_client():
33 sess = op_utils.get_session()
34 neutron_client = NeutronClient(session=sess)
40 image_name="bottlenecks_image"):
41 print "========== Create image in OS =========="
44 print "imagefile not set/found"
47 glance = _get_glance_client()
48 image = glance.images.create(
51 container_format="bare")
52 with open(imagefile) as fimage:
53 glance.images.upload(image.id, fimage)
56 img_status = image.status
57 while img_status == "queued" and timeInQueue < 30:
58 print " image's status: " + img_status
60 timeInQueue = timeInQueue + 1
61 img_status = glance.images.get(image.id).status
63 print "After %d seconds,image status is [%s]" % (timeInQueue, img_status)
64 return True if img_status == "active" else False
67 def stack_create_keypairs(key_path, name="bottlenecks_keypair"):
68 print "========== Add keypairs in OS =========="
69 nova = _get_nova_client()
70 with open(key_path) as pkey:
71 nova.keypairs.create(name=name, public_key=pkey.read())
74 def stack_create_flavors(
75 name="bottlenecks_flavor",
79 print "========== Create flavors in OS =========="
80 nova = _get_nova_client()
81 nova.flavors.create(name=name, ram=ram, vcpus=vcpus, disk=disk)