~ubuntu-branches/ubuntu/saucy/python-quantumclient/saucy

« back to all changes in this revision

Viewing changes to quantumclient/quantum/v2_0/agent.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2013-03-07 11:14:49 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20130307111449-08nu53xwd4bc5if2
Tags: 1:2.1.2-0ubuntu1
[ Adam Gandelman ]
* debian/control: Drop 'Provides: ${python:Provides}'.

[ Chuck Short ]
* New upstream release.
* debian/control: Add python-testtools and python-fixtures as build
  deps.
* debian/patches/override_cliff_version.patch: Dropped, no longer needed.
* debian/control: Add python-iso8601 build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2013 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 quantumclient.quantum import v2_0 as quantumV20
 
21
 
 
22
 
 
23
def _format_timestamp(component):
 
24
    try:
 
25
        return component['heartbeat_timestamp'].split(".", 2)[0]
 
26
    except Exception:
 
27
        return ''
 
28
 
 
29
 
 
30
class ListAgent(quantumV20.ListCommand):
 
31
    """List agents."""
 
32
 
 
33
    resource = 'agent'
 
34
    log = logging.getLogger(__name__ + '.ListAgent')
 
35
    list_columns = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
 
36
    _formatters = {'heartbeat_timestamp': _format_timestamp}
 
37
 
 
38
    def extend_list(self, data, parsed_args):
 
39
        for agent in data:
 
40
            agent['alive'] = ":-)" if agent['alive'] else 'xxx'
 
41
 
 
42
 
 
43
class ShowAgent(quantumV20.ShowCommand):
 
44
    """Show information of a given agent."""
 
45
 
 
46
    resource = 'agent'
 
47
    log = logging.getLogger(__name__ + '.ShowAgent')
 
48
    allow_names = False
 
49
    json_indent = 5
 
50
 
 
51
 
 
52
class DeleteAgent(quantumV20.DeleteCommand):
 
53
    """Delete a given agent."""
 
54
 
 
55
    log = logging.getLogger(__name__ + '.DeleteAgent')
 
56
    resource = 'agent'
 
57
 
 
58
 
 
59
class UpdateAgent(quantumV20.UpdateCommand):
 
60
    """Update a given agent."""
 
61
 
 
62
    log = logging.getLogger(__name__ + '.UpdateAgent')
 
63
    resource = 'agent'
 
64
    allow_names = False