Author: tomaz
Date: Wed May 16 03:02:29 2012
New Revision: 1338979
URL: http://svn.apache.org/viewvc?rev=1338979&view=rev
Log:
Update IBM SBC driver so it works with IBM SCE. This patch has been contributed
by Sengor Kusturica and is part of LIBCLOUD-195.
Modified:
libcloud/trunk/CHANGES
libcloud/trunk/libcloud/compute/drivers/ibm_sbc.py
libcloud/trunk/test/compute/fixtures/ibm_sbc/locations.xml
libcloud/trunk/test/compute/test_ibm_sbc.py
Modified: libcloud/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1338979&r1=1338978&r2=1338979&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Wed May 16 03:02:29 2012
@@ -1,5 +1,12 @@
-*- coding: utf-8 -*-
+Changes with Apache Libcloud in development:
+
+ *) Compute:
+ - Update IBM SBC driver so it works with IBM Smart Cloud Enterprise.
+ ; LIBCLOUD-195
+ [Sengor Kusturica]
+
Changes with Apache Libcloud 0.10.0:
*) Compute:
Modified: libcloud/trunk/libcloud/compute/drivers/ibm_sbc.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/ibm_sbc.py?rev=1338979&r1=1338978&r2=1338979&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/ibm_sbc.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/ibm_sbc.py Wed May 16 03:02:29 2012
@@ -14,7 +14,11 @@
# limitations under the License.
"""
-Driver for the IBM Developer Cloud.
+Driver for IBM SmartCloud Enterprise
+
+Formerly known as:
+- IBM Developer Cloud.
+- IBM SmartBusiness Cloud
"""
import base64
@@ -66,11 +70,11 @@ class IBMConnection(ConnectionUserAndKey
class IBMNodeDriver(NodeDriver):
"""
- IBM Developer Cloud node driver.
+ Node driver for IBM SmartCloud Enterprise
"""
connectionCls = IBMConnection
type = Provider.IBM
- name = "IBM Developer Cloud"
+ name = "IBM SmartCloud Enterprise"
NODE_STATE_MAP = {0: NodeState.PENDING, # New
1: NodeState.PENDING, # Provisioning
@@ -162,6 +166,10 @@ class IBMNodeDriver(NodeDriver):
return self._to_images(self.connection.request(REST_BASE +
'/offerings/image').object)
def list_sizes(self, location = None):
+ """
+ Returns a generic list of sizes. See list_images() for a list of
supported sizes for specific
+ images.
+ """
return [NodeSize('BRZ32.1/2048/60*175', 'Bronze 32 bit', None, None,
None, None, self.connection.driver),
NodeSize('BRZ64.2/4096/60*500*350', 'Bronze 64 bit', None,
None, None, None, self.connection.driver),
NodeSize('COP32.1/2048/60', 'Copper 32 bit', None, None, None,
None, self.connection.driver),
@@ -193,20 +201,60 @@ class IBMNodeDriver(NodeDriver):
driver=self.connection.driver)
def _to_images(self, object):
+ # Converts data retrieved from SCE /offerings/image REST call to a
NodeImage
return [self._to_image(image) for image in object.findall('Image')]
def _to_image(self, image):
- return NodeImage(id=image.findtext('ID'),
- name=image.findtext('Name'),
+ # Converts an SCE Image object to a NodeImage
+ imageID=image.findtext('ID')
+ imageName=image.findtext('Name')
+ parametersURL=image.findtext('Manifest')
+ location=image.findtext('Location')
+ state=image.findtext('State')
+ owner=image.findtext('Owner')
+ visibility=image.findtext('Visibility')
+ platform=image.findtext('Platform')
+ description=image.findtext('Description')
+ documentation=image.findtext('Documentation')
+ instanceTypes=image.findall('SupportedInstanceTypes')
+ nodeSizes=self._to_node_sizes(image.find('SupportedInstanceTypes'))
+ return NodeImage(id=imageID,
+ name=imageName,
driver=self.connection.driver,
- extra={'parametersURL': image.findtext('Manifest')})
+ extra={'parametersURL': parametersURL,
+ 'location' : location,
+ 'state' : state,
+ 'owner' : owner,
+ 'visibility' : visibility,
+ 'platform' : platform,
+ 'description' : description,
+ 'documentation' : documentation,
+ 'supportedInstanceTypes' : nodeSizes
+ }
+ )
def _to_locations(self, object):
return [self._to_location(location) for location in
object.findall('Location')]
def _to_location(self, location):
- # NOTE: country currently hardcoded
+ # Converts an SCE Location object to a Libcloud NodeLocation object
+ name_text = location.findtext('Name')
+ (nameVal, separator, countryVal) = name_text.partition(',')
return NodeLocation(id=location.findtext('ID'),
- name=location.findtext('Name'),
- country='US',
+ name=nameVal,
+ country=countryVal.strip(),
driver=self.connection.driver)
+
+ def _to_node_sizes(self, object):
+ # Converts SCE SupportedInstanceTypes object to a list of Libcloud
NodeSize objects
+ return [self._to_node_size(iType) for iType in
object.findall('InstanceType')]
+
+ def _to_node_size(self, object):
+ # Converts to an SCE InstanceType to a Libcloud NodeSize
+ return NodeSize(object.findtext('ID'),
+ object.findtext('Label'),
+ None,
+ None,
+ None,
+ object.findtext('Price/Rate'),
+ self.connection.driver)
Modified: libcloud/trunk/test/compute/fixtures/ibm_sbc/locations.xml
URL:
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/fixtures/ibm_sbc/locations.xml?rev=1338979&r1=1338978&r2=1338979&view=diff
==============================================================================
--- libcloud/trunk/test/compute/fixtures/ibm_sbc/locations.xml (original)
+++ libcloud/trunk/test/compute/fixtures/ibm_sbc/locations.xml Wed May 16
03:02:29 2012
@@ -1 +1 @@
-<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><ns2:DescribeLocationsResponse
xmlns:ns2="http://www.ibm.com/xmlns/b2b/cloud/api/2009-04-03"><Location><ID>1</ID><Name>US
North East: Poughkeepsie,
NY</Name><Description></Description><Location>POK</Location><Capabilities><Capability
id="oss.storage.capacity"><Entry key="SMALL"><Value>50</Value></Entry><Entry
key="MEDIUM"><Value>100</Value></Entry><Entry
key="LARGE"><Value>200</Value></Entry></Capability><Capability
id="oss.storage.format"><Entry
key="EXT3"><Value>ext3</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"><Entry
key="SMALL"><Value>SMALL</Value></Entry><Entry
key="MEDIUM"><Value>MEDIUM</Value></Entry><Entry
key="LARGE"><Value>LARGE</Value></Entry></Capability><Capability
id="oss.instance.spec.x86_64"/></Capabilities></Location></ns2:DescribeLocationsResponse>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><ns2:DescribeLocationsResponse
xmlns:ns2="http://www.ibm.com/xmlns/b2b/cloud/api/2010-03-31"><Location><ID>41</ID><Name>Raleigh,
U.S.A</Name><Description>This data center is located in Raleigh, North
Carolina, U.S.A. The services provided are: Guest Instances, Image Capture,
Persistent Storage, Reserved IP, Private
VLAN/VPN.</Description><Location>RTP</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"><Entry
key="2"><Value>Area2</Value><Value>gpfs2 of SONAS1</Value></Entry><Entry
key="1"><Value>Area1</Value><Value>gpfs1 of
SONAS1</Value></Entry></Capability></Capabilities><State>1</State></Location><Location><ID>61</ID><Name>Ehningen,
Germany</Name><Description>This data center is loca
ted in Ehningen(near Baden-Wurttemberg), Germany. The services provided are:
Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private
VLAN/VPN.</Description><Location>EHN</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"><Entry
key="4"><Value>Area2</Value><Value>gpfs2 of SONAS1</Value></Entry><Entry
key="3"><Value>Area1</Value><Value>gpfs1 of
SONAS1</Value></Entry></Capability></Capabilities><State>1</State></Location><Location><ID>82</ID><Name>Boulder1,
U.S.A</Name><Description>This data center is located in Boulder(near Denver),
Colorado, U.S.A. The services provided are: Guest Instances, Image Capture,
Persistent Storage, Reserved IP, Private
VLAN/VPN.</Description><Location>us-co-dc1</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"/></Capabilities><State>1</State></Location><Location><ID>101</ID><Name>Markham,
Canada</Name><Description>This data center is located in Markham(near
Toronto), Ontario, Canada. The services provided are: Guest Instances, Image
Capture, Persistent Storage, Reserved IP, Private
VLAN/VPN.</Description><Location>ca-on-dc1</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"/></Capabilities><State>1</State></Location><Location><ID>121</ID><Name>Makuhari,
Japan</Name><Description>This data center
is located in Makuhari(near Tokoyo), Japan. The services provided are: Guest
Instances, Image Capture, Persistent Storage, Reserved IP, Private
VLAN/VPN.</Description><Location>ap-jp-dc1</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"/></Capabilities><State>1</State></Location><Location><ID>141</ID><Name>Singapore,
Singapore</Name><Description>This data center is located in Singapore. The
services provided are: Guest Instances, Image Capture, Persistent Storage,
Reserved IP, Private
VLAN/VPN.</Description><Location>ap-sg-dc1</Location><Capabilities><Capability
id="oss.storage.format"><Entry key="EXT3"><Value>ext3</Value></Entry><Entry
key="RAW"><Value>raw</Value></Entry></Capability><Capability
id="oss.instance.spec.i386"/><Capability
id="oss.instance.spec.x86_64"/><Capability
id="oss.storage.availabilityarea"/></Capabilities><State>1</State></Location></ns2:DescribeLocationsResponse>
\ No newline at end of file
Modified: libcloud/trunk/test/compute/test_ibm_sbc.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_ibm_sbc.py?rev=1338979&r1=1338978&r2=1338979&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_ibm_sbc.py (original)
+++ libcloud/trunk/test/compute/test_ibm_sbc.py Wed May 16 03:02:29 2012
@@ -74,10 +74,10 @@ class IBMTests(unittest.TestCase, TestCa
def test_list_locations(self):
ret = self.driver.list_locations()
- self.assertEquals(len(ret), 1)
- self.assertEquals(ret[0].id, '1')
- self.assertEquals(ret[0].name, 'US North East: Poughkeepsie, NY')
- self.assertEquals(ret[0].country, 'US')
+ self.assertEquals(len(ret), 6)
+ self.assertEquals(ret[0].id, '41')
+ self.assertEquals(ret[0].name, 'Raleigh')
+ self.assertEquals(ret[0].country, 'U.S.A')
def test_create_node(self):
# Test creation of node