Skip to content
Permalink
Browse files
Begin refactoring instances.py
  • Loading branch information
brogand93 committed Jun 15, 2014
1 parent 5bb67d5 commit b443e52121d5be9f59c6818588c7acfa538b1439
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
@@ -126,7 +126,6 @@ def listimages(projectid, authorization):
'template_name_or_list': 'images.json',
'selflink': request.base_url,
'request_id': 'projects/' + projectid + '/global/images',
'request_kind': 'compute#imageList',
'response': image_list['listtemplatesresponse']
}
return helpers.successful_response(
@@ -220,47 +220,29 @@ def aggregatedlistinstances(authorization, projectid):
@authentication.required
def listinstances(authorization, projectid, zone):
instance = None
filter = helpers.get_filter(request.args)

filter = helpers.get_filter(request.args)
virtual_machines = {}
if 'name' in filter:
instance = filter['name']

items = []

if instance:
virtual_machine = _get_virtual_machine_by_name(
virtual_machines['virtualmachine'] = _get_virtual_machine_by_name(
authorization=authorization,
instance=instance
)
if virtual_machine:
items.append(
_cloudstack_virtual_machine_to_gce(
cloudstack_response=virtual_machine,
projectid=projectid,
zone=zone
)
)
else:
virtual_machine_list = _get_virtual_machines(
authorization=authorization)
if virtual_machine_list['listvirtualmachinesresponse']:
for instance in virtual_machine_list['listvirtualmachinesresponse']['virtualmachine']:
items.append(
_cloudstack_virtual_machine_to_gce(
cloudstack_response=instance,
projectid=projectid,
zone=zone,
)
)

populated_response = {
'kind': 'compute#instance_list',
'id': 'projects/' + projectid + '/instances',
'selfLink': request.base_url,
'items': items
virtual_machines = _get_virtual_machines(authorization=authorization)
virtual_machines = virtual_machines['listvirtualmachinesresponse']

kwargs = {
'template_name_or_list': 'instances.json',
'selflink': request.base_url,
'zone':zone,
'request_id': 'projects/' + projectid + '/instances',
'response': virtual_machines
}

return helpers.create_response(data=populated_response)
return helpers.successful_response(**kwargs)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['GET'])
@@ -1,7 +1,8 @@
{% extends "response.json" %}{% block response_content %}
"kind": "compute#imageList",
"items":[{% for image in response.template %}
{
"creationTimestamp":"{{response.template|length}}",
"creationTimestamp":"{{image.created}}",
"description":"{{image.displaytext}}",
"id":"{{image.id}}",
"kind":"compute#image",
@@ -0,0 +1,32 @@
{% extends "response.json" %}{% block response_content %}
"kind": "compute#instanceList",
"items":[{% for instance in response.virtualmachine %}
{
"creationTimestamp":"{{instance.created}}",
"description":"{{instance.name}}",
"id":"{{instance.id}}",
"status":"{{instance.state}}",
"image":"{{instance.templatename}}",
"machineType":"{{instance.serviceofferingname}}",
"kind":"compute#instance",
"name":"{{instance.name}}",
"selfLink":"instances/{{instance.name}}",,
"canIpForward":"true",
"networkInterfaces": [{% if 'securitygroup' in instance %}
"network":"{{instance.securitygroup.0.name}}",
{% if 'nic' in instance %}
"networkIP":"{{instance.nic.0.ipaddress}}",
"name":"{{instance.nic.0.id}}",
"natIP":"{{instance.nic.0.ipaddress}}",
{% endif %}
"accessConfigs":[
"kind": "compute#accessConfig",
"type": "ONE_TO_ONE_NAT",
"name": "External NAT"
]{% endif %}
],
"disks": [],
"zone": "{{zone}}"
}{% if loop.index < response.virtualmachine|length %},{% endif %}{% endfor %}
]
{% endblock %}
@@ -1,6 +1,5 @@
{
{% if not error %}"id":"{{request_id}}",
"kind":"{{request_kind}}",
"selfLink":"{{selflink}}",{% block response_content %}
{% endblock %}{% endif %}
}

0 comments on commit b443e52

Please sign in to comment.