~ubuntu-branches/ubuntu/utopic/python-quantumclient/utopic

« back to all changes in this revision

Viewing changes to quantumclient/quantum/v1_1/interface.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 12:45:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120816124543-5m96n37eik89sr2j
Tags: 1:2.0-0ubuntu1
* New upstream version.
* debian/control: Update build dependencies.
* debian/rules: Enable testsuite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012 OpenStack LLC.
2
 
# All Rights Reserved
3
 
#
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
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
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
14
 
#    under the License.
15
 
#
16
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
17
 
 
18
 
import logging
19
 
 
20
 
from cliff import show
21
 
 
22
 
from quantumclient.quantum.v1_1 import QuantumInterfaceCommand
23
 
 
24
 
 
25
 
class PlugInterface(QuantumInterfaceCommand):
26
 
    """Plug interface to a given port"""
27
 
 
28
 
    api = 'network'
29
 
    log = logging.getLogger(__name__ + '.PlugInterface')
30
 
 
31
 
    def get_parser(self, prog_name):
32
 
        parser = super(PlugInterface, self).get_parser(prog_name)
33
 
        parser.add_argument(
34
 
            'iface_id', metavar='iface-id',
35
 
            help='_(ID of the interface to plug)', )
36
 
        return parser
37
 
 
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
43
 
 
44
 
        data = {'attachment': {'id': '%s' % parsed_args.iface_id, }, }
45
 
        quantum_client.attach_resource(parsed_args.net_id,
46
 
                                       parsed_args.port_id,
47
 
                                       data)
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, })
52
 
 
53
 
        return
54
 
 
55
 
 
56
 
class UnPlugInterface(QuantumInterfaceCommand):
57
 
    """Unplug interface from a given port"""
58
 
 
59
 
    api = 'network'
60
 
    log = logging.getLogger(__name__ + '.UnPlugInterface')
61
 
 
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
67
 
 
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, })
72
 
 
73
 
        return
74
 
 
75
 
 
76
 
class ShowInterface(QuantumInterfaceCommand, show.ShowOne):
77
 
    """Show interface on a given port"""
78
 
 
79
 
    api = 'network'
80
 
    log = logging.getLogger(__name__ + '.ShowInterface')
81
 
 
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
87
 
 
88
 
        iface = quantum_client.show_port_attachment(
89
 
            parsed_args.net_id,
90
 
            parsed_args.port_id)['attachment']
91
 
 
92
 
        if iface:
93
 
            if 'id' not in iface:
94
 
                iface['id'] = '<none>'
95
 
        else:
96
 
            iface = {'': ''}
97
 
        return zip(*sorted(iface.iteritems()))