Skip to content

Commit

Permalink
Added cloudpipe support. Fixes bug 962286
Browse files Browse the repository at this point in the history
Change-Id: Id1c580a085d0bf9699689c5d6d8c8103d7d4a3f8
  • Loading branch information
alvarolopez authored and vishvananda committed Mar 25, 2012
1 parent 7615e51 commit be328c7
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
@@ -1,4 +1,5 @@
Aaron Lee <aaron.lee@rackspace.com>
Alvaro Lopez Garcia <aloga@ifca.unican.es>
Andrey Brindeyev <abrindeyev@griddynamics.com>
Andy Smith <github@anarkystic.com>
Anthony Young <sleepsonthefloor@gmail.com>
Expand Down
2 changes: 2 additions & 0 deletions novaclient/v1_1/client.py
@@ -1,5 +1,6 @@
from novaclient import client
from novaclient.v1_1 import certs
from novaclient.v1_1 import cloudpipe
from novaclient.v1_1 import aggregates
from novaclient.v1_1 import flavors
from novaclient.v1_1 import floating_ip_dns
Expand Down Expand Up @@ -54,6 +55,7 @@ def __init__(self, username, api_key, project_id, auth_url,
# extensions
self.dns_domains = floating_ip_dns.FloatingIPDNSDomainManager(self)
self.dns_entries = floating_ip_dns.FloatingIPDNSEntryManager(self)
self.cloudpipe = cloudpipe.CloudpipeManager(self)
self.certs = certs.CertificateManager(self)
self.floating_ips = floating_ips.FloatingIPManager(self)
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
Expand Down
48 changes: 48 additions & 0 deletions novaclient/v1_1/cloudpipe.py
@@ -0,0 +1,48 @@
# Copyright 2012 OpenStack LLC.
# All Rights Reserved.
#
# Licensed 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.

"""Cloudpipe interface."""

from novaclient import base


class Cloudpipe(base.Resource):
"""A cloudpipe instance is a VPN attached to a proejct's VLAN."""

def __repr__(self):
return "<Cloudpipe: %s>" % self.project_id

def delete(self):
self.manager.delete(self)


class CloudpipeManager(base.ManagerWithFind):
resource_class = Cloudpipe

def create(self, project):
"""
Launch a cloudpipe instance.
:param project: name of the project for the cloudpipe
"""
body = {'cloudpipe': {'project_id': project}}
return self._create('/os-cloudpipe', body, 'instance_id',
return_raw=True)

def list(self):
"""
Get a list of cloudpipe instances.
"""
return self._list('/os-cloudpipe', 'cloudpipes')
13 changes: 13 additions & 0 deletions novaclient/v1_1/shell.py
Expand Up @@ -230,6 +230,19 @@ def do_boot(cs, args):
_poll_for_status(cs.servers.get, info['id'], 'building', ['active'])


def do_cloudpipe_list(cs, args):
"""Print a list of all cloudpipe instances."""
cloudpipes = cs.cloudpipe.list()
columns = ['Project Id', "Public IP", "Public Port", "Internal IP"]
utils.print_list(cloudpipes, columns)


@utils.arg('project', metavar='<project>', help='Name of the project.')
def do_cloudpipe_create(cs, args):
"""Create a cloudpipe instance for the given project"""
cs.cloudpipe.create(args.project)


def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
poll_period=5, show_progress=True):
"""Block while an action is being performed, periodically printing
Expand Down
12 changes: 12 additions & 0 deletions tests/v1_1/fakes.py
Expand Up @@ -339,6 +339,18 @@ def post_servers_1234_action(self, body, **kw):
raise AssertionError("Unexpected server action: %s" % action)
return (resp, _body)

#
# Cloudpipe
#

def get_os_cloudpipe(self, **kw):
return (200, {'cloudpipes': [
{'project_id':1}
]})

def post_os_cloudpipe(self, **ks):
return (202, {'instance_id': '9d5824aa-20e6-4b9f-b967-76a699fc51fd'})

#
# Flavors
#
Expand Down
22 changes: 22 additions & 0 deletions tests/v1_1/test_cloudpipe.py
@@ -0,0 +1,22 @@
from novaclient import exceptions
from novaclient.v1_1 import cloudpipe
from tests import utils
from tests.v1_1 import fakes


cs = fakes.FakeClient()


class CloudpipeTest(utils.TestCase):

def test_list_cloudpipes(self):
cp = cs.cloudpipe.list()
cs.assert_called('GET', '/os-cloudpipe')
[self.assertTrue(isinstance(c, cloudpipe.Cloudpipe)) for c in cp]

def test_create(self):
project = "test"
cp = cs.cloudpipe.create(project)
body = {'cloudpipe': {'project_id': project}}
cs.assert_called('POST', '/os-cloudpipe', body)
self.assertTrue(isinstance(cp, str))

0 comments on commit be328c7

Please sign in to comment.