Add Rest API to get availability zone list

Change-Id: I3a30a908098ae1024095f5fcfccf370f4ef790b8
This commit is contained in:
Yichen Wang 2015-12-07 15:04:22 -08:00
parent 5393e5928c
commit 6bbe5b9dbb
3 changed files with 69 additions and 0 deletions

View File

@ -100,6 +100,19 @@ class ConfigController(object):
return json.dumps(ret_dict)
@expose(generic=True)
@check_session_id
def az_list(self, *args):
session_id = args[0]
kb_session = KBSessionManager.get(session_id)
kloudbuster = kb_session.kloudbuster
ret_dict = {}
ret_dict['server'] = kloudbuster.get_az_list(kloudbuster.server_cred)
if not kloudbuster.single_cloud:
ret_dict['client'] = kloudbuster.get_az_list(kloudbuster.client_cred)
return json.dumps(ret_dict)
@expose(generic=True)
@check_session_id
def topology_config(self, *args):

View File

@ -28,6 +28,30 @@ paths:
type: string
format: json
/config/az_list/{session_id}:
get:
description: |
Get the available availability zone list
parameters:
- name: session_id
type: string
format: md5sum
in: path
description: The session to be queried
required: true
tags:
- config
responses:
200:
description: |
The available availability zones for the session
schema:
$ref: '#/definitions/AZ_List'
400:
description: Cannot get the availability zone list
404:
description: The session_id is not found or invalid
/config/hypervisor_list/{session_id}:
get:
description: |
@ -401,6 +425,20 @@ definitions:
type: string
format: json
description: Tenant and User list for reusing
AZ_List:
properties:
server:
type: array
items:
type: string
format: json
description: Available availability zones for server cloud
client:
type: array
items:
type: string
format: json
description: Available availability zones for client cloud
Hypervisor_List:
properties:
server:

View File

@ -257,6 +257,24 @@ class KloudBuster(object):
return ret_list
def get_az_list(self, cred):
creden_nova = {}
ret_list = []
cred_dict = cred.get_credentials()
creden_nova['username'] = cred_dict['username']
creden_nova['api_key'] = cred_dict['password']
creden_nova['auth_url'] = cred_dict['auth_url']
creden_nova['project_id'] = cred_dict['tenant_name']
creden_nova['version'] = 2
nova_client = novaclient(**creden_nova)
for az in nova_client.availability_zones.list():
zoneName = vars(az)['zoneName']
isAvail = vars(az)['zoneState']['available']
if zoneName != 'internal' and isAvail:
ret_list.append(zoneName)
return ret_list
def check_and_upload_images(self, retry_count=150):
retry = 0
keystone_list = [create_keystone_client(self.server_cred)[0],