1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.high##############################################################################
# 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])
|