Client bindings for Get-me-a-network
Add client bindings for auto-allocated-topology. Add the 'auto-allocated-topology-show' CLI. Partially-implements: blueprint get-me-a-network Depends-On: Ia35e8a946bf0ac0bb085cde46b675d17b0bb2f51 Change-Id: I67a30ce552fd0310e051ac39dda0a763ee29ef6e
This commit is contained in:
parent
9f792d0b9c
commit
da57c86a53
65
neutronclient/neutron/v2_0/auto_allocated_topology.py
Executable file
65
neutronclient/neutron/v2_0/auto_allocated_topology.py
Executable file
@ -0,0 +1,65 @@
|
||||
# Copyright 2016 IBM
|
||||
# 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.
|
||||
#
|
||||
|
||||
import argparse
|
||||
from cliff import show
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from neutronclient._i18n import _
|
||||
from neutronclient.neutron import v2_0
|
||||
|
||||
|
||||
class ShowAutoAllocatedTopology(v2_0.NeutronCommand, show.ShowOne):
|
||||
"""Show the auto-allocated topology of a given tenant."""
|
||||
|
||||
resource = 'auto_allocated_topology'
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowAutoAllocatedTopology, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--tenant-id', metavar='tenant-id',
|
||||
help=_('The owner tenant ID.'))
|
||||
# Allow people to do
|
||||
# neutron auto-allocated-topology-show <tenant-id>
|
||||
# (Only useful to users who can look at other tenants' topologies.)
|
||||
# We use a different name for this arg because the default will
|
||||
# override whatever is in the named arg otherwise.
|
||||
parser.add_argument(
|
||||
'pos_tenant_id',
|
||||
help=argparse.SUPPRESS, nargs='?')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.get_client()
|
||||
tenant_id = parsed_args.tenant_id or parsed_args.pos_tenant_id
|
||||
data = client.show_auto_allocated_topology(tenant_id)
|
||||
if self.resource in data:
|
||||
for k, v in data[self.resource].items():
|
||||
if isinstance(v, list):
|
||||
value = ""
|
||||
for _item in v:
|
||||
if value:
|
||||
value += "\n"
|
||||
if isinstance(_item, dict):
|
||||
value += jsonutils.dumps(_item)
|
||||
else:
|
||||
value += str(_item)
|
||||
data[self.resource][k] = value
|
||||
elif v is None:
|
||||
data[self.resource][k] = ''
|
||||
return zip(*sorted(data[self.resource].items()))
|
||||
else:
|
||||
return None
|
@ -43,6 +43,7 @@ from neutronclient.common import utils
|
||||
from neutronclient.neutron.v2_0 import address_scope
|
||||
from neutronclient.neutron.v2_0 import agent
|
||||
from neutronclient.neutron.v2_0 import agentscheduler
|
||||
from neutronclient.neutron.v2_0 import auto_allocated_topology
|
||||
from neutronclient.neutron.v2_0 import availability_zone
|
||||
from neutronclient.neutron.v2_0 import extension
|
||||
from neutronclient.neutron.v2_0.flavor import flavor
|
||||
@ -392,6 +393,8 @@ COMMAND_V2 = {
|
||||
'flavor-profile-delete': flavor_profile.DeleteFlavorProfile,
|
||||
'flavor-profile-update': flavor_profile.UpdateFlavorProfile,
|
||||
'availability-zone-list': availability_zone.ListAvailabilityZone,
|
||||
'auto-allocated-topology-show': (
|
||||
auto_allocated_topology.ShowAutoAllocatedTopology),
|
||||
}
|
||||
|
||||
COMMANDS = {'2.0': COMMAND_V2}
|
||||
|
41
neutronclient/tests/unit/test_auto_allocated_topology.py
Executable file
41
neutronclient/tests/unit/test_auto_allocated_topology.py
Executable file
@ -0,0 +1,41 @@
|
||||
# Copyright 2016 IBM
|
||||
# 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.
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
from neutronclient.neutron.v2_0 import auto_allocated_topology as aat
|
||||
from neutronclient.tests.unit import test_cli20
|
||||
|
||||
|
||||
class TestAutoAllocatedTopologyJSON(test_cli20.CLITestV20Base):
|
||||
|
||||
def test_show_auto_allocated_topology_arg(self):
|
||||
resource = 'auto_allocated_topology'
|
||||
cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
|
||||
args = ['--tenant-id', self.test_id]
|
||||
self._test_show_resource(resource, cmd, self.test_id, args)
|
||||
|
||||
def test_show_auto_allocated_topology_posarg(self):
|
||||
resource = 'auto_allocated_topology'
|
||||
cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
|
||||
args = ['some-tenant']
|
||||
self._test_show_resource(resource, cmd, "some-tenant", args)
|
||||
|
||||
def test_show_auto_allocated_topology_no_arg(self):
|
||||
resource = 'auto_allocated_topology'
|
||||
cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
|
||||
args = []
|
||||
self._test_show_resource(resource, cmd, "None", args)
|
@ -409,6 +409,7 @@ class Client(ClientBase):
|
||||
flavor_profile_bindings_path = flavor_path + service_profiles_path
|
||||
flavor_profile_binding_path = flavor_path + service_profile_path
|
||||
availability_zones_path = "/availability_zones"
|
||||
auto_allocated_topology_path = "/auto-allocated-topology/%s"
|
||||
|
||||
# API has no way to report plurals, so we have to hard code them
|
||||
EXTED_PLURALS = {'routers': 'router',
|
||||
@ -1693,6 +1694,13 @@ class Client(ClientBase):
|
||||
return self.list('availability_zones', self.availability_zones_path,
|
||||
retrieve_all, **_params)
|
||||
|
||||
@APIParamsCall
|
||||
def show_auto_allocated_topology(self, tenant_id, **_params):
|
||||
"""Fetch information about a tenant's auto-allocated topology."""
|
||||
return self.get(
|
||||
self.auto_allocated_topology_path % tenant_id,
|
||||
params=_params)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Initialize a new client for the Neutron v2.0 API."""
|
||||
super(Client, self).__init__(**kwargs)
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
CLI support for the "get-me-a-network" feature, which simplifies
|
||||
the process for launching an instance with basic network
|
||||
connectivity.
|
||||
|
||||
* The ``auto-allocated-topology-show`` command provides the
|
||||
network of the automatically allocated topology for a tenant.
|
Loading…
x
Reference in New Issue
Block a user