attach/detach interface command

Change-Id: I53b5d25736f0be116501a3e58bea6683d6f85414
This commit is contained in:
Isaku Yamahata
2014-08-05 00:31:39 +09:00
parent bd5bbfbe92
commit 2ec8130365
3 changed files with 57 additions and 0 deletions

View File

@@ -83,6 +83,8 @@ COMMAND_V1 = {
'device-show': device.ShowDevice,
'device-update': device.UpdateDevice,
'device-delete': device.DeleteDevice,
'interface-attach': device.AttachInterface,
'interface-detach': device.DetachInterface,
}
COMMANDS = {'1.0': COMMAND_V1}

View File

@@ -19,6 +19,9 @@
#
# @author: Isaku Yamahata, Intel
import abc
import six
from tackerclient.common import exceptions
from tackerclient.openstack.common.gettextutils import _
from tackerclient.tacker import v1_0 as tackerV10
@@ -135,3 +138,45 @@ class DeleteDevice(tackerV10.DeleteCommand):
"""Delete a given Device."""
resource = _DEVICE
@six.add_metaclass(abc.ABCMeta)
class _XtachInterface(tackerV10.UpdateCommand):
resource = _DEVICE
@abc.abstractmethod
def call_api(self, tacker_client, device_id, body):
pass
def args2body(self, parsed_args):
body = {
'port_id': parsed_args.port_id,
}
tackerV10.update_dict(parsed_args, body, [])
return body
def get_parser(self, prog_name):
parser = super(AttachInterface, self).get_parser(prog_name)
parser.add_argument('port_id', metavar='PORT',
help=_('port to attach/detach'))
self.add_known_arguments(parser)
return parser
def run(self, parsed_args):
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
body = self.args2body(parsed_args)
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
self.resource,
parsed_args.id)
self.call_api(tacker_client, _id, body)
class AttachInterface(_XtachInterface):
def call_api(self, tacker_client, device_id, body):
return tacker_client.attach_interface(device_id, body)
class DetachInterface(_XtachInterface):
def call_api(self, tacker_client, device_id, body):
return tacker_client.detach_interface(device_id, body)

View File

@@ -150,6 +150,8 @@ class Client(object):
device_template_path = '/device-templates/%s'
devices_path = '/devices'
device_path = '/devices/%s'
interface_attach_path = '/devices/%s/attach_interface'
interface_detach_path = '/devices/%s/detach_interface'
# API has no way to report plurals, so we have to hard code them
EXTED_PLURALS = {}
@@ -220,6 +222,14 @@ class Client(object):
def delete_device(self, device):
return self.delete(self.device_path % device)
@APIParamsCall
def attach_interface(self, device, body=None):
return self.put(self.attach_interface_path % device, body)
@APIParamsCall
def detach_interface(self, device, body=None):
return self.put(self.detach_interface_path % device, body)
def __init__(self, **kwargs):
"""Initialize a new client for the Tacker v1.0 API."""
super(Client, self).__init__()