Added cloudpipe support. Fixes bug 962286

Change-Id: Id1c580a085d0bf9699689c5d6d8c8103d7d4a3f8
This commit is contained in:
Alvaro Lopez Garcia 2012-03-22 12:23:39 +01:00
parent 204ffabe38
commit 0191005de3
6 changed files with 98 additions and 0 deletions

@ -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>

@ -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
@ -55,6 +56,7 @@ class Client(object):
# 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)

@ -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')

@ -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

@ -339,6 +339,18 @@ class FakeHTTPClient(base_client.HTTPClient):
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
#

@ -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))