Imporve base controller code
diff --git a/gstack/controllers/__init__.py b/gstack/controllers/__init__.py
index 51f1269..a6c7290 100644
--- a/gstack/controllers/__init__.py
+++ b/gstack/controllers/__init__.py
@@ -32,6 +32,8 @@
for item in data:
if item['name'] == name:
return item
+ elif 'displayname' in item and item['displayname'] == name:
+ return item
return None
@@ -66,7 +68,7 @@
return None
-def _get_requested_items(authorization, args, type, projectid, to_cloudstack, zone):
+def _get_requested_items(authorization, args, type, to_cloudstack, zone, projectid):
name = None
filter = helpers.get_filter(request.args)
@@ -85,8 +87,7 @@
if cloudstack_item:
items.append(
to_cloudstack(
- cloudstack_response=cloudstack_item,
- projectid=projectid, zone=zone
+ cloudstack_response=cloudstack_item, zone=zone, projectid=projectid
)
)
else:
@@ -95,33 +96,28 @@
for cloudstack_item in cloudstack_items[type]:
items.append(
to_cloudstack(
- cloudstack_response=cloudstack_item,
- projectid=projectid, zone=zone,
- )
+ cloudstack_response=cloudstack_item, zone=zone, projectid=projectid)
)
return items
-def describe_items_aggregated(authorization, args, type, projectid, to_cloudstack):
+def describe_items_aggregated(authorization, args, type, gce_type, projectid, to_cloudstack):
from gstack.controllers import zones
- args['listAll'] = 'true'
-
items = {}
zone_list = zones.get_zone_names(authorization=authorization)
for zone in zone_list:
- zone_items = _get_requested_items(authorization, args, type, projectid, to_cloudstack, zone)
-
+ zone_items = _get_requested_items(authorization, args, type, to_cloudstack, zone, projectid)
items['zone/' + zone] = {}
- items['zone/' + zone]['instances'] = zone_items
+ items['zone/' + zone][gce_type] = zone_items
return items
-def describe_items(authorization, args, type, projectid, zone, to_cloudstack):
- items = _get_requested_items(authorization, args, type, projectid, to_cloudstack, zone)
+def describe_items(authorization, args, type, zone, projectid, to_cloudstack):
+ items = _get_requested_items(authorization, args, type, to_cloudstack, zone, projectid)
return items
\ No newline at end of file
diff --git a/gstack/controllers/disks.py b/gstack/controllers/disks.py
index 1898022..20fa073 100644
--- a/gstack/controllers/disks.py
+++ b/gstack/controllers/disks.py
@@ -88,44 +88,10 @@
@app.route('/compute/v1/projects/<projectid>/aggregated/disks', methods=['GET'])
@authentication.required
def aggregatedlistdisks(projectid, authorization):
- disk_list = _get_disks(authorization=authorization)
- zone_list = zones.get_zone_names(authorization=authorization)
-
- disk = None
- filter = helpers.get_filter(request.args)
-
- if 'name' in filter:
- disk = filter['name']
-
- items = {}
-
- for zone in zone_list:
- zone_disks = []
- if disk:
- disk = get_disk_by_name(
- authorization=authorization,
- disk=disk
- )
- if disk:
- zone_disks.append(
- _cloudstack_volume_to_gce(
- cloudstack_response=disk,
- projectid=projectid,
- zone=zone,
- )
- )
-
- elif disk_list['listvolumesresponse']:
- for disk in disk_list['listvolumesresponse']['volume']:
- zone_disks.append(
- _cloudstack_volume_to_gce(
- cloudstack_response=disk,
- projectid=projectid,
- zone=zone,
- )
- )
- items['zone/' + zone] = {}
- items['zone/' + zone]['disks'] = zone_disks
+ args = {'command':'listVolumes'}
+ items = controllers.describe_items_aggregated(
+ authorization, args, 'volume',
+ projectid, _cloudstack_volume_to_gce)
populated_response = {
'kind': 'compute#diskAggregatedList',
@@ -140,43 +106,10 @@
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks', methods=['GET'])
@authentication.required
def listdisks(projectid, authorization, zone):
- disk = None
- filter = helpers.get_filter(request.args)
-
- if 'name' in filter:
- disk = filter['name']
-
- items = []
-
- if disk:
- disk_list = _get_disks(
- authorization=authorization,
- args={'keyword': disk}
- )
- if disk_list['listvolumesresponse']:
- disk = controllers.filter_by_name(
- data=disk_list['listvolumesresponse']['volume'],
- name=disk
- )
- if disk:
- items.append(
- _cloudstack_volume_to_gce(
- cloudstack_response=disk,
- projectid=projectid,
- zone=zone
- )
- )
- else:
- disk_list = _get_disks(authorization=authorization)
- if disk_list['listvolumesresponse']:
- for disk in disk_list['listvolumesresponse']['volume']:
- items.append(
- _cloudstack_volume_to_gce(
- cloudstack_response=disk,
- projectid=projectid,
- zone=zone
- )
- )
+ args = {'command':'listVolumes'}
+ items = controllers.describe_items(
+ authorization, args, 'volume',
+ projectid, zone, _cloudstack_volume_to_gce)
populated_response = {
'kind': 'compute#imageList',
diff --git a/gstack/controllers/firewalls.py b/gstack/controllers/firewalls.py
index 34fb736..3286390 100755
--- a/gstack/controllers/firewalls.py
+++ b/gstack/controllers/firewalls.py
@@ -61,32 +61,10 @@
@app.route('/compute/v1/projects/<projectid>/global/firewalls', methods=['GET'])
@authentication.required
def listsecuritygroups(projectid, authorization):
- command = 'listSecurityGroups'
- args = {}
- cloudstack_response = requester.make_request(
- command,
- args,
- authorization.client_id,
- authorization.client_secret
- )
-
- cloudstack_response = cloudstack_response
-
- app.logger.debug(
- 'Processing request for aggregated list Firewalls\n'
- 'Project: ' + projectid + '\n' +
- json.dumps(cloudstack_response, indent=4, separators=(',', ': '))
- )
-
- firewalls = []
- if cloudstack_response['listsecuritygroupsresponse']:
- res = cloudstack_response['listsecuritygroupsresponse']
- for response_item in res['securitygroup']:
- firewalls.append(response_item)
-
- items = []
- for fw in firewalls:
- items.append(_cloudstack_securitygroup_to_gce(fw))
+ args = {'command':'listSecurityGroups'}
+ items = controllers.describe_items(
+ authorization, args, 'securitygroup',
+ projectid, zone, _cloudstack_securitygroup_to_gce)
populated_response = {
'kind': 'compute#firewallList',
diff --git a/gstack/controllers/instances.py b/gstack/controllers/instances.py
index 8ac2441..3caecc1 100755
--- a/gstack/controllers/instances.py
+++ b/gstack/controllers/instances.py
@@ -145,7 +145,6 @@
))
response['zone'] = zone
- print response
return response
@@ -172,7 +171,7 @@
def aggregatedlistinstances(authorization, projectid):
args = {'command':'listVirtualMachines'}
items = controllers.describe_items_aggregated(
- authorization, args, 'virtualmachine',
+ authorization, args, 'virtualmachine', 'instances',
projectid, _cloudstack_virtual_machine_to_gce)
populated_response = {
@@ -190,7 +189,7 @@
args = {'command':'listVirtualMachines'}
items = controllers.describe_items(
authorization, args, 'virtualmachine',
- projectid, zone, _cloudstack_virtual_machine_to_gce)
+ zone, projectid, _cloudstack_virtual_machine_to_gce)
populated_response = {
'kind': 'compute#instance_list',