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
16 def _get_glance_client():
17 sess = op_utils.get_session()
19 op_utils.get_glance_api_version(),
23 def _get_nova_client():
24 sess = op_utils.get_session()
27 op_utils.get_nova_api_version(),
31 def stack_create_images(
33 image_name="bottlenecks_image"):
34 print "========== Create image in OS =========="
37 print "imagefile not set/found"
40 glance = _get_glance_client()
41 image = glance.images.create(
44 container_format="bare")
45 with open(imagefile) as fimage:
46 glance.images.upload(image.id, fimage)
49 img_status = image.status
50 while img_status == "queued" and timeInQueue < 30:
51 print " image's status: " + img_status
53 timeInQueue = timeInQueue + 1
54 img_status = glance.images.get(image.id).status
56 print "After %d seconds,image status is [%s]" % (timeInQueue, img_status)
57 return True if img_status == "active" else False
60 def stack_create_keypairs(key_path, name="bottlenecks_keypair"):
61 print "========== Add keypairs in OS =========="
62 nova = _get_nova_client()
63 with open(key_path) as pkey:
64 nova.keypairs.create(name=name, public_key=pkey.read())
67 def stack_create_flavors(
68 name="bottlenecks_flavor",
72 print "========== Create flavors in OS =========="
73 nova = _get_nova_client()
74 nova.flavors.create(name=name, ram=ram, vcpus=vcpus, disk=disk)