cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [05/50] [abbrv] cloudstack-gcestack git commit: Begin refactoring instances.py
Date Tue, 05 May 2015 11:18:39 GMT
Begin refactoring instances.py


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/commit/b443e521
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/tree/b443e521
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/diff/b443e521

Branch: refs/heads/master
Commit: b443e52121d5be9f59c6818588c7acfa538b1439
Parents: 5bb67d5
Author: BroganD1993 <darrenbrogan@hotmail.com>
Authored: Sun Jun 15 18:03:23 2014 +0100
Committer: BroganD1993 <darrenbrogan@hotmail.com>
Committed: Sun Jun 15 18:03:23 2014 +0100

----------------------------------------------------------------------
 gstack/controllers/images.py    |  1 -
 gstack/controllers/instances.py | 44 +++++++++++-------------------------
 gstack/templates/images.json    |  3 ++-
 gstack/templates/instances.json | 32 ++++++++++++++++++++++++++
 gstack/templates/response.json  |  1 -
 5 files changed, 47 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/b443e521/gstack/controllers/images.py
----------------------------------------------------------------------
diff --git a/gstack/controllers/images.py b/gstack/controllers/images.py
index c2e5ec5..b15d277 100755
--- a/gstack/controllers/images.py
+++ b/gstack/controllers/images.py
@@ -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(

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/b443e521/gstack/controllers/instances.py
----------------------------------------------------------------------
diff --git a/gstack/controllers/instances.py b/gstack/controllers/instances.py
index 4c196ae..9667e76 100755
--- a/gstack/controllers/instances.py
+++ b/gstack/controllers/instances.py
@@ -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'])

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/b443e521/gstack/templates/images.json
----------------------------------------------------------------------
diff --git a/gstack/templates/images.json b/gstack/templates/images.json
index d986853..3baa8a9 100644
--- a/gstack/templates/images.json
+++ b/gstack/templates/images.json
@@ -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",

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/b443e521/gstack/templates/instances.json
----------------------------------------------------------------------
diff --git a/gstack/templates/instances.json b/gstack/templates/instances.json
new file mode 100644
index 0000000..bd0c670
--- /dev/null
+++ b/gstack/templates/instances.json
@@ -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 %}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/b443e521/gstack/templates/response.json
----------------------------------------------------------------------
diff --git a/gstack/templates/response.json b/gstack/templates/response.json
index 1bc68d1..a32f929 100644
--- a/gstack/templates/response.json
+++ b/gstack/templates/response.json
@@ -1,6 +1,5 @@
 {
     {% if not error %}"id":"{{request_id}}",
-    "kind":"{{request_kind}}",
     "selfLink":"{{selflink}}",{% block response_content %}
     {% endblock %}{% endif %}
 }


Mime
View raw message