http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/runabove.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/runabove.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/runabove.py deleted file mode 100644 index 72a45c6..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/runabove.py +++ /dev/null @@ -1,453 +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. -""" -RunAbove driver -""" -from libcloud.common.runabove import API_ROOT, RunAboveConnection -from libcloud.compute.base import NodeDriver, NodeSize, Node, NodeLocation -from libcloud.compute.base import NodeImage, StorageVolume -from libcloud.compute.types import Provider, StorageVolumeState -from libcloud.compute.drivers.openstack import OpenStackNodeDriver -from libcloud.compute.drivers.openstack import OpenStackKeyPair - - -class RunAboveNodeDriver(NodeDriver): - """ - Libcloud driver for the RunAbove API - - For more information on the RunAbove API, read the official reference: - - https://api.runabove.com/console/ - """ - type = Provider.RUNABOVE - name = "RunAbove" - website = 'https://www.runabove.com/' - connectionCls = RunAboveConnection - features = {'create_node': ['ssh_key']} - api_name = 'runabove' - - NODE_STATE_MAP = OpenStackNodeDriver.NODE_STATE_MAP - VOLUME_STATE_MAP = OpenStackNodeDriver.VOLUME_STATE_MAP - - def __init__(self, key, secret, ex_consumer_key=None): - """ - Instantiate the driver with the given API credentials. - - :param key: Your application key (required) - :type key: ``str`` - - :param secret: Your application secret (required) - :type secret: ``str`` - - :param ex_consumer_key: Your consumer key (required) - :type ex_consumer_key: ``str`` - - :rtype: ``None`` - """ - self.datacenter = None - self.consumer_key = ex_consumer_key - NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key) - - def list_nodes(self, location=None): - """ - List all nodes. - - :keyword location: Location (region) used as filter - :type location: :class:`NodeLocation` - - :return: List of node objects - :rtype: ``list`` of :class:`Node` - """ - action = API_ROOT + '/instance' - data = {} - if location: - data['region'] = location.id - response = self.connection.request(action, data=data) - return self._to_nodes(response.object) - - def ex_get_node(self, node_id): - """ - Get a individual node. - - :keyword node_id: Node's ID - :type node_id: ``str`` - - :return: Created node - :rtype : :class:`Node` - """ - action = API_ROOT + '/instance/' + node_id - response = self.connection.request(action, method='GET') - return self._to_node(response.object) - - def create_node(self, name, image, size, location, ex_keyname=None): - """ - Create a new node - - :keyword name: Name of created node - :type name: ``str`` - - :keyword image: Image used for node - :type image: :class:`NodeImage` - - :keyword size: Size (flavor) used for node - :type size: :class:`NodeSize` - - :keyword location: Location (region) where to create node - :type location: :class:`NodeLocation` - - :keyword ex_keyname: Name of SSH key used - :type ex_keyname: ``str`` - - :return: Created node - :rtype : :class:`Node` - """ - action = API_ROOT + '/instance' - data = { - 'name': name, - 'imageId': image.id, - 'flavorId': size.id, - 'region': location.id, - } - if ex_keyname: - data['sshKeyName'] = ex_keyname - response = self.connection.request(action, data=data, method='POST') - return self._to_node(response.object) - - def destroy_node(self, node): - action = API_ROOT + '/instance/' + node.id - self.connection.request(action, method='DELETE') - return True - - def list_sizes(self, location=None): - action = API_ROOT + '/flavor' - data = {} - if location: - data['region'] = location.id - response = self.connection.request(action, data=data) - return self._to_sizes(response.object) - - def ex_get_size(self, size_id): - """ - Get an individual size (flavor). - - :keyword size_id: Size's ID - :type size_id: ``str`` - - :return: Size - :rtype: :class:`NodeSize` - """ - action = API_ROOT + '/flavor/' + size_id - response = self.connection.request(action) - return self._to_size(response.object) - - def list_images(self, location=None, ex_size=None): - """ - List available images - - :keyword location: Location (region) used as filter - :type location: :class:`NodeLocation` - - :keyword ex_size: Exclude images which are uncompatible with given size - :type ex_size: :class:`NodeImage` - - :return: List of images - :rtype : ``list`` of :class:`NodeImage` - """ - action = API_ROOT + '/image' - data = {} - if location: - data['region'] = location.id - if ex_size: - data['flavorId'] = ex_size.id - response = self.connection.request(action, data=data) - return self._to_images(response.object) - - def get_image(self, image_id): - action = API_ROOT + '/image/' + image_id - response = self.connection.request(action) - return self._to_image(response.object) - - def list_locations(self): - action = API_ROOT + '/region' - data = self.connection.request(action) - return self._to_locations(data.object) - - def list_key_pairs(self, location=None): - """ - List available SSH public keys. - - :keyword location: Location (region) used as filter - :type location: :class:`NodeLocation` - - :return: Public keys - :rtype: ``list``of :class:`KeyPair` - """ - action = API_ROOT + '/ssh' - data = {} - if location: - data['region'] = location.id - response = self.connection.request(action, data=data) - return self._to_key_pairs(response.object) - - def get_key_pair(self, name, location): - """ - Get an individual SSH public key by its name and location. - - :keyword name: SSH key name - :type name: str - - :keyword location: Key's region - :type location: :class:`NodeLocation` - - :return: Public key - :rtype: :class:`KeyPair` - """ - action = API_ROOT + '/ssh/' + name - data = {'region': location.id} - response = self.connection.request(action, data=data) - return self._to_key_pair(response.object) - - def import_key_pair_from_string(self, name, key_material, location): - """ - Import a new public key from string. - - :param name: Key pair name. - :type name: ``str`` - - :param key_material: Public key material. - :type key_material: ``str`` - - :return: Imported key pair object. - :rtype: :class:`KeyPair` - """ - action = API_ROOT + '/ssh' - data = {'name': name, 'publicKey': key_material, 'region': location.id} - response = self.connection.request(action, data=data, method='POST') - return self._to_key_pair(response.object) - - def delete_key_pair(self, name, location): - """ - Delete an existing key pair. - - :param name: Key pair name. - :type name: ``str`` - - :keyword location: Key's region - :type location: :class:`NodeLocation` - - :return: True of False based on success of Keypair deletion - :rtype: ``bool`` - """ - action = API_ROOT + '/ssh/' + name - data = {'name': name, 'region': location.id} - self.connection.request(action, data=data, method='DELETE') - return True - - def create_volume(self, size, location, name=None, - ex_volume_type='classic', ex_description=None): - """ - Create a volume. - - :param size: Size of volume to create (in GB). - :type size: ``int`` - - :param name: Name of volume to create - :type name: ``str`` - - :keyword location: Location to create the volume in - :type location: :class:`NodeLocation` or ``None`` - - :keyword ex_volume_type: ``'classic'`` or ``'high-speed'`` - :type ex_volume_type: ``str`` - - :keyword ex_description: Optionnal description of volume - :type ex_description: str - - :return: Storage Volume object - :rtype: :class:`StorageVolume` - """ - action = API_ROOT + '/volume' - data = { - 'region': location.id, - 'size': str(size), - 'type': ex_volume_type, - } - if name: - data['name'] = name - if ex_description: - data['description'] = ex_description - response = self.connection.request(action, data=data, method='POST') - return self._to_volume(response.object) - - def destroy_volume(self, volume): - action = API_ROOT + '/volume/' + volume.id - self.connection.request(action, method='DELETE') - return True - - def list_volumes(self, location=None): - """ - Return a list of volumes. - - :keyword location: Location use for filter - :type location: :class:`NodeLocation` or ``None`` - - :return: A list of volume objects. - :rtype: ``list`` of :class:`StorageVolume` - """ - action = API_ROOT + '/volume' - data = {} - if location: - data['region'] = location.id - response = self.connection.request(action, data=data) - return self._to_volumes(response.object) - - def ex_get_volume(self, volume_id): - """ - Return a Volume object based on a volume ID. - - :param volume_id: The ID of the volume - :type volume_id: ``int`` - - :return: A StorageVolume object for the volume - :rtype: :class:`StorageVolume` - """ - action = API_ROOT + '/volume/' + volume_id - response = self.connection.request(action) - return self._to_volume(response.object) - - def attach_volume(self, node, volume, device=None): - """ - Attach a volume to a node. - - :param node: Node where to attach volume - :type node: :class:`Node` - - :param volume: The ID of the volume - :type volume: :class:`StorageVolume` - - :param device: Unsed parameter - - :return: True or False representing operation successful - :rtype: ``bool`` - """ - action = '%s/volume/%s/attach' % (API_ROOT, volume.id) - data = {'instanceId': node.id} - self.connection.request(action, data=data, method='POST') - return True - - def detach_volume(self, volume, ex_node=None): - """ - Detach a volume to a node. - - :param volume: The ID of the volume - :type volume: :class:`StorageVolume` - - :param ex_node: Node to detach from (optionnal if volume is attached - to only one node) - :type ex_node: :class:`Node` - - :return: True or False representing operation successful - :rtype: ``bool`` - - :raises: Exception: If ``ex_node`` is not provided and more than one - node is attached to the volume - """ - action = '%s/volume/%s/detach' % (API_ROOT, volume.id) - if ex_node is None: - if len(volume.extra['attachedTo']) != 1: - err_msg = "Volume '%s' has more or less than one attached \ - nodes, you must specify one." - raise Exception(err_msg) - ex_node = self.ex_get_node(volume.extra['attachedTo'][0]) - data = {'instanceId': ex_node.id} - self.connection.request(action, data=data, method='POST') - return True - - def _to_volume(self, obj): - extra = obj.copy() - extra.pop('id') - extra.pop('name') - extra.pop('size') - state = self.VOLUME_STATE_MAP.get(obj.pop('status', None), - StorageVolumeState.UNKNOWN) - return StorageVolume(id=obj['id'], name=obj['name'], size=obj['size'], - state=state, extra=extra, driver=self) - - def _to_volumes(self, objs): - return [self._to_volume(obj) for obj in objs] - - def _to_location(self, obj): - location = self.connection.LOCATIONS[obj] - return NodeLocation(driver=self, **location) - - def _to_locations(self, objs): - return [self._to_location(obj) for obj in objs] - - def _to_node(self, obj): - extra = obj.copy() - if 'flavorId' in extra: - public_ips = [obj.pop('ip')] - else: - ip = extra.pop('ipv4') - public_ips = [ip] if ip else [] - del extra['instanceId'] - del extra['name'] - return Node(id=obj['instanceId'], name=obj['name'], - state=self.NODE_STATE_MAP[obj['status']], - public_ips=public_ips, private_ips=[], driver=self, - extra=extra) - - def _to_nodes(self, objs): - return [self._to_node(obj) for obj in objs] - - def _to_size(self, obj): - extra = {'vcpus': obj['vcpus'], 'type': obj['type'], - 'region': obj['region']} - return NodeSize(id=obj['id'], name=obj['name'], ram=obj['ram'], - disk=obj['disk'], bandwidth=None, price=None, - driver=self, extra=extra) - - def _to_sizes(self, objs): - return [self._to_size(obj) for obj in objs] - - def _to_image(self, obj): - extra = {'region': obj['region'], 'visibility': obj['visibility'], - 'deprecated': obj['deprecated']} - return NodeImage(id=obj['id'], name=obj['name'], driver=self, - extra=extra) - - def _to_images(self, objs): - return [self._to_image(obj) for obj in objs] - - def _to_key_pair(self, obj): - extra = {'region': obj['region']} - return OpenStackKeyPair(name=obj['name'], public_key=obj['publicKey'], - driver=self, fingerprint=obj['fingerPrint'], - extra=extra) - - def _to_key_pairs(self, objs): - return [self._to_key_pair(obj) for obj in objs] - - def _ex_connection_class_kwargs(self): - return {'ex_consumer_key': self.consumer_key} - - def _add_required_headers(self, headers, method, action, data, timestamp): - timestamp = self.connection.get_timestamp() - signature = self.connection.make_signature(method, action, data, - str(timestamp)) - headers.update({ - 'X-Ra-Timestamp': timestamp, - 'X-Ra-Signature': signature - })
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/serverlove.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/serverlove.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/serverlove.py deleted file mode 100644 index 2ba92a9..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/serverlove.py +++ /dev/null @@ -1,83 +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. - -""" -ServerLove Driver -""" - -from libcloud.compute.types import Provider -from libcloud.compute.drivers.elasticstack import ElasticStackBaseNodeDriver -from libcloud.compute.drivers.elasticstack import ElasticStackBaseConnection - - -# API end-points -API_ENDPOINTS = { - 'uk-1': { - 'name': 'United Kingdom, Manchester', - 'country': 'United Kingdom', - 'host': 'api.z1-man.serverlove.com' - } -} - -# Default API end-point for the base connection class. -DEFAULT_ENDPOINT = 'uk-1' - -# Retrieved from http://www.serverlove.com/cloud-server-faqs/api-questions/ -STANDARD_DRIVES = { - '679f5f44-0be7-4745-a658-cccd4334c1aa': { - 'uuid': '679f5f44-0be7-4745-a658-cccd4334c1aa', - 'description': 'CentOS 5.5', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - '5f2e0e29-2937-42b9-b362-d2d07eddbdeb': { - 'uuid': '5f2e0e29-2937-42b9-b362-d2d07eddbdeb', - 'description': 'Ubuntu Linux 10.04', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - '5795b68f-ed26-4639-b41d-c93235062b6b': { - 'uuid': '5795b68f-ed26-4639-b41d-c93235062b6b', - 'description': 'Debian Linux 5', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - '41993a02-0b22-4e49-bb47-0aa8975217e4': { - 'uuid': '41993a02-0b22-4e49-bb47-0aa8975217e4', - 'description': 'Windows Server 2008 R2 Standard', - 'size_gunzipped': '15GB', - 'supports_deployment': False, - }, - '85623ca1-9c2a-4398-a771-9a43c347e86b': { - 'uuid': '85623ca1-9c2a-4398-a771-9a43c347e86b', - 'description': 'Windows Web Server 2008 R2', - 'size_gunzipped': '15GB', - 'supports_deployment': False, - } -} - - -class ServerLoveConnection(ElasticStackBaseConnection): - host = API_ENDPOINTS[DEFAULT_ENDPOINT]['host'] - - -class ServerLoveNodeDriver(ElasticStackBaseNodeDriver): - type = Provider.SERVERLOVE - api_name = 'serverlove' - website = 'http://www.serverlove.com/' - name = 'ServerLove' - connectionCls = ServerLoveConnection - features = {'create_node': ['generates_password']} - _standard_drives = STANDARD_DRIVES http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/skalicloud.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/skalicloud.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/skalicloud.py deleted file mode 100644 index c0b0d79..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/skalicloud.py +++ /dev/null @@ -1,83 +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. - -""" -skalicloud Driver -""" - -from libcloud.compute.types import Provider -from libcloud.compute.drivers.elasticstack import ElasticStackBaseNodeDriver -from libcloud.compute.drivers.elasticstack import ElasticStackBaseConnection - - -# API end-points -API_ENDPOINTS = { - 'my-1': { - 'name': 'Malaysia, Kuala Lumpur', - 'country': 'Malaysia', - 'host': 'api.sdg-my.skalicloud.com' - } -} - -# Default API end-point for the base connection class. -DEFAULT_ENDPOINT = 'my-1' - -# Retrieved from http://www.skalicloud.com/cloud-api/ -STANDARD_DRIVES = { - '90aa51f2-15c0-4cff-81ee-e93aa20b9468': { - 'uuid': '90aa51f2-15c0-4cff-81ee-e93aa20b9468', - 'description': 'CentOS 5.5 -64bit', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - 'c144d7a7-e24b-48ab-954b-6b6ec514ed6f': { - 'uuid': 'c144d7a7-e24b-48ab-954b-6b6ec514ed6f', - 'description': 'Debian 5 -64bit', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - '3051699a-a536-4220-aeb5-67f2ec101a09': { - 'uuid': '3051699a-a536-4220-aeb5-67f2ec101a09', - 'description': 'Ubuntu Server 10.10 -64bit', - 'size_gunzipped': '1GB', - 'supports_deployment': True, - }, - '11c4c922-5ff8-4094-b06c-eb8ffaec1ea9': { - 'uuid': '11c4c922-5ff8-4094-b06c-eb8ffaec1ea9', - 'description': 'Windows 2008R2 Web Edition', - 'size_gunzipped': '13GB', - 'supports_deployment': False, - }, - '93bf390e-4f46-4252-a8bc-9d6d80e3f955': { - 'uuid': '93bf390e-4f46-4252-a8bc-9d6d80e3f955', - 'description': 'Windows Server 2008R2 Standard', - 'size_gunzipped': '13GB', - 'supports_deployment': False, - } -} - - -class SkaliCloudConnection(ElasticStackBaseConnection): - host = API_ENDPOINTS[DEFAULT_ENDPOINT]['host'] - - -class SkaliCloudNodeDriver(ElasticStackBaseNodeDriver): - type = Provider.SKALICLOUD - api_name = 'skalicloud' - name = 'skalicloud' - website = 'http://www.skalicloud.com/' - connectionCls = SkaliCloudConnection - features = {"create_node": ["generates_password"]} - _standard_drives = STANDARD_DRIVES http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/softlayer.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/softlayer.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/softlayer.py deleted file mode 100644 index 5243d0b..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/softlayer.py +++ /dev/null @@ -1,505 +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. -""" -Softlayer driver -""" - -import time -try: - from Crypto.PublicKey import RSA - crypto = True -except ImportError: - crypto = False - -from libcloud.common.softlayer import SoftLayerConnection, SoftLayerException -from libcloud.compute.types import Provider, NodeState -from libcloud.compute.base import NodeDriver, Node, NodeLocation, NodeSize, \ - NodeImage, KeyPair -from libcloud.compute.types import KeyPairDoesNotExistError - -DEFAULT_DOMAIN = 'example.com' -DEFAULT_CPU_SIZE = 1 -DEFAULT_RAM_SIZE = 2048 -DEFAULT_DISK_SIZE = 100 - -DATACENTERS = { - 'hou02': {'country': 'US'}, - 'sea01': {'country': 'US', 'name': 'Seattle - West Coast U.S.'}, - 'wdc01': {'country': 'US', 'name': 'Washington, DC - East Coast U.S.'}, - 'dal01': {'country': 'US'}, - 'dal02': {'country': 'US'}, - 'dal04': {'country': 'US'}, - 'dal05': {'country': 'US', 'name': 'Dallas - Central U.S.'}, - 'dal06': {'country': 'US'}, - 'dal07': {'country': 'US'}, - 'sjc01': {'country': 'US', 'name': 'San Jose - West Coast U.S.'}, - 'sng01': {'country': 'SG', 'name': 'Singapore - Southeast Asia'}, - 'ams01': {'country': 'NL', 'name': 'Amsterdam - Western Europe'}, - 'tok02': {'country': 'JP', 'name': 'Tokyo - Japan'}, -} - -NODE_STATE_MAP = { - 'RUNNING': NodeState.RUNNING, - 'HALTED': NodeState.UNKNOWN, - 'PAUSED': NodeState.UNKNOWN, - 'INITIATING': NodeState.PENDING -} - -SL_BASE_TEMPLATES = [ - { - 'name': '1 CPU, 1GB ram, 25GB', - 'ram': 1024, - 'disk': 25, - 'cpus': 1, - }, { - 'name': '1 CPU, 1GB ram, 100GB', - 'ram': 1024, - 'disk': 100, - 'cpus': 1, - }, { - 'name': '1 CPU, 2GB ram, 100GB', - 'ram': 2 * 1024, - 'disk': 100, - 'cpus': 1, - }, { - 'name': '1 CPU, 4GB ram, 100GB', - 'ram': 4 * 1024, - 'disk': 100, - 'cpus': 1, - }, { - 'name': '2 CPU, 2GB ram, 100GB', - 'ram': 2 * 1024, - 'disk': 100, - 'cpus': 2, - }, { - 'name': '2 CPU, 4GB ram, 100GB', - 'ram': 4 * 1024, - 'disk': 100, - 'cpus': 2, - }, { - 'name': '2 CPU, 8GB ram, 100GB', - 'ram': 8 * 1024, - 'disk': 100, - 'cpus': 2, - }, { - 'name': '4 CPU, 4GB ram, 100GB', - 'ram': 4 * 1024, - 'disk': 100, - 'cpus': 4, - }, { - 'name': '4 CPU, 8GB ram, 100GB', - 'ram': 8 * 1024, - 'disk': 100, - 'cpus': 4, - }, { - 'name': '6 CPU, 4GB ram, 100GB', - 'ram': 4 * 1024, - 'disk': 100, - 'cpus': 6, - }, { - 'name': '6 CPU, 8GB ram, 100GB', - 'ram': 8 * 1024, - 'disk': 100, - 'cpus': 6, - }, { - 'name': '8 CPU, 8GB ram, 100GB', - 'ram': 8 * 1024, - 'disk': 100, - 'cpus': 8, - }, { - 'name': '8 CPU, 16GB ram, 100GB', - 'ram': 16 * 1024, - 'disk': 100, - 'cpus': 8, - }] - -SL_TEMPLATES = {} -for i, template in enumerate(SL_BASE_TEMPLATES): - # Add local disk templates - local = template.copy() - local['local_disk'] = True - SL_TEMPLATES[i] = local - - -class SoftLayerNodeDriver(NodeDriver): - """ - SoftLayer node driver - - Extra node attributes: - - password: root password - - hourlyRecurringFee: hourly price (if applicable) - - recurringFee : flat rate (if applicable) - - recurringMonths : The number of months in which the recurringFee - will be incurred. - """ - connectionCls = SoftLayerConnection - name = 'SoftLayer' - website = 'http://www.softlayer.com/' - type = Provider.SOFTLAYER - - features = {'create_node': ['generates_password', 'ssh_key']} - api_name = 'softlayer' - - def _to_node(self, host): - try: - password = \ - host['operatingSystem']['passwords'][0]['password'] - except (IndexError, KeyError): - password = None - - hourlyRecurringFee = host.get('billingItem', {}).get( - 'hourlyRecurringFee', 0) - recurringFee = host.get('billingItem', {}).get('recurringFee', 0) - recurringMonths = host.get('billingItem', {}).get('recurringMonths', 0) - createDate = host.get('createDate', None) - - # When machine is launching it gets state halted - # we change this to pending - state = NODE_STATE_MAP.get(host['powerState']['keyName'], - NodeState.UNKNOWN) - - if not password and state == NodeState.UNKNOWN: - state = NODE_STATE_MAP['INITIATING'] - - public_ips = [] - private_ips = [] - - if 'primaryIpAddress' in host: - public_ips.append(host['primaryIpAddress']) - - if 'primaryBackendIpAddress' in host: - private_ips.append(host['primaryBackendIpAddress']) - - image = host.get('operatingSystem', {}).get('softwareLicense', {}) \ - .get('softwareDescription', {}) \ - .get('longDescription', None) - - return Node( - id=host['id'], - name=host['fullyQualifiedDomainName'], - state=state, - public_ips=public_ips, - private_ips=private_ips, - driver=self, - extra={ - 'hostname': host['hostname'], - 'fullyQualifiedDomainName': host['fullyQualifiedDomainName'], - 'password': password, - 'maxCpu': host.get('maxCpu', None), - 'datacenter': host.get('datacenter', {}).get('longName', None), - 'maxMemory': host.get('maxMemory', None), - 'image': image, - 'hourlyRecurringFee': hourlyRecurringFee, - 'recurringFee': recurringFee, - 'recurringMonths': recurringMonths, - 'created': createDate, - } - ) - - def destroy_node(self, node): - self.connection.request( - 'SoftLayer_Virtual_Guest', 'deleteObject', id=node.id - ) - return True - - def reboot_node(self, node): - self.connection.request( - 'SoftLayer_Virtual_Guest', 'rebootSoft', id=node.id - ) - return True - - def ex_stop_node(self, node): - self.connection.request( - 'SoftLayer_Virtual_Guest', 'powerOff', id=node.id - ) - return True - - def ex_start_node(self, node): - self.connection.request( - 'SoftLayer_Virtual_Guest', 'powerOn', id=node.id - ) - return True - - def _get_order_information(self, node_id, timeout=1200, check_interval=5): - mask = { - 'billingItem': '', - 'powerState': '', - 'operatingSystem': {'passwords': ''}, - 'provisionDate': '', - } - - for i in range(0, timeout, check_interval): - res = self.connection.request( - 'SoftLayer_Virtual_Guest', - 'getObject', - id=node_id, - object_mask=mask - ).object - - if res.get('provisionDate', None): - return res - - time.sleep(check_interval) - - raise SoftLayerException('Timeout on getting node details') - - def create_node(self, **kwargs): - """Create a new SoftLayer node - - @inherits: :class:`NodeDriver.create_node` - - :keyword ex_domain: e.g. libcloud.org - :type ex_domain: ``str`` - :keyword ex_cpus: e.g. 2 - :type ex_cpus: ``int`` - :keyword ex_disk: e.g. 100 - :type ex_disk: ``int`` - :keyword ex_ram: e.g. 2048 - :type ex_ram: ``int`` - :keyword ex_bandwidth: e.g. 100 - :type ex_bandwidth: ``int`` - :keyword ex_local_disk: e.g. True - :type ex_local_disk: ``bool`` - :keyword ex_datacenter: e.g. Dal05 - :type ex_datacenter: ``str`` - :keyword ex_os: e.g. UBUNTU_LATEST - :type ex_os: ``str`` - :keyword ex_keyname: The name of the key pair - :type ex_keyname: ``str`` - """ - name = kwargs['name'] - os = 'DEBIAN_LATEST' - if 'ex_os' in kwargs: - os = kwargs['ex_os'] - elif 'image' in kwargs: - os = kwargs['image'].id - - size = kwargs.get('size', NodeSize(id=123, name='Custom', ram=None, - disk=None, bandwidth=None, - price=None, - driver=self.connection.driver)) - ex_size_data = SL_TEMPLATES.get(int(size.id)) or {} - # plan keys are ints - cpu_count = kwargs.get('ex_cpus') or ex_size_data.get('cpus') or \ - DEFAULT_CPU_SIZE - ram = kwargs.get('ex_ram') or ex_size_data.get('ram') or \ - DEFAULT_RAM_SIZE - bandwidth = kwargs.get('ex_bandwidth') or size.bandwidth or 10 - hourly = 'true' if kwargs.get('ex_hourly', True) else 'false' - - local_disk = 'true' - if ex_size_data.get('local_disk') is False: - local_disk = 'false' - - if kwargs.get('ex_local_disk') is False: - local_disk = 'false' - - disk_size = DEFAULT_DISK_SIZE - if size.disk: - disk_size = size.disk - if kwargs.get('ex_disk'): - disk_size = kwargs.get('ex_disk') - - datacenter = '' - if 'ex_datacenter' in kwargs: - datacenter = kwargs['ex_datacenter'] - elif 'location' in kwargs: - datacenter = kwargs['location'].id - - domain = kwargs.get('ex_domain') - if domain is None: - if name.find('.') != -1: - domain = name[name.find('.') + 1:] - if domain is None: - # TODO: domain is a required argument for the Sofylayer API, but it - # it shouldn't be. - domain = DEFAULT_DOMAIN - - newCCI = { - 'hostname': name, - 'domain': domain, - 'startCpus': cpu_count, - 'maxMemory': ram, - 'networkComponents': [{'maxSpeed': bandwidth}], - 'hourlyBillingFlag': hourly, - 'operatingSystemReferenceCode': os, - 'localDiskFlag': local_disk, - 'blockDevices': [ - { - 'device': '0', - 'diskImage': { - 'capacity': disk_size, - } - } - ] - - } - - if datacenter: - newCCI['datacenter'] = {'name': datacenter} - - if 'ex_keyname' in kwargs: - newCCI['sshKeys'] = [ - { - 'id': self._key_name_to_id(kwargs['ex_keyname']) - } - ] - - res = self.connection.request( - 'SoftLayer_Virtual_Guest', 'createObject', newCCI - ).object - - node_id = res['id'] - raw_node = self._get_order_information(node_id) - - return self._to_node(raw_node) - - def list_key_pairs(self): - result = self.connection.request( - 'SoftLayer_Account', 'getSshKeys' - ).object - elems = [x for x in result] - key_pairs = self._to_key_pairs(elems=elems) - return key_pairs - - def get_key_pair(self, name): - key_id = self._key_name_to_id(name=name) - result = self.connection.request( - 'SoftLayer_Security_Ssh_Key', 'getObject', id=key_id - ).object - return self._to_key_pair(result) - - # TODO: Check this with the libcloud guys, - # can we create new dependencies? - def create_key_pair(self, name, ex_size=4096): - if crypto is False: - raise NotImplementedError('create_key_pair needs' - 'the pycrypto library') - key = RSA.generate(ex_size) - new_key = { - 'key': key.publickey().exportKey('OpenSSH'), - 'label': name, - 'notes': '', - } - result = self.connection.request( - 'SoftLayer_Security_Ssh_Key', 'createObject', new_key - ).object - result['private'] = key.exportKey('PEM') - return self._to_key_pair(result) - - def import_key_pair_from_string(self, name, key_material): - new_key = { - 'key': key_material, - 'label': name, - 'notes': '', - } - result = self.connection.request( - 'SoftLayer_Security_Ssh_Key', 'createObject', new_key - ).object - - key_pair = self._to_key_pair(result) - return key_pair - - def delete_key_pair(self, key_pair): - key = self._key_name_to_id(key_pair) - result = self.connection.request( - 'SoftLayer_Security_Ssh_Key', 'deleteObject', id=key - ).object - return result - - def _to_image(self, img): - return NodeImage( - id=img['template']['operatingSystemReferenceCode'], - name=img['itemPrice']['item']['description'], - driver=self.connection.driver - ) - - def list_images(self, location=None): - result = self.connection.request( - 'SoftLayer_Virtual_Guest', 'getCreateObjectOptions' - ).object - return [self._to_image(i) for i in result['operatingSystems']] - - def _to_size(self, id, size): - return NodeSize( - id=id, - name=size['name'], - ram=size['ram'], - disk=size['disk'], - bandwidth=size.get('bandwidth'), - price=self._get_size_price(str(id)), - driver=self.connection.driver, - ) - - def list_sizes(self, location=None): - return [self._to_size(id, s) for id, s in SL_TEMPLATES.items()] - - def _to_loc(self, loc): - country = 'UNKNOWN' - loc_id = loc['template']['datacenter']['name'] - name = loc_id - - if loc_id in DATACENTERS: - country = DATACENTERS[loc_id]['country'] - name = DATACENTERS[loc_id].get('name', loc_id) - return NodeLocation(id=loc_id, name=name, - country=country, driver=self) - - def list_locations(self): - res = self.connection.request( - 'SoftLayer_Virtual_Guest', 'getCreateObjectOptions' - ).object - return [self._to_loc(l) for l in res['datacenters']] - - def list_nodes(self): - mask = { - 'virtualGuests': { - 'powerState': '', - 'hostname': '', - 'maxMemory': '', - 'datacenter': '', - 'operatingSystem': {'passwords': ''}, - 'billingItem': '', - }, - } - res = self.connection.request( - 'SoftLayer_Account', - 'getVirtualGuests', - object_mask=mask - ).object - return [self._to_node(h) for h in res] - - def _to_key_pairs(self, elems): - key_pairs = [self._to_key_pair(elem=elem) for elem in elems] - return key_pairs - - def _to_key_pair(self, elem): - key_pair = KeyPair(name=elem['label'], - public_key=elem['key'], - fingerprint=elem['fingerprint'], - private_key=elem.get('private', None), - driver=self, - extra={'id': elem['id']}) - return key_pair - - def _key_name_to_id(self, name): - result = self.connection.request( - 'SoftLayer_Account', 'getSshKeys' - ).object - key_id = [x for x in result if x['label'] == name] - if len(key_id) == 0: - raise KeyPairDoesNotExistError(name, self) - else: - return int(key_id[0]['id']) http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/vcl.py ---------------------------------------------------------------------- diff --git a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/vcl.py b/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/vcl.py deleted file mode 100644 index a5ec464..0000000 --- a/apache-libcloud-1.0.0rc2/libcloud/compute/drivers/vcl.py +++ /dev/null @@ -1,302 +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. -""" -VCL driver -""" - -import time - -from libcloud.common.base import ConnectionUserAndKey -from libcloud.common.xmlrpc import XMLRPCResponse, XMLRPCConnection -from libcloud.common.types import InvalidCredsError, LibcloudError -from libcloud.compute.types import Provider, NodeState -from libcloud.compute.base import NodeDriver, Node -from libcloud.compute.base import NodeSize, NodeImage - - -class VCLResponse(XMLRPCResponse): - exceptions = { - 'VCL_Account': InvalidCredsError, - } - - -class VCLConnection(XMLRPCConnection, ConnectionUserAndKey): - endpoint = '/index.php?mode=xmlrpccall' - - def add_default_headers(self, headers): - headers['X-APIVERSION'] = '2' - headers['X-User'] = self.user_id - headers['X-Pass'] = self.key - return headers - - -class VCLNodeDriver(NodeDriver): - """ - VCL node driver - - :keyword host: The VCL host to which you make requests(required) - :type host: ``str`` - """ - - NODE_STATE_MAP = { - 'ready': NodeState.RUNNING, - 'failed': NodeState.TERMINATED, - 'timedout': NodeState.TERMINATED, - 'loading': NodeState.PENDING, - 'time': NodeState.PENDING, - 'future': NodeState.PENDING, - 'error': NodeState.UNKNOWN, - 'notready': NodeState.PENDING, - 'notavailable': NodeState.TERMINATED, - 'success': NodeState.PENDING - } - - connectionCls = VCLConnection - name = 'VCL' - website = 'http://incubator.apache.org/vcl/' - type = Provider.VCL - - def __init__(self, key, secret, secure=True, host=None, port=None, *args, - **kwargs): - """ - :param key: API key or username to used (required) - :type key: ``str`` - - :param secret: Secret password to be used (required) - :type secret: ``str`` - - :param secure: Weither to use HTTPS or HTTP. - :type secure: ``bool`` - - :param host: Override hostname used for connections. (required) - :type host: ``str`` - - :param port: Override port used for connections. - :type port: ``int`` - - :rtype: ``None`` - """ - if not host: - raise Exception('When instantiating VCL driver directly ' + - 'you also need to provide host') - - super(VCLNodeDriver, self).__init__(key, secret, secure=True, - host=None, port=None, *args, - **kwargs) - - def _vcl_request(self, method, *args): - res = self.connection.request( - method, - *args - ).object - if(res['status'] == 'error'): - raise LibcloudError(res['errormsg'], driver=self) - return res - - def create_node(self, **kwargs): - """Create a new VCL reservation - size and name ignored, image is the id from list_image - - @inherits: :class:`NodeDriver.create_node` - - :keyword image: image is the id from list_image - :type image: ``str`` - - :keyword start: start time as unix timestamp - :type start: ``str`` - - :keyword length: length of time in minutes - :type length: ``str`` - """ - - image = kwargs["image"] - start = kwargs.get('start', int(time.time())) - length = kwargs.get('length', '60') - - res = self._vcl_request( - "XMLRPCaddRequest", - image.id, - start, - length - ) - - return Node( - id=res['requestid'], - name=image.name, - state=self.NODE_STATE_MAP[res['status']], - public_ips=[], - private_ips=[], - driver=self, - image=image.name - ) - - def destroy_node(self, node): - """ - End VCL reservation for the node passed in. - Throws error if request fails. - - :param node: The node to be destroyed - :type node: :class:`Node` - - :rtype: ``bool`` - """ - try: - self._vcl_request( - 'XMLRPCendRequest', - node.id - ) - except LibcloudError: - return False - return True - - def _to_image(self, img): - return NodeImage( - id=img['id'], - name=img['name'], - driver=self.connection.driver - ) - - def list_images(self, location=None): - """ - List images available to the user provided credentials - - @inherits: :class:`NodeDriver.list_images` - """ - res = self.connection.request( - "XMLRPCgetImages" - ).object - return [self._to_image(i) for i in res] - - def list_sizes(self, location=None): - """ - VCL does not choosing sizes for node creation. - Size of images are statically set by administrators. - - @inherits: :class:`NodeDriver.list_sizes` - """ - return [NodeSize( - 't1.micro', - 'none', - '512', - 0, 0, 0, self) - ] - - def _to_connect_data(self, request_id, ipaddr): - res = self._vcl_request( - "XMLRPCgetRequestConnectData", - request_id, - ipaddr - ) - return res - - def _to_status(self, requestid, imagename, ipaddr): - res = self._vcl_request( - "XMLRPCgetRequestStatus", - requestid - ) - - public_ips = [] - extra = [] - if(res['status'] == 'ready'): - cdata = self._to_connect_data(requestid, ipaddr) - public_ips = [cdata['serverIP']] - extra = { - 'user': cdata['user'], - 'pass': cdata['password'] - } - return Node( - id=requestid, - name=imagename, - state=self.NODE_STATE_MAP[res['status']], - public_ips=public_ips, - private_ips=[], - driver=self, - image=imagename, - extra=extra - ) - - def _to_nodes(self, res, ipaddr): - return [self._to_status( - h['requestid'], - h['imagename'], - ipaddr - ) for h in res] - - def list_nodes(self, ipaddr): - """ - List nodes - - :param ipaddr: IP address which should be used - :type ipaddr: ``str`` - - :rtype: ``list`` of :class:`Node` - """ - res = self._vcl_request( - "XMLRPCgetRequestIds" - ) - return self._to_nodes(res['requests'], ipaddr) - - def ex_update_node_access(self, node, ipaddr): - """ - Update the remote ip accessing the node. - - :param node: the reservation node to update - :type node: :class:`Node` - - :param ipaddr: the ipaddr used to access the node - :type ipaddr: ``str`` - - :return: node with updated information - :rtype: :class:`Node` - """ - return self._to_status(node.id, node.image, ipaddr) - - def ex_extend_request_time(self, node, minutes): - """ - Time in minutes to extend the requested node's reservation time - - :param node: the reservation node to update - :type node: :class:`Node` - - :param minutes: the number of mintes to update - :type minutes: ``str`` - - :return: true on success, throws error on failure - :rtype: ``bool`` - """ - return self._vcl_request( - "XMLRPCextendRequest", - node.id, - minutes - ) - - def ex_get_request_end_time(self, node): - """ - Get the ending time of the node reservation. - - :param node: the reservation node to update - :type node: :class:`Node` - - :return: unix timestamp - :rtype: ``int`` - """ - res = self._vcl_request( - "XMLRPCgetRequestIds" - ) - time = 0 - for i in res['requests']: - if i['requestid'] == node.id: - time = i['end'] - return time