From 481b711faefe21738da20187cef80fc5fa63fce4 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Tue, 1 Dec 2015 16:00:28 +0800 Subject: [PATCH] SDK integration: Add a temporary method to create network client using sdk. This patch adds a temporary method to create a network client using sdk. This method will help to migrate network commands from neutronclient to sdk one by one. The command which is being migrated will use this temporary method to create the sdk client, and the rest ones will use the old client. The temporary method will finally be removed and implement the same thing in make_client(). This patch will also add sdk to requirements file. And adds some formatter helper functions, which will be used in class CreateNetwork, ListNetwork and ShowNetwork. This patch is splited from TerryHowe 's original patch. Change-Id: Ie9b35747680afeb66cf6922e2c654fbca7e03569 Implements: blueprint neutron-client Co-Authored-By: TerryHowe Co-Authored-By: Tang Chen --- openstackclient/network/v2/network.py | 24 +++++++++++++++++++++++- requirements.txt | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 336b3086e2..cd14592df4 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -20,15 +20,37 @@ from cliff import command from cliff import lister from cliff import show +from openstack import connection + from openstackclient.common import exceptions from openstackclient.common import utils from openstackclient.identity import common as identity_common from openstackclient.network import common +def _format_admin_state(item): + return 'UP' if item else 'DOWN' + + +def _format_router_external(item): + return 'External' if item else 'Internal' + + +_formatters = { + 'subnets': utils.format_list, + 'admin_state_up': _format_admin_state, + 'router_external': _format_router_external, +} + + +def _make_client_sdk(instance): + """Return a network proxy""" + conn = connection.Connection(authenticator=instance.session.auth) + return conn.network + + def _prep_network_detail(net): """Prepare network object for output""" - if 'subnets' in net: net['subnets'] = utils.format_list(net['subnets']) if 'admin_state_up' in net: diff --git a/requirements.txt b/requirements.txt index fbe3b8d656..8b1a999d2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ six>=1.9.0 Babel>=1.3 cliff>=1.15.0 # Apache-2.0 keystoneauth1>=1.0.0 +openstacksdk os-client-config!=1.6.2,>=1.4.0 oslo.config>=2.7.0 # Apache-2.0 oslo.i18n>=1.5.0 # Apache-2.0