libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Reategui (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LIBCLOUD-439) Cloudstack list_nodes does not fill in image field
Date Fri, 15 Nov 2013 08:31:25 GMT

    [ https://issues.apache.org/jira/browse/LIBCLOUD-439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13823387#comment-13823387
] 

Carlos Reategui edited comment on LIBCLOUD-439 at 11/15/13 8:31 AM:
--------------------------------------------------------------------

I decided to go ahead and patch my cloudstack.py because I need to display the image name
and instance size when listing nodes.  Here is the diff for my changes. Hope the part for
the no longer available images is not too hackinsh.  [~kami], [~sebgoa] Let me know what you
think.  Note it also includes the updates from LIBCLOUD-438

{code}
$ diff -u apache-libcloud-0.13.2/libcloud/compute/drivers/cloudstack.py cloudstack.py
--- apache-libcloud-0.13.2/libcloud/compute/drivers/cloudstack.py       2013-09-15 08:40:43.000000000
-0700
+++ cloudstack.py       2013-11-15 00:25:31.785019200 -0800
@@ -198,7 +198,21 @@
         """
         vms = self._sync_request('listVirtualMachines')
         addrs = self._sync_request('listPublicIpAddresses')
+        args = {
+            'templatefilter': 'executable'
+        }
+        imgs = self._sync_request('listTemplates', **args)
 
+        img_map={}
+        for img in imgs.get('template', []):
+            img_map[img['id']]=NodeImage(
+                id=img['id'],
+                name=img['name'],
+                driver=self.connection.driver,
+                extra={'hypervisor': img['hypervisor'],
+                       'format': img['format'],
+                       'os': img['ostypename']})
+        
         public_ips_map = {}
         for addr in addrs.get('publicipaddress', []):
             if 'virtualmachineid' not in addr:
@@ -229,7 +243,14 @@
                 public_ips=public_ips,
                 private_ips=private_ips,
                 driver=self,
-                extra={'zoneid': vm['zoneid'], }
+                image=img_map.get(vm['templateid'],
+                    NodeImage(id=vm['templateid'],
+                    name='**No longer Available ('+vm['templatename']+')**',
+                    driver=self.connection.driver)),
+                extra={'zoneid': vm['zoneid'], 
+                       'size': NodeSize(vm['serviceofferingid'], 
+                                        vm['serviceofferingname'], 
+                                        vm['memory'], 0, 0, 0, self), }
             )
 
             addrs = public_ips_map.get(vm['id'], {}).items()
@@ -597,8 +618,9 @@
 
         extra_args = kwargs.copy()
         res = self._sync_request('listSSHKeyPairs', **extra_args)
-        return res['sshkeypair']
-
+        keypairs = res.get('sshkeypair', [])
+        return keypairs
+  
     def ex_create_keypair(self, name, **kwargs):
         """
         Creates a SSH KeyPair, returns fingerprint and private key
@@ -707,8 +729,10 @@
         @rtype C{list}
         """
         extra_args = kwargs
-        return self._sync_request('listSecurityGroups',
-                                  **extra_args)['securitygroup']
+        res = self._sync_request('listSecurityGroups', **extra_args)
+
+        security_groups = res.get('securitygroup', [])
+        return security_groups
 
     def ex_create_security_group(self, name, **kwargs):
         """
{code}


was (Author: creategui):
I decided to go ahead and patch my cloudstack.py because I need to display the image name
and instance size when listing nodes.  Here is the diff for my changes.  [~kami], [~sebgoa]
Let me know what you think:

{code}
--- apache-libcloud-0.13.2/libcloud/compute/drivers/cloudstack.py       2013-09-15 08:40:43.000000000
-0700
+++ cloudstack.py       2013-11-14 23:38:56.075049400 -0800
@@ -198,7 +198,21 @@
         """
         vms = self._sync_request('listVirtualMachines')
         addrs = self._sync_request('listPublicIpAddresses')
+        args = {
+            'templatefilter': 'executable'
+        }
+        imgs = self._sync_request('listTemplates', **args)
 
+        img_map={}
+        for img in imgs.get('template', []):
+            img_map[img['id']]=NodeImage(
+                id=img['id'],
+                name=img['name'],
+                driver=self.connection.driver,
+                extra={'hypervisor': img['hypervisor'],
+                       'format': img['format'],
+                       'os': img['ostypename']})
+        
         public_ips_map = {}
         for addr in addrs.get('publicipaddress', []):
             if 'virtualmachineid' not in addr:
@@ -229,7 +243,9 @@
                 public_ips=public_ips,
                 private_ips=private_ips,
                 driver=self,
-                extra={'zoneid': vm['zoneid'], }
+                image=img_map[vm['templateid']],
+                extra={'zoneid': vm['zoneid'], 
+                       'size': NodeSize(vm['serviceofferingid'], 
+                                        vm['serviceofferingname'], 
+                                        vm['memory'], 0, 0, 0, self), }
             )
 
             addrs = public_ips_map.get(vm['id'], {}).items()
{code}

> Cloudstack list_nodes does not fill in image field
> --------------------------------------------------
>
>                 Key: LIBCLOUD-439
>                 URL: https://issues.apache.org/jira/browse/LIBCLOUD-439
>             Project: Libcloud
>          Issue Type: Bug
>          Components: Compute
>    Affects Versions: 0.13.2
>         Environment: python 2.6
>            Reporter: Carlos Reategui
>            Priority: Trivial
>
> I made the following change but not sure if it is consistent with what other drivers
put in the image field:
> --- apache-libcloud-0.13.2/libcloud/compute/drivers/cloudstack.py       2013-09-15 15:40:43.000000000
+0000
> +++ cloudstack.py       2013-11-14 04:05:26.000000000 +0000
> @@ -229,6 +229,7 @@
>                  public_ips=public_ips,
>                  private_ips=private_ips,
>                  driver=self,
> +                image=vm.get('templatename', None),
>                  extra={'zoneid': vm['zoneid'], }
>              )
> Another alternative could be templateid instead of templatename



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message