diff options
author | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2016-11-10 10:59:26 +0800 |
---|---|---|
committer | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2016-11-10 14:50:17 +0800 |
commit | 9edb0f9e48cc923ed443d3d66886713cde9b628d (patch) | |
tree | 1463ca978963b6570ea143131d64d0b919a0b1f3 /utils/create_zones.py | |
parent | 939299c36b3cf79f198d4a4849345eabd878973b (diff) |
Adjust folder structure
Note: this patchset may break existing features, but it will help
to accelerate the refactoring work.
JIRA: QTIP-131
Change-Id: Ie0cd9d185e6b02316878daef905e26f4e533a66b
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'utils/create_zones.py')
-rw-r--r-- | utils/create_zones.py | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/utils/create_zones.py b/utils/create_zones.py deleted file mode 100644 index 5e378c83..00000000 --- a/utils/create_zones.py +++ /dev/null @@ -1,86 +0,0 @@ -##############################################################################
-# Copyright (c) 2016 Dell Inc, ZTE 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
-import random
-import logger_utils
-
-logger = logger_utils.QtipLogger('create_zones').get
-
-
-class AvailabilityZone:
-
- def __init__(self):
- 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)
- else:
- return self._keystone_client
-
- 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 clean_all_aggregates(self):
- logger.info("clean all aggregates")
- nova = self._get_nova_client()
- agg_list = nova.aggregates.list()
-
- for agg in agg_list:
- agg_info = nova.aggregates.get_details(agg.id)
- agg_hosts = agg_info.hosts
- if len(agg_hosts):
- for host in agg_hosts:
- nova.aggregates.remove_host(agg.id, host)
- nova.aggregates.delete(agg.id)
-
- def create_aggs(self, args):
- azone_list = list(set(args))
- azone_list.sort()
-
- nova = self._get_nova_client()
- hyper_list = nova.hypervisors.list()
-
- if len(azone_list) > len(hyper_list):
- logger.error("required available zones > compute nodes")
- return None
-
- compute_nodes = map(lambda x: x.service['host'], hyper_list)
- sample_nodes = random.sample(compute_nodes, len(azone_list))
- sample_nodes.sort()
-
- for index, item in enumerate(azone_list):
- logger.info("create aggregates: %s" % str(item))
- agg_id = nova.aggregates.create(item, item)
-
- logger.info("add host: %s" % sample_nodes[index])
- nova.aggregates.add_host(aggregate=agg_id, host=sample_nodes[index])
|