You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2020/01/28 17:55:24 UTC

[GitHub] [libcloud] jmgnc opened a new issue #1419: ec2 driver does not support strings for size and image parameters

jmgnc opened a new issue #1419: ec2 driver does not support strings for size and image parameters
URL: https://github.com/apache/libcloud/issues/1419
 
 
   ## Summary
   
   Both the GCP and the Dummy drivers for compute allow passing the imaged id, and size id as a string, and both drivers will do a lookup to find them.
   
   The EC2 driver requires that the image and size be objects that have the name as an id attribute.
   
   ## Detailed Information
   
   The commit https://github.com/newcontext-oss/openc2-aws-actuator/commit/f67cbee488236604b65c72a8f5f695fddf9592e9 fixes the issue for that code.  GCP works w/ the previous commit.
   
   This is on MacOSX 10.14.6.
   
   ```
   $python
   Python 3.6.7 (default, Oct 21 2018, 08:56:20)
   [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.2)] on darwin
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import libcloud
   >>> libcloud.__version__
   '2.7.0'
   >>> from libcloud.compute.types import Provider
   >>> from libcloud.compute.providers import get_driver
   >>> cls = get_driver(Provider.EC2)
   >>> access_key, secret_key = open('.keys').read().split()
   >>> drv = cls(access_key, secret_key, region='us-west-2')
   >>> drv.create_node(image='ami-0b74be4bc329b8a1b', size='t2.nano')
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/Users/jmg/work/openc2-aws-actuator/p/lib/python3.6/site-packages/libcloud/compute/drivers/ec2.py", line 1891, in create_node                                                           
       'ImageId': image.id,
   AttributeError: 'str' object has no attribute 'id'
   >>> from mock import MagicMock
   >>> img = MagicMock()
   >>> img.id = 'ami-0b74be4bc329b8a1b'
   >>> sizeobj = MagicMock()
   >>> sizeobj.id = 't2.nano'
   >>> drv.create_node(image=img, size=sizeobj, name='somename')
   <Node: uuid=2ba587a276a105f6676e4df1957ff89926206dbb, name=somename, state=PENDING, public_ips=[], private_ips=['172.31.37.77'], provider=Amazon EC2 ...>                                       
   >>> 
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] jmgnc commented on issue #1419: ec2 driver does not support strings for size and image parameters

Posted by GitBox <gi...@apache.org>.
jmgnc commented on issue #1419: ec2 driver does not support strings for size and image parameters
URL: https://github.com/apache/libcloud/issues/1419#issuecomment-606320053
 
 
   The biggest issue I see with this is that GCP does not present all of the images as part of list_images  (current count is 80 images, and this clearly doesn't include images that are available in the marketplace and the like).  If drivers don't present these instances, and it isn't defined HOW to instantiate a NodeImage or NodeSize class, then saying you must use an instance isn't helpful.
   
   Also, GCP does not implement get_image:
   ```
   >>> drv.get_image('FreeBSD')
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/Users/jmg/work/openc2-aws-actuator/p/lib/python3.6/site-packages/libcloud/compute/base.py", line 1343, in get_image
       'get_image not implemented for this driver')
   NotImplementedError: get_image not implemented for this driver
   ```
   
   So, there is no way to create a NodeImage other than the 80 that GCP provide, and that is problematic.
   
   In fact, the docs for NodeImage pretty much tell you NOT to create your own (from https://libcloud.apache.org/apidocs/0.4.2/libcloud.base.NodeImage.html):
   ```
   NodeImage objects are typically returned by the driver for the cloud provider in response to the list_images function
   
   >>> from libcloud.drivers.dummy import DummyNodeDriver
   >>> driver = DummyNodeDriver(0)
   >>> image = driver.list_images()[0]
   >>> image.name
   'Ubuntu 9.10'
   Apart from name and id, there is no further standard information; other parameters are stored in a driver specific "extra" variable
   
   When creating a node, a node image should be given as an argument to the create_node function to decide which OS image to use.
   
   >>> node = driver.create_node(image=image)
   ```
   
   I'll also note that these docs only say that a NodeImage *SHOULD* be given instead of *MUST* be given.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [libcloud] Kami commented on issue #1419: ec2 driver does not support strings for size and image parameters

Posted by GitBox <gi...@apache.org>.
Kami commented on issue #1419: ec2 driver does not support strings for size and image parameters
URL: https://github.com/apache/libcloud/issues/1419#issuecomment-579748574
 
 
   Thanks for reporting this.
   
   This works as designed / intended. Base compute API declares those arguments to be of a type of NodeImage and NodeSize.
   
   If any of the drivers supports string notation, that's because they don't comply with the base compute API.
   
   In the past, we didn't have a good automated way to enforce compliance with the base API so some things like that have slipped through, but going forward, some of that will be easier with the MyPy support.
   
   In short, in scenarios like that, you need to instantiate ``NodeImage`` and ``NodeSize`` classes yourself manually (although some drivers may offer convenience extension methods for that).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services