aboutsummaryrefslogtreecommitdiffstats
path: root/func/create_zones.py
diff options
context:
space:
mode:
authorMofassir Arif <mofassir@gmail.com>2015-10-22 12:39:37 -0700
committerMofassir Arif <mofassir@gmail.com>2015-11-05 06:17:02 -0800
commit95bf8a8c96b2be94512e042f3f3c82edcbebf84d (patch)
tree7c7d1acd4dd596e84699a18d04e6ba2790e6fec2 /func/create_zones.py
parented6de63572d92bb5af8be22ced0a749400f4d3d4 (diff)
Python Framework for QTIP
Dhrystone Whetstone and DPI benchmarks have been implemented CLI arguments have been implemented test case are sorted based on category such as compute,network and storage glance and heat client have been used to generate the stack. automatic upload of QTIP image and delete function for existing stack before creating new stack has been implemented system information collecton and result generation has been implemented JIRA: QTIP-17 Signed-off-by: Mofassir Arif <mofassir_arif@dell.com> Change-Id: I4b7b134017723c30c771cc14d2edce33fcb8ba00
Diffstat (limited to 'func/create_zones.py')
-rw-r--r--func/create_zones.py117
1 files changed, 117 insertions, 0 deletions
diff --git a/func/create_zones.py b/func/create_zones.py
new file mode 100644
index 00000000..92ce43fe
--- /dev/null
+++ b/func/create_zones.py
@@ -0,0 +1,117 @@
+##############################################################################
+# Copyright (c) 2015 Dell Inc and others.
+#
+# 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 keystoneclient.auth.identity import v2
+from keystoneclient import session
+from novaclient import client
+import os
+from collections import defaultdict
+
+
+class create_zones:
+
+ def __init__(self):
+ print 'Creating Zones'
+ self._keystone_client = None
+ self._nova_client = None
+
+ def _get_keystone_client(self):
+ '''returns a keystone client instance'''
+
+ if self._keystone_client is None:
+ '''
+ self._keystone_client = keystoneclient.v2_0.client.Client(
+ auth_url=os.environ.get('OS_AUTH_URL'),
+ username=os.environ.get('OS_USERNAME'),
+ password=os.environ.get('OS_PASSWORD'),
+ tenant_name=os.environ.get('OS_TENANT_NAME'))
+ '''
+ auth = v2.Password(auth_url=os.environ.get('OS_AUTH_URL'),
+ username=os.environ.get('OS_USERNAME'),
+ password=os.environ.get('OS_PASSWORD'),
+ tenant_name=os.environ.get('OS_TENANT_NAME'))
+
+ sess = session.Session(auth=auth)
+
+ return sess
+
+ def _get_nova_client(self):
+ if self._nova_client is None:
+ keystone = self._get_keystone_client()
+ self._nova_client = client.Client('2', session=keystone)
+ return self._nova_client
+
+ def check_aggregate(self, nova, agg_name):
+ list1 = nova.aggregates.list()
+
+ agg_name_exist = False
+ for x in list1:
+
+ if x.name == agg_name:
+ agg_name_exist = True
+ return agg_name_exist
+
+ def get_aggregate_id(self, nova, agg_name):
+ list1 = nova.aggregates.list()
+ agg_id = 0
+ agg_name_exist = False
+ for x in list1:
+ if x.name == agg_name:
+ agg_id = x.id
+ return agg_id
+
+ def check_host_added_to_aggregate(self, nova, agg_id, hostname):
+ host_added = False
+ list1 = nova.aggregates.get_details(agg_id)
+
+ nme = str(list1.hosts)
+ if(hostname in nme):
+ host_added = True
+ return host_added
+
+ def del_agg(self, nova, id, host):
+
+ nova.aggregates.remove_host(id, host)
+ nova.aggregates.delete(id)
+
+ def create_agg(self, D):
+ nova = self._get_nova_client()
+ hyper_list = nova.hypervisors.list()
+ hostnA = []
+ zone_machine = defaultdict(list)
+
+ x = 0
+ for x in range(len(hyper_list)):
+
+ hostnA.append(hyper_list[x].service['host'])
+ hostnA[x] = str(hostnA[x])
+
+ hostnA.sort()
+ for k in D:
+
+ zone_machine[k].append(' ')
+
+ for x in range(len(zone_machine)):
+ if not self.check_aggregate(nova, hostnA[x]):
+ agg_idA = nova.aggregates.create(hostnA[x], D[x])
+ nova.aggregates.add_host(aggregate=agg_idA, host=hostnA[x])
+
+ else:
+
+ id1 = self.get_aggregate_id(nova, hostnA[x])
+ self.del_agg(nova, id1, hostnA[x])
+ agg_idA = nova.aggregates.create(hostnA[x], D[x])
+ id1 = self.get_aggregate_id(nova, hostnA[x])
+
+ if not self.check_host_added_to_aggregate(
+ nova, id1, hostnA[x]):
+
+ nova.aggregates.add_host(aggregate=id1, host=hostnA[x])