1 # Copyright 2012 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from __future__ import print_function
20 from oslo_utils import strutils
21 import escalatorclient.v1.versions
22 import escalatorclient.v1.clusters
23 import escalatorclient.v1.update
24 from escalatorclient.common import utils
26 _bool_strict = functools.partial(strutils.bool_from_string, strict=True)
29 def _escalator_show(escalator, max_column_width=80):
30 info = copy.deepcopy(escalator._info)
31 exclusive_field = ('deleted', 'deleted_at')
32 for field in exclusive_field:
35 utils.print_dict(info, max_column_width=max_column_width)
38 @utils.arg('--type', metavar='<TYPE>',
39 help='Type of escalator version, supported type are "internal": '
40 'the internal version of escalator.')
41 def do_version(dc, args):
42 """Get version of escalator."""
43 fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
45 # Filter out values we can't use
46 VERSION_PARAMS = escalatorclient.v1.versions.VERSION_PARAMS
47 fields = dict(filter(lambda x: x[0] in VERSION_PARAMS, fields.items()))
48 version = dc.versions.version(**fields)
49 _escalator_show(version)
52 @utils.arg('--name', metavar='<NAME>',
53 help='Filter version to those that have this name.')
54 @utils.arg('--status', metavar='<STATUS>',
55 help='Filter version status.')
56 @utils.arg('--type', metavar='<type>',
57 help='Filter by type.')
58 @utils.arg('--version', metavar='<version>',
59 help='Filter by version number.')
60 @utils.arg('--page-size', metavar='<SIZE>', default=None, type=int,
61 help='Number to request in each paginated request.')
62 @utils.arg('--sort-key', default='name',
63 choices=escalatorclient.v1.versions.SORT_KEY_VALUES,
64 help='Sort version list by specified field.')
65 @utils.arg('--sort-dir', default='asc',
66 choices=escalatorclient.v1.versions.SORT_DIR_VALUES,
67 help='Sort version list in specified direction.')
68 def do_cluster_version_list(dc, args):
69 """List hosts you can access."""
70 filter_keys = ['name', 'type', 'status', 'version']
71 filter_items = [(key, getattr(args, key)) for key in filter_keys]
72 filters = dict([item for item in filter_items if item[1] is not None])
74 kwargs = {'filters': filters}
75 if args.page_size is not None:
76 kwargs['page_size'] = args.page_size
78 kwargs['sort_key'] = args.sort_key
79 kwargs['sort_dir'] = args.sort_dir
81 versions = dc.versions.list(**kwargs)
83 columns = ['ID', 'NAME', 'TYPE', 'VERSION', 'size',
84 'checksum', 'description', 'status', 'VERSION_PATCH']
86 utils.print_list(versions, columns)
89 @utils.arg('--name', metavar='<NAME>',
90 help='Filter version to those that have this name.')
91 @utils.arg('--status', metavar='<STATUS>',
92 help='Filter version status.')
93 @utils.arg('--type', metavar='<type>',
94 help='Filter by type.')
95 @utils.arg('--version', metavar='<version>',
96 help='Filter by version number.')
97 @utils.arg('--page-size', metavar='<SIZE>', default=None, type=int,
98 help='Number to request in each paginated request.')
99 @utils.arg('--sort-key', default='name',
100 choices=escalatorclient.v1.versions.SORT_KEY_VALUES,
101 help='Sort version list by specified field.')
102 @utils.arg('--sort-dir', default='asc',
103 choices=escalatorclient.v1.versions.SORT_DIR_VALUES,
104 help='Sort version list in specified direction.')
105 def do_cluster_list(gc, args):
106 """List clusters you can access."""
107 filter_keys = ['name']
108 filter_items = [(key, getattr(args, key)) for key in filter_keys]
109 filters = dict([item for item in filter_items if item[1] is not None])
111 kwargs = {'filters': filters}
112 if args.page_size is not None:
113 kwargs['page_size'] = args.page_size
115 kwargs['sort_key'] = args.sort_key
116 kwargs['sort_dir'] = args.sort_dir
118 clusters = gc.clusters.list(**kwargs)
120 columns = ['ID', 'Name', 'Description', 'Nodes', 'Networks',
121 'Auto_scale', 'Use_dns', 'Status']
122 utils.print_list(clusters, columns)
125 @utils.arg('id', metavar='<ID>',
126 help='Filter cluster to those that have this id.')
127 def do_cluster_detail(gc, args):
128 """List cluster you can access."""
130 filter_items = [(key, getattr(args, key)) for key in filter_keys]
131 filters = dict([item for item in filter_items if item[1] is not None])
132 fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
133 kwargs = {'filters': filters}
135 cluster = utils.find_resource(gc.clusters, fields.pop('id'))
136 _escalator_show(cluster)
138 cluster = gc.clusters.list(**kwargs)
139 columns = ['ID', 'Name', 'Description', 'Nodes',
140 'Networks', 'Auto_scale', 'Use_dns']
141 utils.print_list(cluster, columns)
144 @utils.arg('cluster_id', metavar='<CLUSTER_ID>',
145 help='The cluster ID to update os and TECS.')
146 @utils.arg('--hosts', metavar='<HOSTS>', nargs='+',
147 help='The host ID to update')
148 @utils.arg('--update-object', metavar='<UPDATE_OBJECT>',
149 help='update object:vplat or tecs or zenic......')
150 @utils.arg('--version-id', metavar='<VERSION>',
151 help='if not patch, update version id is used to update.')
152 @utils.arg('--version-patch-id', metavar='<VERSION_PATCH>',
153 help='if update version patch, version patch id is needed')
154 @utils.arg('--update-script', metavar='<UPDATE_SCRIPT>',
155 help='update script in /var/lib/daisy/os')
156 def do_update(gc, args):
158 fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
160 # Filter out values we can't use
161 CREATE_PARAMS = escalatorclient.v1.update.CREATE_PARAMS
162 fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items()))
164 update = gc.update.update(**fields)
165 _escalator_show(update)