Updated Branches: refs/heads/trunk 5ef0707b2 -> a8aff7e19
Remove Slicehost driver. Slicehost API has been shut down in 2012 so it makes no sense to keep this driver. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6ebe04b9 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6ebe04b9 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6ebe04b9 Branch: refs/heads/trunk Commit: 6ebe04b9bda6587bf2d0cf4f4474cfb8f66974d8 Parents: 5ef0707 Author: Tomaz Muraus <[email protected]> Authored: Sat Nov 16 17:49:15 2013 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Sat Nov 16 17:55:09 2013 +0100 ---------------------------------------------------------------------- CHANGES | 10 + .../_supported_methods_block_storage.rst | 2 - docs/compute/_supported_methods_main.rst | 2 - docs/compute/_supported_providers.rst | 2 - libcloud/compute/drivers/__init__.py | 1 - libcloud/compute/drivers/slicehost.py | 235 ------------------- libcloud/compute/providers.py | 2 - libcloud/compute/types.py | 5 +- .../test/compute/fixtures/slicehost/flavors.xml | 45 ---- .../test/compute/fixtures/slicehost/images.xml | 47 ---- .../fixtures/slicehost/slices_1_reboot.xml | 15 -- .../slicehost/slices_1_reboot_forbidden.xml | 3 - .../fixtures/slicehost/slices_errors.xml | 4 - .../compute/fixtures/slicehost/slices_get.xml | 17 -- .../compute/fixtures/slicehost/slices_post.xml | 16 -- libcloud/test/compute/test_slicehost.py | 163 ------------- 16 files changed, 13 insertions(+), 556 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 1a8d9e2..d18f50f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,15 @@ -*- coding: utf-8 -*- +Changes with Apache Libcloud in development + + *) Compute + + - Remove Slicehost driver. + + SliceHost API has been shut down in 2012 so it makes no sense to keep + this driver. + [Tomaz Muraus] + Changes with Apache Libcloud 0.14.0-beta3 *) General http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/docs/compute/_supported_methods_block_storage.rst ---------------------------------------------------------------------- diff --git a/docs/compute/_supported_methods_block_storage.rst b/docs/compute/_supported_methods_block_storage.rst index edca534..ab1c8b1 100644 --- a/docs/compute/_supported_methods_block_storage.rst +++ b/docs/compute/_supported_methods_block_storage.rst @@ -51,7 +51,6 @@ Provider list volumes create volume destroy volume `RimuHosting`_ no no no no no no no `ServerLove`_ no no no no no no no `skalicloud`_ no no no no no no no -`Slicehost`_ no no no no no no no `SoftLayer`_ no no no no no no no `vCloud`_ no no no no no no no `VCL`_ no no no no no no no @@ -111,7 +110,6 @@ Provider list volumes create volume destroy volume .. _`RimuHosting`: http://rimuhosting.com/ .. _`ServerLove`: http://www.serverlove.com/ .. _`skalicloud`: http://www.skalicloud.com/ -.. _`Slicehost`: http://slicehost.com/ .. _`SoftLayer`: http://www.softlayer.com/ .. _`vCloud`: http://www.vmware.com/products/vcloud/ .. _`VCL`: http://incubator.apache.org/vcl/ http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/docs/compute/_supported_methods_main.rst ---------------------------------------------------------------------- diff --git a/docs/compute/_supported_methods_main.rst b/docs/compute/_supported_methods_main.rst index 0654f40..8d7a2e9 100644 --- a/docs/compute/_supported_methods_main.rst +++ b/docs/compute/_supported_methods_main.rst @@ -51,7 +51,6 @@ Provider list nodes create node reboot node destroy `RimuHosting`_ yes yes yes yes yes yes yes `ServerLove`_ yes yes yes yes yes yes yes `skalicloud`_ yes yes yes yes yes yes yes -`Slicehost`_ yes yes yes yes yes yes yes `SoftLayer`_ yes yes yes yes yes yes yes `vCloud`_ yes yes yes yes yes yes yes `VCL`_ yes yes yes yes yes no no @@ -111,7 +110,6 @@ Provider list nodes create node reboot node destroy .. _`RimuHosting`: http://rimuhosting.com/ .. _`ServerLove`: http://www.serverlove.com/ .. _`skalicloud`: http://www.skalicloud.com/ -.. _`Slicehost`: http://slicehost.com/ .. _`SoftLayer`: http://www.softlayer.com/ .. _`vCloud`: http://www.vmware.com/products/vcloud/ .. _`VCL`: http://incubator.apache.org/vcl/ http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/docs/compute/_supported_providers.rst ---------------------------------------------------------------------- diff --git a/docs/compute/_supported_providers.rst b/docs/compute/_supported_providers.rst index f738973..c190c4b 100644 --- a/docs/compute/_supported_providers.rst +++ b/docs/compute/_supported_providers.rst @@ -51,7 +51,6 @@ Provider Documentation `RimuHosting`_ RIMUHOSTING :mod:`libcloud.compute.drivers.rimuhosting` :class:`RimuHostingNodeDriver` `ServerLove`_ SERVERLOVE :mod:`libcloud.compute.drivers.serverlove` :class:`ServerLoveNodeDriver` `skalicloud`_ SKALICLOUD :mod:`libcloud.compute.drivers.skalicloud` :class:`SkaliCloudNodeDriver` -`Slicehost`_ SLICEHOST :mod:`libcloud.compute.drivers.slicehost` :class:`SlicehostNodeDriver` `SoftLayer`_ SOFTLAYER :mod:`libcloud.compute.drivers.softlayer` :class:`SoftLayerNodeDriver` `vCloud`_ TERREMARK :mod:`libcloud.compute.drivers.vcloud` :class:`TerremarkDriver` `VCL`_ VCL :mod:`libcloud.compute.drivers.vcl` :class:`VCLNodeDriver` @@ -111,7 +110,6 @@ Provider Documentation .. _`RimuHosting`: http://rimuhosting.com/ .. _`ServerLove`: http://www.serverlove.com/ .. _`skalicloud`: http://www.skalicloud.com/ -.. _`Slicehost`: http://slicehost.com/ .. _`SoftLayer`: http://www.softlayer.com/ .. _`vCloud`: http://www.vmware.com/products/vcloud/ .. _`VCL`: http://incubator.apache.org/vcl/ http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/compute/drivers/__init__.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/__init__.py b/libcloud/compute/drivers/__init__.py index 9c6c078..ab02a6b 100644 --- a/libcloud/compute/drivers/__init__.py +++ b/libcloud/compute/drivers/__init__.py @@ -35,7 +35,6 @@ __all__ = [ 'opennebula', 'rackspace', 'rimuhosting', - 'slicehost', 'softlayer', 'vcloud', 'voxel', http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/compute/drivers/slicehost.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/slicehost.py b/libcloud/compute/drivers/slicehost.py deleted file mode 100644 index c8e717c..0000000 --- a/libcloud/compute/drivers/slicehost.py +++ /dev/null @@ -1,235 +0,0 @@ -# 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. -# The ASF 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. -""" -Slicehost Driver -""" -import base64 -import socket - -from xml.etree import ElementTree as ET -from xml.parsers.expat import ExpatError - -from libcloud.utils.py3 import b - -from libcloud.common.base import ConnectionKey, XmlResponse -from libcloud.compute.types import NodeState, Provider, InvalidCredsError -from libcloud.compute.base import NodeSize, NodeDriver, NodeImage, NodeLocation -from libcloud.compute.base import Node, is_private_subnet - - -class SlicehostResponse(XmlResponse): - def parse_error(self): - if self.status == 401: - raise InvalidCredsError(self.body) - - body = super(SlicehostResponse, self).parse_body() - try: - return "; ".join([err.text - for err in - body.findall('error')]) - except ExpatError: - return self.body - - -class SlicehostConnection(ConnectionKey): - """ - Connection class for the Slicehost driver - """ - - host = 'api.slicehost.com' - responseCls = SlicehostResponse - - def add_default_headers(self, headers): - headers['Authorization'] = ('Basic %s' % (base64.b64encode( - b('%s:' % self.key))).decode('utf-8')) - return headers - - -class SlicehostNodeDriver(NodeDriver): - """ - Slicehost node driver - """ - - connectionCls = SlicehostConnection - - type = Provider.SLICEHOST - name = 'Slicehost' - website = 'http://slicehost.com/' - - features = {"create_node": ["generates_password"]} - - NODE_STATE_MAP = {'active': NodeState.RUNNING, - 'build': NodeState.PENDING, - 'reboot': NodeState.REBOOTING, - 'hard_reboot': NodeState.REBOOTING, - 'terminated': NodeState.TERMINATED} - - def list_nodes(self): - return self._to_nodes(self.connection.request('/slices.xml').object) - - def list_sizes(self, location=None): - return self._to_sizes(self.connection.request('/flavors.xml').object) - - def list_images(self, location=None): - return self._to_images(self.connection.request('/images.xml').object) - - def list_locations(self): - return [ - NodeLocation(0, 'Slicehost St. Louis (STL-A)', 'US', self), - NodeLocation(0, 'Slicehost St. Louis (STL-B)', 'US', self), - NodeLocation(0, 'Slicehost Dallas-Fort Worth (DFW-1)', 'US', self) - ] - - def create_node(self, **kwargs): - name = kwargs['name'] - image = kwargs['image'] - size = kwargs['size'] - uri = '/slices.xml' - - # create a slice obj - root = ET.Element('slice') - el_name = ET.SubElement(root, 'name') - el_name.text = name - flavor_id = ET.SubElement(root, 'flavor-id') - flavor_id.text = str(size.id) - image_id = ET.SubElement(root, 'image-id') - image_id.text = str(image.id) - xml = ET.tostring(root) - - node = self._to_nodes( - self.connection.request( - uri, - method='POST', - data=xml, - headers={'Content-Type': 'application/xml'} - ).object - )[0] - return node - - def reboot_node(self, node): - # 'hard' could bubble up as kwarg depending on how reboot_node - # turns out. Defaulting to soft reboot. - #hard = False - #reboot = self.api.hard_reboot if hard else self.api.reboot - #expected_status = 'hard_reboot' if hard else 'reboot' - - uri = '/slices/%s/reboot.xml' % (node.id) - node = self._to_nodes( - self.connection.request(uri, method='PUT').object - )[0] - return node.state == NodeState.REBOOTING - - def destroy_node(self, node): - """Destroys the node - - Requires 'Allow Slices to be deleted or rebuilt from the API' to be - ticked at https://manage.slicehost.com/api, otherwise returns:: - <errors> - <error>You must enable slice deletes in the SliceManager</error> - <error>Permission denied</error> - </errors> - - @inherits: :class:`NodeDriver.destroy_node` - """ - uri = '/slices/%s/destroy.xml' % (node.id) - self.connection.request(uri, method='PUT') - return True - - def _to_nodes(self, object): - if object.tag == 'slice': - return [self._to_node(object)] - node_elements = object.findall('slice') - return [self._to_node(el) for el in node_elements] - - def _to_node(self, element): - attrs = ['name', 'image-id', 'progress', 'id', 'bw-out', 'bw-in', - 'flavor-id', 'status', 'ip-address', 'root-password'] - - node_attrs = {} - for attr in attrs: - node_attrs[attr] = element.findtext(attr) - - # slicehost does not determine between public and private, so we - # have to figure it out - public_ip = [] - private_ip = [] - - ip_address = element.findtext('ip-address') - if is_private_subnet(ip_address): - private_ip.append(ip_address) - else: - public_ip.append(ip_address) - - for addr in element.findall('addresses/address'): - ip = addr.text - try: - socket.inet_aton(ip) - except socket.error: - # not a valid ip - continue - if is_private_subnet(ip): - private_ip.append(ip) - else: - public_ip.append(ip) - - public_ip = list(set(public_ip)) - - try: - state = self.NODE_STATE_MAP[element.findtext('status')] - except: - state = NodeState.UNKNOWN - - # for consistency with other drivers, we put this in two places. - node_attrs['password'] = node_attrs['root-password'] - extra = {} - for k in list(node_attrs.keys()): - ek = k.replace("-", "_") - extra[ek] = node_attrs[k] - n = Node(id=element.findtext('id'), - name=element.findtext('name'), - state=state, - public_ips=public_ip, - private_ips=private_ip, - driver=self.connection.driver, - extra=extra) - return n - - def _to_sizes(self, object): - if object.tag == 'flavor': - return [self._to_size(object)] - elements = object.findall('flavor') - return [self._to_size(el) for el in elements] - - def _to_size(self, element): - s = NodeSize(id=int(element.findtext('id')), - name=str(element.findtext('name')), - ram=int(element.findtext('ram')), - disk=None, # XXX: needs hardcode - bandwidth=None, # XXX: needs hardcode - price=float(element.findtext('price')) / (100 * 24 * 30), - driver=self.connection.driver) - return s - - def _to_images(self, object): - if object.tag == 'image': - return [self._to_image(object)] - elements = object.findall('image') - return [self._to_image(el) for el in elements] - - def _to_image(self, element): - i = NodeImage(id=int(element.findtext('id')), - name=str(element.findtext('name')), - driver=self.connection.driver) - return i http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/compute/providers.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/providers.py b/libcloud/compute/providers.py index b9c6808..e78fe18 100644 --- a/libcloud/compute/providers.py +++ b/libcloud/compute/providers.py @@ -81,8 +81,6 @@ DRIVERS = { ('libcloud.compute.drivers.rackspace', 'RackspaceNodeDriver'), Provider.RACKSPACE_FIRST_GEN: ('libcloud.compute.drivers.rackspace', 'RackspaceFirstGenNodeDriver'), - Provider.SLICEHOST: - ('libcloud.compute.drivers.slicehost', 'SlicehostNodeDriver'), Provider.VPSNET: ('libcloud.compute.drivers.vpsnet', 'VPSNetNodeDriver'), Provider.LINODE: http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/compute/types.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py index c75da81..7dd7b74 100644 --- a/libcloud/compute/types.py +++ b/libcloud/compute/types.py @@ -45,7 +45,6 @@ class Provider(object): :cvar EC2_EU_WEST: Amazon AWS EU Ireland :cvar RACKSPACE: Rackspace next-gen OpenStack based Cloud Servers :cvar RACKSPACE_FIRST_GEN: Rackspace First Gen Cloud Servers - :cvar SLICEHOST: Slicehost.com :cvar GCE: Google Compute Engine :cvar GOGRID: GoGrid :cvar VPSNET: VPS.net @@ -77,7 +76,6 @@ class Provider(object): DUMMY = 'dummy' EC2 = 'ec2_us_east' RACKSPACE = 'rackspace' - SLICEHOST = 'slicehost' GCE = 'gce' GOGRID = 'gogrid' VPSNET = 'vpsnet' @@ -144,6 +142,9 @@ class Provider(object): RACKSPACE_NOVA_LON = 'rackspace_nova_lon' RACKSPACE_NOVA_ORD = 'rackspace_nova_ord' + # Removed + # SLICEHOST = 'slicehost' + DEPRECATED_RACKSPACE_PROVIDERS = [Provider.RACKSPACE_UK, Provider.RACKSPACE_NOVA_BETA, http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/flavors.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/flavors.xml b/libcloud/test/compute/fixtures/slicehost/flavors.xml deleted file mode 100644 index 552e524..0000000 --- a/libcloud/test/compute/fixtures/slicehost/flavors.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<flavors type="array"> - <flavor> - <id type="integer">1</id> - <name>256 slice</name> - <price type="integer">2000</price> - <ram type="integer">256</ram> - </flavor> - <flavor> - <id type="integer">2</id> - <name>512 slice</name> - <price type="integer">3800</price> - <ram type="integer">512</ram> - </flavor> - <flavor> - <id type="integer">3</id> - <name>1GB slice</name> - <price type="integer">7000</price> - <ram type="integer">1024</ram> - </flavor> - <flavor> - <id type="integer">4</id> - <name>2GB slice</name> - <price type="integer">13000</price> - <ram type="integer">2048</ram> - </flavor> - <flavor> - <id type="integer">5</id> - <name>4GB slice</name> - <price type="integer">25000</price> - <ram type="integer">4096</ram> - </flavor> - <flavor> - <id type="integer">6</id> - <name>8GB slice</name> - <price type="integer">45000</price> - <ram type="integer">8192</ram> - </flavor> - <flavor> - <id type="integer">7</id> - <name>15.5GB slice</name> - <price type="integer">80000</price> - <ram type="integer">15872</ram> - </flavor> -</flavors> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/images.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/images.xml b/libcloud/test/compute/fixtures/slicehost/images.xml deleted file mode 100644 index f87b4e7..0000000 --- a/libcloud/test/compute/fixtures/slicehost/images.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<images type="array"> - <image> - <name>CentOS 5.2</name> - <id type="integer">2</id> - </image> - <image> - <name>Gentoo 2008.0</name> - <id type="integer">3</id> - </image> - <image> - <name>Debian 5.0 (lenny)</name> - <id type="integer">4</id> - </image> - <image> - <name>Fedora 10 (Cambridge)</name> - <id type="integer">5</id> - </image> - <image> - <name>CentOS 5.3</name> - <id type="integer">7</id> - </image> - <image> - <name>Ubuntu 9.04 (jaunty)</name> - <id type="integer">8</id> - </image> - <image> - <name>Arch 2009.02</name> - <id type="integer">9</id> - </image> - <image> - <name>Ubuntu 8.04.2 LTS (hardy)</name> - <id type="integer">10</id> - </image> - <image> - <name>Ubuntu 8.10 (intrepid)</name> - <id type="integer">11</id> - </image> - <image> - <name>Red Hat EL 5.3</name> - <id type="integer">12</id> - </image> - <image> - <name>Fedora 11 (Leonidas)</name> - <id type="integer">13</id> - </image> -</images> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/slices_1_reboot.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/slices_1_reboot.xml b/libcloud/test/compute/fixtures/slicehost/slices_1_reboot.xml deleted file mode 100644 index 8dac90b..0000000 --- a/libcloud/test/compute/fixtures/slicehost/slices_1_reboot.xml +++ /dev/null @@ -1,15 +0,0 @@ -<slice> - <name>libcloud-test</name> - <image-id type="integer">10</image-id> - <addresses type="array"> - <address>174.143.212.229</address> - <address>10.176.164.199</address> - </addresses> - <progress type="integer">100</progress> - <id type="integer">70507</id> - <bw-out type="float">0.0</bw-out> - <bw-in type="float">0.0</bw-in> - <flavor-id type="integer">1</flavor-id> - <status>reboot</status> - <ip-address>174.143.212.229</ip-address> -</slice> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/slices_1_reboot_forbidden.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/slices_1_reboot_forbidden.xml b/libcloud/test/compute/fixtures/slicehost/slices_1_reboot_forbidden.xml deleted file mode 100644 index cb8c99b..0000000 --- a/libcloud/test/compute/fixtures/slicehost/slices_1_reboot_forbidden.xml +++ /dev/null @@ -1,3 +0,0 @@ -<errors> - <error>Permission denied</error> -</errors> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/slices_errors.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/slices_errors.xml b/libcloud/test/compute/fixtures/slicehost/slices_errors.xml deleted file mode 100644 index 6555aa1..0000000 --- a/libcloud/test/compute/fixtures/slicehost/slices_errors.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<errors> - <error>Slice parameters are not properly nested</error> -</errors> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/slices_get.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/slices_get.xml b/libcloud/test/compute/fixtures/slicehost/slices_get.xml deleted file mode 100644 index 5fb51bf..0000000 --- a/libcloud/test/compute/fixtures/slicehost/slices_get.xml +++ /dev/null @@ -1,17 +0,0 @@ -<slices type="array"> - <slice> - <name>libcloud-foo</name> - <image-id type="integer">10</image-id> - <addresses type="array"> - <address>174.143.212.229</address> - <address>10.176.164.199</address> - </addresses> - <progress type="integer">0</progress> - <id type="integer">1</id> - <bw-out type="float">0.0</bw-out> - <bw-in type="float">0.0</bw-in> - <flavor-id type="integer">1</flavor-id> - <status>build</status> - <ip-address>174.143.212.229</ip-address> - </slice> -</slices> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/fixtures/slicehost/slices_post.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/slicehost/slices_post.xml b/libcloud/test/compute/fixtures/slicehost/slices_post.xml deleted file mode 100644 index 2257f26..0000000 --- a/libcloud/test/compute/fixtures/slicehost/slices_post.xml +++ /dev/null @@ -1,16 +0,0 @@ -<slice> - <name>slicetest</name> - <image-id type="integer">11</image-id> - <addresses type="array"> - <address>10.176.168.15</address> - <address>67.23.20.114</address> - </addresses> - <root-password>fooadfa1231</root-password> - <progress type="integer">0</progress> - <id type="integer">71907</id> - <bw-out type="float">0.0</bw-out> - <bw-in type="float">0.0</bw-in> - <flavor-id type="integer">1</flavor-id> - <status>build</status> - <ip-address>10.176.168.15</ip-address> -</slice> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ebe04b9/libcloud/test/compute/test_slicehost.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_slicehost.py b/libcloud/test/compute/test_slicehost.py deleted file mode 100644 index 3b3bb3d..0000000 --- a/libcloud/test/compute/test_slicehost.py +++ /dev/null @@ -1,163 +0,0 @@ -# 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. -# The ASF 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. -import sys -import unittest -from libcloud.utils.py3 import httplib - -from xml.etree import ElementTree as ET - -from libcloud.compute.drivers.slicehost import SlicehostNodeDriver as Slicehost -from libcloud.compute.types import NodeState, InvalidCredsError -from libcloud.compute.base import Node, NodeImage, NodeSize - -from libcloud.test import MockHttp -from libcloud.test.compute import TestCaseMixin -from libcloud.test.file_fixtures import ComputeFileFixtures -from libcloud.test.secrets import SLICEHOST_PARAMS - - -class SlicehostTest(unittest.TestCase, TestCaseMixin): - - def setUp(self): - - Slicehost.connectionCls.conn_classes = (None, SlicehostMockHttp) - SlicehostMockHttp.type = None - self.driver = Slicehost(*SLICEHOST_PARAMS) - - def test_list_nodes(self): - ret = self.driver.list_nodes() - self.assertEqual(len(ret), 1) - node = ret[0] - self.assertTrue('174.143.212.229' in node.public_ips) - self.assertTrue('10.176.164.199' in node.private_ips) - self.assertEqual(node.state, NodeState.PENDING) - - SlicehostMockHttp.type = 'UNAUTHORIZED' - try: - ret = self.driver.list_nodes() - except InvalidCredsError: - e = sys.exc_info()[1] - self.assertEqual(e.value, 'HTTP Basic: Access denied.') - else: - self.fail('test should have thrown') - - def test_list_sizes(self): - ret = self.driver.list_sizes() - self.assertEqual(len(ret), 7) - size = ret[0] - self.assertEqual(size.name, '256 slice') - - def test_list_images(self): - ret = self.driver.list_images() - self.assertEqual(len(ret), 11) - image = ret[0] - self.assertEqual(image.name, 'CentOS 5.2') - self.assertEqual(image.id, '2') - - def test_reboot_node(self): - node = Node( - id=1, name=None, state=None, public_ips=None, private_ips=None, - driver=self.driver) - - ret = node.reboot() - self.assertTrue(ret is True) - - ret = self.driver.reboot_node(node) - self.assertTrue(ret is True) - - SlicehostMockHttp.type = 'FORBIDDEN' - try: - ret = self.driver.reboot_node(node) - except Exception: - e = sys.exc_info()[1] - self.assertEqual(e.args[0], 'Permission denied') - else: - self.fail('test should have thrown') - - def test_destroy_node(self): - node = Node( - id=1, name=None, state=None, public_ips=None, private_ips=None, - driver=self.driver) - - ret = node.destroy() - self.assertTrue(ret is True) - - ret = self.driver.destroy_node(node) - self.assertTrue(ret is True) - - def test_create_node(self): - image = NodeImage(id=11, name='ubuntu 8.10', driver=self.driver) - size = NodeSize( - 1, '256 slice', None, None, None, None, driver=self.driver) - node = self.driver.create_node( - name='slicetest', image=image, size=size) - self.assertEqual(node.name, 'slicetest') - self.assertEqual(node.extra.get('password'), 'fooadfa1231') - - -class SlicehostMockHttp(MockHttp): - - fixtures = ComputeFileFixtures('slicehost') - - def _slices_xml(self, method, url, body, headers): - if method == 'POST': - tree = ET.XML(body) - name = tree.findtext('name') - image_id = int(tree.findtext('image-id')) - flavor_id = int(tree.findtext('flavor-id')) - - # TODO: would be awesome to get the slicehost api developers to fill in the - # the correct validation logic - if not (name and image_id and flavor_id) \ - or tree.tag != 'slice' \ - or not 'Content-Type' in headers \ - or headers['Content-Type'] != 'application/xml': - - err_body = self.fixtures.load('slices_error.xml') - return (httplib.UNPROCESSABLE_ENTITY, err_body, {}, '') - - body = self.fixtures.load('slices_post.xml') - return (httplib.CREATED, body, {}, '') - else: - body = self.fixtures.load('slices_get.xml') - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - - def _slices_xml_UNAUTHORIZED(self, method, url, body, headers): - err_body = 'HTTP Basic: Access denied.' - return (httplib.UNAUTHORIZED, err_body, {}, - httplib.responses[httplib.UNAUTHORIZED]) - - def _flavors_xml(self, method, url, body, headers): - body = self.fixtures.load('flavors.xml') - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - - def _images_xml(self, method, url, body, headers): - body = self.fixtures.load('images.xml') - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - - def _slices_1_reboot_xml(self, method, url, body, headers): - body = self.fixtures.load('slices_1_reboot.xml') - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - - def _slices_1_reboot_xml_FORBIDDEN(self, method, url, body, headers): - body = self.fixtures.load('slices_1_reboot_forbidden.xml') - return (httplib.FORBIDDEN, body, {}, httplib.responses[httplib.FORBIDDEN]) - - def _slices_1_destroy_xml(self, method, url, body, headers): - body = '' - return (httplib.OK, body, {}, httplib.responses[httplib.OK]) - -if __name__ == '__main__': - sys.exit(unittest.main())
