~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/eucadmin/eucadmin/describerequest.py

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2011, Eucalyptus Systems, Inc.
 
2
# All rights reserved.
 
3
#
 
4
# Redistribution and use of this software in source and binary forms, with or
 
5
# without modification, are permitted provided that the following conditions
 
6
# are met:
 
7
#
 
8
#   Redistributions of source code must retain the above
 
9
#   copyright notice, this list of conditions and the
 
10
#   following disclaimer.
 
11
#
 
12
#   Redistributions in binary form must reproduce the above
 
13
#   copyright notice, this list of conditions and the
 
14
#   following disclaimer in the documentation and/or other
 
15
#   materials provided with the distribution.
 
16
#
 
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
18
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
19
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
20
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
21
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
22
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
23
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
24
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
25
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
26
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
27
# POSSIBILITY OF SUCH DAMAGE.
 
28
#
 
29
# Author: Mitch Garnaat mgarnaat@eucalyptus.com
 
30
 
 
31
from boto.roboto.awsqueryrequest import AWSQueryRequest
 
32
from boto.roboto.param import Param
 
33
import eucadmin
 
34
import math
 
35
 
 
36
class DescribeRequest(AWSQueryRequest):
 
37
 
 
38
    ServiceName = ''
 
39
    ServicePath = '/services/Configuration'
 
40
    ServiceClass = eucadmin.EucAdmin
 
41
 
 
42
    def __init__(self, **args):
 
43
        AWSQueryRequest.__init__(self, **args)
 
44
        self.list_markers = ['euca:registered']
 
45
        self.item_markers = ['euca:item']
 
46
 
 
47
    def get_connection(self, **args):
 
48
        if self.connection is None:
 
49
            args['path'] = self.ServicePath
 
50
            self.connection = self.ServiceClass(**args)
 
51
        return self.connection
 
52
 
 
53
    def cli_formatter(self, data):
 
54
        services = getattr(data, 'euca:registered')
 
55
        fields = {'euca:partition' : 15,
 
56
                  'euca:name' : 15,
 
57
                  'euca:hostName' : 25}
 
58
        for s in services:
 
59
            if s.get('euca:hostName', None) != 'detail':
 
60
                for field_name in fields:
 
61
                    field_size = math.ceil(fields[field_name]/5.0)*5
 
62
                    if len(s.get(field_name)) > field_size:
 
63
                        fields[field_name] = field_size
 
64
        fmt = '%%s\t%%-%s.%ss\t%%-%d.%ds\t%%-%ds\t%%s\t%%s' % (fields['euca:partition'],
 
65
                                                               fields['euca:partition'],
 
66
                                                               fields['euca:name'],
 
67
                                                               fields['euca:name'],
 
68
                                                               fields['euca:hostName'])
 
69
        for s in services:
 
70
            if s.get('euca:hostName', None) != 'detail':
 
71
                print fmt % (
 
72
                    self.ServiceName.upper(),
 
73
                    s.get('euca:partition', None),
 
74
                    s.get('euca:name', None),
 
75
                    s.get('euca:hostName', None),
 
76
                    s.get('euca:state', None),
 
77
                    s.get('euca:detail', None))
 
78
 
 
79
    def main(self, **args):
 
80
        return self.send(**args)
 
81
 
 
82
    def main_cli(self):
 
83
        eucadmin.print_version_if_necessary()
 
84
        self.do_cli()