Index: libcloud/drivers/ibm.py =================================================================== --- libcloud/drivers/ibm.py (revision 0) +++ libcloud/drivers/ibm.py (revision 0) @@ -0,0 +1,131 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# libcloud.org licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Copyright 2009 RedRata Ltd +""" +Driver for the IBM Developer Cloud. +""" +from libcloud.types import NodeState, InvalidCredsException, Provider +from libcloud.base import Response, ConnectionUserAndKey, NodeDriver, Node, NodeImage, NodeSize, NodeLocation +import base64 + +from xml.etree import ElementTree as ET + +HOST = 'www-180.ibm.com' +REST_BASE = '/cloud/developer/api/rest/20090403/' + +class IBMResponse(Response): + def success(self): + return int(self.status) == 200 + + def parse_body(self): + if not self.body: + return None + return ET.XML(self.body) + + def parse_error(self): + return "Oh noes! We encountered an error!" + +class IBMConnection(ConnectionUserAndKey): + """ + Handles the connection to the IBM Developer Cloud. + """ + host = HOST + responseCls = IBMResponse + + def add_default_headers(self, headers): + headers['Accept'] = 'text/xml' + headers['Authorization'] = ('Basic %s' + % (base64.b64encode('%s:%s' % (self.user_id, self.key)))) + return headers + +class IBMNodeDriver(NodeDriver): + """ + IBM Developer Cloud node driver. + """ + connectionCls = IBMConnection + type = Provider.IBM + name = "IBM Developer Cloud" + + NODE_STATE_MAP = { 0: NodeState.PENDING, + 1: NodeState.PENDING, + 2: NodeState.TERMINATED, + 3: NodeState.TERMINATED, + 4: NodeState.TERMINATED, + 5: NodeState.RUNNING, + 6: NodeState.UNKNOWN, + 7: NodeState.PENDING, + 8: NodeState.REBOOTING, + 9: NodeState.PENDING, + 10: NodeState.PENDING, + 11: NodeState.TERMINATED } + + def create_node(self, **kwargs): + pass + + def destroy_node(self, node): + pass + + def reboot_node(self, node): + pass + + def deploy_node(self, **kwargs): + pass + + def list_nodes(self): + return self._to_nodes(self.connection.request(REST_BASE + 'instances').object) + + def list_images(self, location = None): + return self._to_images(self.connection.request(REST_BASE + 'images').object) + + def list_sizes(self, location = None): + # IBM Developer Cloud instances currently support SMALL, MEDIUM, and + # LARGE. Storage also supports SMALL, MEDIUM, and LARGE. + # TODO: could retrieve these dynamically from GET /locations. + return [ NodeSize(0, 'SMALL', None, None, None, None, self.connection.driver), + NodeSize(1, 'MEDIUM', None, None, None, None, self.connection.driver), + NodeSize(2, 'LARGE', None, None, None, None, self.connection.driver) ] + + def list_locations(self): + return self._to_locations(self.connection.request(REST_BASE + 'locations').object) + + def _to_nodes(self, object): + return [ self._to_node(instance) for instance in object.findall('Instance') ] + + + def _to_node(self, instance): + return Node(id = instance.findtext('ID'), + name = instance.findtext('Name'), + state = self.NODE_STATE_MAP[int(instance.findtext('Status'))], + public_ip = instance.findtext('IP'), + private_ip = instance.findtext('IP'), + driver = self.connection.driver) + + def _to_images(self, object): + 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'), + driver = self.connection.driver) + + 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 + return NodeLocation(id = location.findtext('ID'), + name = location.findtext('Name'), + country = 'USA', + driver = self.connection.driver) Index: test/test_ibm.py =================================================================== --- test/test_ibm.py (revision 0) +++ test/test_ibm.py (revision 0) @@ -0,0 +1,73 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# libcloud.org licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +import unittest +import httplib + +from test.file_fixtures import FileFixtures +from libcloud.drivers.ibm import IBMNodeDriver as IBM +from libcloud.base import Node, NodeImage, NodeSize +from test import MockHttp, TestCaseMixin +from secrets import IBM_USER, IBM_SECRET + +class IBMTests(unittest.TestCase, TestCaseMixin): + """ + Tests the IBM Developer Cloud driver. + """ + + def setUp(self): + IBM.connectionCls.conn_classes = (None, IBMMockHttp) + IBMMockHttp.type = None + self.driver = IBM(IBM_USER, IBM_SECRET) + + def test_auth(self): + self.fail('not yet implemented!') + + def test_list_nodes(self): + self.fail('not yet implemented') + + def test_list_sizes(self): + self.fail('not yet implemented') + + def test_list_images(self): + ret = self.driver.list_images() + self.assertEqual(len(ret), 21) + self.assertEqual(ret[10].name, "Rational Asset Manager 7.2.0.1") + + def test_create_node(self): + self.fail('not yet implemented') + + def test_destroy_node(self): + self.fail('not yet implemented') + + def test_reboot_node(self): + self.fail('not yet implemented') + +class IBMMockHttp(MockHttp): + fixtures = FileFixtures('ibm') + + def _cloud_developer_api_rest_20090403_instances(self, method, url, body, headers): + print 'enter enter response_instances(' + method + ' ' + url + ' ' + body + ')' + pass + + def _cloud_developer_api_rest_20090403_images(self, method, url, body, headers): + print 'enter response_images(' + method + ' ' + url + ')' + body = self.fixtures.load('cloud_developer_api_rest_20090403_images.xml') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + + def _cloud_developer_api_rest_20090403_locations(self, method, url, body, headers): + print 'enter response_locations(' + method + ' ' + url + ' ' + body + ')' + pass + +if __name__ == '__main__': + sys.exit(unittest.main()) \ No newline at end of file Index: test/fixtures/ibm/cloud_developer_api_rest_20090403_images.xml =================================================================== --- test/fixtures/ibm/cloud_developer_api_rest_20090403_images.xml (revision 0) +++ test/fixtures/ibm/cloud_developer_api_rest_20090403_images.xml (revision 0) @@ -0,0 +1,2 @@ + +2fd2d0478b132490897526b9b4433a334Rational Build Forge Agent11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2Rational Build Forge provides an adaptive process execution framework that automates, orchestrates, manages, and tracks all the processes between each handoff within the assembly line of software development, creating an automated software factory.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:00384e900960c3d4b648fa6d4670aed2cd1SUSE 10 SP211SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2SuSE v10.2 Base OS Imagehttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{07F112A1-84A7-72BF-B8FD-B36011E0E433}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{07F112A1-84A7-72BF-B8FD-B36011E0E433}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:0015a72d3e7bb1cb4942ab0da2968e2e77bbWebSphere Application Server and Rational Agent Controller11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2WebSphere Application Server and Rational Agent Controller enables a performance based foundation to build, reuse, run, integrate and manage Service Oriented Architecture (SOA) applications and services.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{86E8E71D-29A3-86DE-8A26-792C5E839D92}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{86E8E71D-29A3-86DE-8A26-792C5E839D92}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:00117da905ba0fdf4d8b8f94e7f4ef43c1beRational Insight11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2Rational Insight helps organizations reduce time to market, improve quality, and take greater control of software and systems development and delivery. It provides objective dashboards and best practice metrics to identify risks, status, and trends.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{4F774DCF-1469-EAAB-FBC3-64AE241CF8E8}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{4F774DCF-1469-EAAB-FBC3-64AE241CF8E8}/1.0/GettingStarted.htmlLARGE2009-04-25T00:00:00.000-04:0018edf7ad43f75943b1b0c0f915dba8d86cDB2 Express-C11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2DB2 Express-C is an entry-level edition of the DB2 database server for the developer community. It has standard relational functionality and includes pureXML, and other features of DB2 for Linux, Unix, and Windows (LUW).https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{E69488DE-FB79-63CD-E51E-79505A1309BD}/2.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{E69488DE-FB79-63CD-E51E-79505A1309BD}/2.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:0021c03be6800bf043c0b44c584545e04099Informix Dynamic Server Developer Edition11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2Informix Dynamic Server (IDS) Developer Edition is a development version of the IDS Enterprise Edition. IDS is designed to meet the database server needs of small-size to large-size enterprise businesses.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{9B0C8F66-9639-CA0A-0A94-7928D7DAD6CB}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{9B0C8F66-9639-CA0A-0A94-7928D7DAD6CB}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:00229b2b6482ba374a6ab4bb3585414a910aWebSphere sMash with AppBuilder11SYSTEMPUBLICi386SUSE Linux Enterprise/10 SP2WebSphere sMash® provides a web platform that includes support for dynamic scripting in PHP and Groovy.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{88E74AC6-9CCB-2710-7E9B-936DA2CE496C}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{88E74AC6-9CCB-2710-7E9B-936DA2CE496C}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-04-25T00:00:00.000-04:001000150416662e71fae44bdba4d7bb502a09c5e7DB2 Enterprise V9.7 (32-bit, 90-day trial)11leonsp@ca.ibm.comPUBLICi386SuSE v10.2DB2 Enterprise V9.7 (32-bit, 90-day trial)https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{38F2AB86-9F03-E463-024D-A9ABC3AE3831}/2.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{38F2AB86-9F03-E463-024D-A9ABC3AE3831}/2.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-11-09T17:01:28.000-05:00100020639da8863714964624b8b13631642c785bRHEL 5.4 Base OS11youngdj@us.ibm.comPUBLICi386Redhat Enterprise Linux (32-bit)/5.4Red Hat Enterprise Linux 5.4 Base OShttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{34904879-E794-A2D8-2D7C-2E8D6AD6AE77}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{34904879-E794-A2D8-2D7C-2E8D6AD6AE77}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2009-11-18T13:51:12.000-05:0010002573e5f09a64667e4faeaf3ac661600ec6caRational Build Forge11leighw@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2Rational Build Forge provides an adaptive process execution framework that automates, orchestrates, manages, and tracks all the processes between each handoff within the assembly line of software development, creating an automated software factory.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{22E039C6-108E-B626-ECC9-E2C9B62479FF}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{22E039C6-108E-B626-ECC9-E2C9B62479FF}/1.0/GettingStarted.htmlMEDIUMLARGE2009-12-08T16:34:37.000-05:00100030563e276d758ed842caafe77770d60dedeaRational Asset Manager 7.2.0.111gmendel@us.ibm.comPUBLICi386Redhat Enterprise Linux (32-bit)/5.4Rational Asset Manager helps to create, modify, govern, find and reuse development assets, including SOA and systems development assets. It facilitates the reuse of all types of software development related assets, potentially saving development time.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{296C6DDF-B87B-327B-3E5A-F2C50C353A69}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{296C6DDF-B87B-327B-3E5A-F2C50C353A69}/1.0/GettingStarted.htmlMEDIUMLARGE2009-12-14T14:30:57.000-05:0010003854e3067f999edf4914932295cfb5f79d59WebSphere Portal/WCM 6.1.511mlamb@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2IBM® WebSphere® Portal Server enables you to quickly consolidate applications and content into role-based applications, complete with search, personalization, and security capabilities.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{279F3E12-A7EF-0768-135B-F08B66DF8F71}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{279F3E12-A7EF-0768-135B-F08B66DF8F71}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2010-01-12T18:06:29.000-05:00100038640112efd8f1e144998f2a70a165d00bd3Rational Quality Manager11brownms@gmail.comPUBLICi386Redhat Enterprise Linux (32-bit)/5.4Rational Quality Manager provides a collaborative application lifecycle management (ALM) environment for test planning, construction, and execution.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{9DA927BA-2CEF-1686-71B0-2BAC468B7445}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{9DA927BA-2CEF-1686-71B0-2BAC468B7445}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2010-01-15T09:40:12.000-05:00100038653fbf6936e5cb42b5959ad9837add054fIBM Mashup Center with IBM Lotus Widget Factory11mgilmore@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2IBM Mashup Center is an end-to-end enterprise mashup platform, supporting rapid assembly of dynamic web applications with the management, security, and governance capabilities.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{0F867D03-588B-BA51-4E18-4CE9D11AECFC}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{0F867D03-588B-BA51-4E18-4CE9D11AECFC}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2010-01-15T10:44:24.000-05:0010003780425e2dfef95647498561f98c4de356abRational Team Concert11sonia_dimitrov@ca.ibm.comPUBLICi386Redhat Enterprise Linux (32-bit)/5.4Rational Team Concert is a collaborative software delivery environment that empowers project teams to simplify, automate and govern software delivery.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{679CA6F5-1E8E-267B-0C84-F7B0B41DF1DC}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{679CA6F5-1E8E-267B-0C84-F7B0B41DF1DC}/1.0/GettingStarted.htmlMEDIUMLARGE2010-01-19T14:13:58.000-05:0010003785c4867b72f2fc43fe982e76c76c32efaaLotus Forms Turbo 3.5.111rlintern@ca.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2Lotus Forms Turbo requires no training and is designed to help customers address basic form software requirements such as surveys, applications, feedback, orders, request for submission, and more - without involvement from the IT department.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{846AD7D3-9A0F-E02C-89D2-BE250CAE2318}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{846AD7D3-9A0F-E02C-89D2-BE250CAE2318}/1.0/GettingStarted.htmlLARGE2010-01-22T13:27:08.000-05:0010005598Rational Requirements Composer11mutdosch@us.ibm.comPUBLICi386Redhat Enterprise Linux (32-bit)/5.4Rational Requirements Composer helps teams define and use requirements effectively across the project lifecycle.https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/GettingStarted.htmlMEDIUMLARGE2010-02-08T11:43:18.000-05:0010007509Rational Software Architecture11danberg@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2Rational Software Architect for WebSphere with the Cloud Client plug-ins created on 2/22/10 8:06 PMhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{2C6FB6D2-CB87-C4A0-CDE0-5AAF03E214B2}/1.1/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{2C6FB6D2-CB87-C4A0-CDE0-5AAF03E214B2}/1.1/GettingStarted.htmlLARGE2010-02-22T20:03:18.000-05:0010008319WebSphere Feature Pack for OSGi Apps and JPA 2.011radavenp@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2IBM WebSphere Application Server V7.0 Fix Pack 7, Feature Pack for OSGi Applications and Java Persistence API 2.0 Open Beta, and Feature Pack for Service Component Architecture (SCA) V1.0.1 Fix Pack V1.0.1.1https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A397B7CD-A1C7-1956-7AEF-6AB495E37958}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A397B7CD-A1C7-1956-7AEF-6AB495E37958}/1.0/GettingStarted.htmlSMALLMEDIUMLARGE2010-03-14T21:06:38.000-04:0010008273Rational Software Architect for WebSphere11danberg@us.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2Rational Software Architect for WebSphere with the Cloud Client plug-ins created on 3/15/10 12:21 PMhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{839D92BB-DEA5-9820-8E2E-AE5D0A6DEAE3}/1.1/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{839D92BB-DEA5-9820-8E2E-AE5D0A6DEAE3}/1.1/GettingStarted.htmlLARGE2010-03-15T12:17:26.000-04:0010008404Rational Application Developer11khiamt@ca.ibm.comPUBLICi386SUSE Linux Enterprise/10 SP2An Eclipse-based IDE with visual development features that helps Java developers rapidly design, develop, assemble, test, profile and deploy high quality Java/J2EE, Portal, Web/Web 2.0, Web services and SOA applications. (03/16/2010)https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{6A957586-A17A-4927-7C71-0FDE280DB66B}/1.0/parameters.xmlhttps://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{6A957586-A17A-4927-7C71-0FDE280DB66B}/1.0/GettingStarted.htmlMEDIUMLARGE2010-03-16T00:10:30.000-04:00 \ No newline at end of file Index: test/fixtures/ibm/cloud_developer_api_rest_20090403_instances.xml =================================================================== --- test/fixtures/ibm/cloud_developer_api_rest_20090403_instances.xml (revision 0) +++ test/fixtures/ibm/cloud_developer_api_rest_20090403_instances.xml (revision 0) @@ -0,0 +1 @@ + Index: test/fixtures/ibm/cloud_developer_api_rest_20090403_locations.xml =================================================================== --- test/fixtures/ibm/cloud_developer_api_rest_20090403_locations.xml (revision 0) +++ test/fixtures/ibm/cloud_developer_api_rest_20090403_locations.xml (revision 0) @@ -0,0 +1 @@ +