| 1 |
# Copyright 2013 OpenStack Foundation. |
| 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 |
|
| 17 |
from neutronclient._i18n import _ |
| 18 |
from neutronclient.neutron import v2_0 as neutronV20 |
| 19 |
|
| 20 |
|
| 21 |
def _format_timestamp(component): |
| 22 |
try: |
| 23 |
return component['heartbeat_timestamp'].split(".", 2)[0] |
| 24 |
except (TypeError, KeyError): |
| 25 |
return '' |
| 26 |
|
| 27 |
|
| 28 |
class ListAgent(neutronV20.ListCommand): |
| 29 |
"""List agents.""" |
| 30 |
|
| 31 |
resource = 'agent' |
| 32 |
list_columns = ['id', 'agent_type', 'host', 'availability_zone', 'alive', |
| 33 |
'admin_state_up', 'binary'] |
| 34 |
_formatters = {'heartbeat_timestamp': _format_timestamp} |
| 35 |
sorting_support = True |
| 36 |
|
| 37 |
def extend_list(self, data, parsed_args): |
| 38 |
for agent in data: |
| 39 |
if 'alive' in agent: |
| 40 |
agent['alive'] = ":-)" if agent['alive'] else 'xxx' |
| 41 |
|
| 42 |
|
| 43 |
class ShowAgent(neutronV20.ShowCommand): |
| 44 |
"""Show information of a given agent.""" |
| 45 |
|
| 46 |
resource = 'agent' |
| 47 |
allow_names = False |
| 48 |
json_indent = 5 |
| 49 |
|
| 50 |
|
| 51 |
class DeleteAgent(neutronV20.DeleteCommand): |
| 52 |
"""Delete a given agent.""" |
| 53 |
|
| 54 |
resource = 'agent' |
| 55 |
allow_names = False |
| 56 |
|
| 57 |
|
| 58 |
class UpdateAgent(neutronV20.UpdateCommand): |
| 59 |
"""Updates the admin status and description for a specified agent.""" |
| 60 |
|
| 61 |
resource = 'agent' |
| 62 |
allow_names = False |
| 63 |
|
| 64 |
def add_known_arguments(self, parser): |
| 65 |
parser.add_argument( |
| 66 |
'--admin-state-down', |
| 67 |
dest='admin_state', |
| 68 |
action='store_false', |
| 69 |
help=_('Set admin state up of the agent to false.')) |
| 70 |
parser.add_argument( |
| 71 |
'--description', |
| 72 |
help=_('Description for the agent.')) |
| 73 |
|
| 74 |
def args2body(self, parsed_args): |
| 75 |
body = {'admin_state_up': parsed_args.admin_state} |
| 76 |
neutronV20.update_dict(parsed_args, body, |
| 77 |
['description']) |
| 78 |
return {self.resource: body} |