2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2012, Nachi Ueno, NTT MCL, Inc.
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
21
from cliff import lister
23
from quantumclient.common import utils
24
from quantumclient.quantum.v2_0 import QuantumCommand
25
from quantumclient.quantum.v2_0.port import _format_fixed_ips
28
class ProbeCommand(QuantumCommand):
29
log = logging.getLogger(__name__ + '.ProbeCommand')
31
def get_debug_agent(self):
32
return self.app.debug_agent
34
def run(self, parsed_args):
35
self.log.debug('run(%s)' % parsed_args)
36
self.app.stdout.write(_('Unimplemented commands') + '\n')
39
class CreateProbe(ProbeCommand):
40
"""Create probe port and interface, then plug it in."""
42
log = logging.getLogger(__name__ + '.CreateProbe')
44
def get_parser(self, prog_name):
45
parser = super(CreateProbe, self).get_parser(prog_name)
47
'id', metavar='network_id',
48
help='ID of network to probe')
51
def run(self, parsed_args):
52
self.log.debug('run(%s)' % parsed_args)
53
debug_agent = self.get_debug_agent()
54
port = debug_agent.create_probe(parsed_args.id)
55
self.app.stdout.write(_('Probe created : %s ') % port.id + '\n')
58
class DeleteProbe(ProbeCommand):
59
"""Delete probe - delete port then uplug """
61
log = logging.getLogger(__name__ + '.DeleteProbe')
63
def get_parser(self, prog_name):
64
parser = super(DeleteProbe, self).get_parser(prog_name)
66
'id', metavar='port_id',
67
help='ID of probe port to delete')
70
def run(self, parsed_args):
71
self.log.debug('run(%s)' % parsed_args)
72
debug_agent = self.get_debug_agent()
73
debug_agent.delete_probe(parsed_args.id)
74
self.app.stdout.write(_('Probe %s deleted') % parsed_args.id + '\n')
77
class ListProbe(QuantumCommand, lister.Lister):
80
log = logging.getLogger(__name__ + '.ListProbe')
81
_formatters = {'fixed_ips': _format_fixed_ips, }
83
def get_debug_agent(self):
84
return self.app.debug_agent
86
def get_data(self, parsed_args):
88
debug_agent = self.get_debug_agent()
89
info = debug_agent.list_probes()
90
columns = len(info) > 0 and sorted(info[0].keys()) or []
91
return (columns, (utils.get_item_properties(
92
s, columns, formatters=self._formatters, )
96
class ClearProbe(ProbeCommand):
97
"""Clear All probes """
99
log = logging.getLogger(__name__ + '.ClearProbe')
101
def run(self, parsed_args):
102
self.log.debug('run(%s)' % parsed_args)
103
debug_agent = self.get_debug_agent()
104
debug_agent.clear_probe()
105
self.app.stdout.write(_('All Probes deleted ') + '\n')
108
class ExecProbe(ProbeCommand):
109
"""Exec commands on the namespace of the probe
112
log = logging.getLogger(__name__ + '.ExecProbe')
114
def get_parser(self, prog_name):
115
parser = super(ExecProbe, self).get_parser(prog_name)
117
'id', metavar='port_id',
118
help='ID of probe port to execute command')
120
'command', metavar='command',
123
help='Command to execute')
126
def run(self, parsed_args):
127
self.log.debug('run(%s)' % parsed_args)
128
debug_agent = self.get_debug_agent()
129
result = debug_agent.exec_command(parsed_args.id, parsed_args.command)
130
self.app.stdout.write(result + '\n')
133
class PingAll(ProbeCommand):
137
log = logging.getLogger(__name__ + '.ExecProbe')
139
def get_parser(self, prog_name):
140
parser = super(PingAll, self).get_parser(prog_name)
142
'--timeout', metavar='<timeout>',
146
'--id', metavar='network_id',
148
help='ID of network')
151
def run(self, parsed_args):
152
self.log.debug('run(%s)' % parsed_args)
153
debug_agent = self.get_debug_agent()
154
result = debug_agent.ping_all(parsed_args.id,
155
timeout=parsed_args.timeout)
156
self.app.stdout.write(result + '\n')