1
# Copyright 2012 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
# vim: tabstop=4 shiftwidth=4 softtabstop=4
20
from cliff import show
22
from quantumclient.quantum.v1_1 import QuantumInterfaceCommand
25
class PlugInterface(QuantumInterfaceCommand):
26
"""Plug interface to a given port"""
29
log = logging.getLogger(__name__ + '.PlugInterface')
31
def get_parser(self, prog_name):
32
parser = super(PlugInterface, self).get_parser(prog_name)
34
'iface_id', metavar='iface-id',
35
help='_(ID of the interface to plug)', )
38
def run(self, parsed_args):
39
self.log.debug('run(%s)' % parsed_args)
40
quantum_client = self.app.client_manager.quantum
41
quantum_client.tenant = parsed_args.tenant_id
42
quantum_client.format = parsed_args.request_format
44
data = {'attachment': {'id': '%s' % parsed_args.iface_id, }, }
45
quantum_client.attach_resource(parsed_args.net_id,
48
print >>self.app.stdout, (_('Plugged interface %(interfaceid)s'
49
' into Logical Port %(portid)s')
50
% {'interfaceid': parsed_args.iface_id,
51
'portid': parsed_args.port_id, })
56
class UnPlugInterface(QuantumInterfaceCommand):
57
"""Unplug interface from a given port"""
60
log = logging.getLogger(__name__ + '.UnPlugInterface')
62
def run(self, parsed_args):
63
self.log.debug('run(%s)' % parsed_args)
64
quantum_client = self.app.client_manager.quantum
65
quantum_client.tenant = parsed_args.tenant_id
66
quantum_client.format = parsed_args.request_format
68
quantum_client.detach_resource(parsed_args.net_id, parsed_args.port_id)
69
print >>self.app.stdout, (
70
_('Unplugged interface on Logical Port %(portid)s')
71
% {'portid': parsed_args.port_id, })
76
class ShowInterface(QuantumInterfaceCommand, show.ShowOne):
77
"""Show interface on a given port"""
80
log = logging.getLogger(__name__ + '.ShowInterface')
82
def get_data(self, parsed_args):
83
self.log.debug('get_data(%s)' % parsed_args)
84
quantum_client = self.app.client_manager.quantum
85
quantum_client.tenant = parsed_args.tenant_id
86
quantum_client.format = parsed_args.request_format
88
iface = quantum_client.show_port_attachment(
90
parsed_args.port_id)['attachment']
94
iface['id'] = '<none>'
97
return zip(*sorted(iface.iteritems()))