Repository: libcloud Updated Branches: refs/heads/trunk c452e7dbc -> a91147f2b
Add new native driver for HP Public cloud (Helion). Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a91147f2 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a91147f2 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a91147f2 Branch: refs/heads/trunk Commit: a91147f2b5d820bf2e4c2717b8fb4352d1491502 Parents: c452e7d Author: Tomaz Muraus <[email protected]> Authored: Wed May 14 12:24:42 2014 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Wed May 14 12:39:35 2014 +0200 ---------------------------------------------------------------------- CHANGES.rst | 4 + .../images/misc/hp_cloud_console_projects.jpg | Bin 0 -> 70787 bytes docs/_static/images/provider_logos/hpcloud.png | Bin 0 -> 13309 bytes docs/compute/drivers/hpcloud.rst | 44 +++++++++ .../compute/openstack/hpcloud_native.py | 13 +++ libcloud/compute/drivers/hpcloud.py | 99 +++++++++++++++++++ libcloud/compute/providers.py | 2 + libcloud/compute/types.py | 3 + 8 files changed, 165 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index 6eb473c..ca519ad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -134,6 +134,10 @@ Compute (GITHUB-285) [Benoit Canet] +- Add new driver for HP Public Cloud (Helion) available via Provider.HPCLOUD + constant. + [Tomaz Muraus] + Load Balancer ~~~~~~~~~~~~~ http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/docs/_static/images/misc/hp_cloud_console_projects.jpg ---------------------------------------------------------------------- diff --git a/docs/_static/images/misc/hp_cloud_console_projects.jpg b/docs/_static/images/misc/hp_cloud_console_projects.jpg new file mode 100644 index 0000000..70d0a4a Binary files /dev/null and b/docs/_static/images/misc/hp_cloud_console_projects.jpg differ http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/docs/_static/images/provider_logos/hpcloud.png ---------------------------------------------------------------------- diff --git a/docs/_static/images/provider_logos/hpcloud.png b/docs/_static/images/provider_logos/hpcloud.png new file mode 100644 index 0000000..f4e0ecb Binary files /dev/null and b/docs/_static/images/provider_logos/hpcloud.png differ http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/docs/compute/drivers/hpcloud.rst ---------------------------------------------------------------------- diff --git a/docs/compute/drivers/hpcloud.rst b/docs/compute/drivers/hpcloud.rst new file mode 100644 index 0000000..26450f3 --- /dev/null +++ b/docs/compute/drivers/hpcloud.rst @@ -0,0 +1,44 @@ +HP Cloud Computer Driver Documentation +====================================== + +`HP Cloud`_ is a public cloud computing service offered by HP. + +.. figure:: /_static/images/provider_logos/hpcloud.png + :align: center + :width: 300 + :target: https://www.hpcloud.com + +HP Cloud driver is based on the OpenStack one. For more information +information and OpenStack specific documentation, please refer to +:doc:`OpenStack Compute Driver Documentation <openstack>` page. + +Examples +-------- + +1. Instantiating the driver +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Unlike other OpenStack based providers, HP cloud also requires you to specify +tenant name when connecting to their cloud. You can do that by passing +``tenant_name`` argument to the driver constructor as shown in the code example +bellow. + +This attribute represents a project name and can be obtained in the `HP Cloud +console`_ as shown in the picture bellow. + +.. figure:: /_static/images/misc/hp_cloud_console_projects.jpg + :align: center + :width: 800 + +.. literalinclude:: /examples/compute/openstack/hpcloud_native.py + :language: python + +API Docs +-------- + +.. autoclass:: libcloud.compute.drivers.hpcloud.HPCloudNodeDriver + :members: + :inherited-members: + +.. _`HP Cloud`: https://www.hpcloud.com +.. _`HP Cloud console`: https://horizon.hpcloud.com http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/docs/examples/compute/openstack/hpcloud_native.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/openstack/hpcloud_native.py b/docs/examples/compute/openstack/hpcloud_native.py new file mode 100644 index 0000000..592d189 --- /dev/null +++ b/docs/examples/compute/openstack/hpcloud_native.py @@ -0,0 +1,13 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + + +USERNAME = 'your account username' +PASSWORD = 'your account password' +TENANT_NAME = 'project name' +REGION = 'region-b.geo-1' + +cls = get_driver(Provider.HPCLOUD) +driver = cls(USERNAME, PASSWORD, tenant_name=TENANT_NAME, + region=REGION) +print(driver.list_nodes()) http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/libcloud/compute/drivers/hpcloud.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/hpcloud.py b/libcloud/compute/drivers/hpcloud.py new file mode 100644 index 0000000..97de03e --- /dev/null +++ b/libcloud/compute/drivers/hpcloud.py @@ -0,0 +1,99 @@ +# 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. + +""" +HP Public cloud driver which is esentially just a small wrapper around +OpenStack driver. +""" + +from libcloud.compute.types import Provider, LibcloudError +from libcloud.compute.drivers.openstack import OpenStack_1_1_Connection +from libcloud.compute.drivers.openstack import OpenStack_1_1_NodeDriver + + +__all__ = [ + 'HPCloudNodeDriver' +] + +ENDPOINT_ARGS_MAP = { + 'region-a.geo-1': { + 'service_type': 'compute', + 'name': 'Compute', + 'region': 'region-a.geo-1' + }, + 'region-b.geo-1': { + 'service_type': 'compute', + 'name': 'Compute', + 'region': 'region-b.geo-1' + }, +} + +AUTH_URL_TEMPLATE = 'https://%s.identity.hpcloudsvc.com:35357/v2.0/tokens' + + +class HPCloudConnection(OpenStack_1_1_Connection): + _auth_version = '2.0_password' + + def __init__(self, *args, **kwargs): + self.region = kwargs.pop('region', None) + self.get_endpoint_args = kwargs.pop('get_endpoint_args', None) + super(HPCloudConnection, self).__init__(*args, **kwargs) + + def get_endpoint(self): + if not self.get_endpoint_args: + raise LibcloudError( + 'HPCloudConnection must have get_endpoint_args set') + + if '2.0_password' in self._auth_version: + ep = self.service_catalog.get_endpoint(**self.get_endpoint_args) + else: + raise LibcloudError( + 'Auth version "%s" not supported' % (self._auth_version)) + + public_url = ep.get('publicURL', None) + + if not public_url: + raise LibcloudError('Could not find specified endpoint') + + return public_url + + +class HPCloudNodeDriver(OpenStack_1_1_NodeDriver): + name = 'HP Public Cloud (Helion)' + website = 'http://www.hpcloud.com/' + connectionCls = HPCloudConnection + type = Provider.HPCLOUD + + def __init__(self, key, secret, tenant_name, secure=True, + host=None, port=None, region='region-b.geo-1', **kwargs): + """ + Note: tenant_name argument is required for HP cloud. + """ + self.tenant_name = tenant_name + super(HPCloudNodeDriver, self).__init__(key=key, secret=secret, + secure=secure, host=host, + port=port, + region=region, + **kwargs) + + def _ex_connection_class_kwargs(self): + endpoint_args = ENDPOINT_ARGS_MAP[self.region] + + kwargs = self.openstack_connection_kwargs() + kwargs['region'] = self.region + kwargs['get_endpoint_args'] = endpoint_args + kwargs['ex_force_auth_url'] = AUTH_URL_TEMPLATE % (self.region) + kwargs['ex_tenant_name'] = self.tenant_name + + return kwargs http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/libcloud/compute/providers.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/providers.py b/libcloud/compute/providers.py index 87a46b7..2fc280b 100644 --- a/libcloud/compute/providers.py +++ b/libcloud/compute/providers.py @@ -79,6 +79,8 @@ DRIVERS = { ('libcloud.compute.drivers.rackspace', 'RackspaceNodeDriver'), Provider.RACKSPACE_FIRST_GEN: ('libcloud.compute.drivers.rackspace', 'RackspaceFirstGenNodeDriver'), + Provider.HPCLOUD: + ('libcloud.compute.drivers.hpcloud', 'HPCloudNodeDriver'), Provider.VPSNET: ('libcloud.compute.drivers.vpsnet', 'VPSNetNodeDriver'), Provider.LINODE: http://git-wip-us.apache.org/repos/asf/libcloud/blob/a91147f2/libcloud/compute/types.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py index 561474e..290f38e 100644 --- a/libcloud/compute/types.py +++ b/libcloud/compute/types.py @@ -120,6 +120,9 @@ class Provider(object): IKOULA = 'ikoula' OUTSCALE_SAS = 'outscale_sas' + # OpenStack based providers + HPCLOUD = 'hpcloud' + # Deprecated constants which are still supported EC2_US_EAST = 'ec2_us_east' EC2_EU = 'ec2_eu_west' # deprecated name
