2014-05-28 11:02:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2013-09-26 11:13:29 +01:00
|
|
|
# Copyright 2013 Red Hat, Inc.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
from ironicclient.common import utils
|
2014-02-10 18:45:12 +02:00
|
|
|
from ironicclient.openstack.common import cliutils
|
2014-09-09 11:50:07 +01:00
|
|
|
from ironicclient.v1 import resource_fields as res_fields
|
2013-09-26 11:13:29 +01:00
|
|
|
|
|
|
|
|
2013-09-30 14:22:38 +01:00
|
|
|
def _print_chassis_show(chassis):
|
2013-11-22 07:29:04 +08:00
|
|
|
fields = ['uuid', 'description', 'created_at', 'updated_at', 'extra']
|
2013-09-30 14:22:38 +01:00
|
|
|
data = dict([(f, getattr(chassis, f, '')) for f in fields])
|
2014-02-10 18:45:12 +02:00
|
|
|
cliutils.print_dict(data, wrap=72)
|
2013-09-30 14:22:38 +01:00
|
|
|
|
|
|
|
|
2014-07-03 16:54:36 +03:00
|
|
|
@cliutils.arg('chassis', metavar='<chassis id>', help="UUID of chassis")
|
2013-09-26 11:13:29 +01:00
|
|
|
def do_chassis_show(cc, args):
|
|
|
|
"""Show a chassis."""
|
2013-11-19 18:35:06 +02:00
|
|
|
chassis = cc.chassis.get(args.chassis)
|
|
|
|
_print_chassis_show(chassis)
|
2013-09-26 11:13:29 +01:00
|
|
|
|
|
|
|
|
2014-09-09 11:50:07 +01:00
|
|
|
@cliutils.arg(
|
|
|
|
'--detail',
|
|
|
|
dest='detail',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Show detailed information about chassis.")
|
2014-05-01 15:22:20 +01:00
|
|
|
@cliutils.arg(
|
|
|
|
'--limit',
|
|
|
|
metavar='<limit>',
|
|
|
|
type=int,
|
|
|
|
help='Maximum number of chassis to return per request, '
|
|
|
|
'0 for no limit. Default is the maximum number used '
|
|
|
|
'by the Ironic API Service.')
|
|
|
|
@cliutils.arg(
|
|
|
|
'--marker',
|
|
|
|
metavar='<marker>',
|
|
|
|
help='Chassis UUID (e.g of the last chassis in the list '
|
|
|
|
'from a previous request). Returns the list of chassis '
|
|
|
|
'after this UUID.')
|
2014-08-15 16:12:19 +02:00
|
|
|
@cliutils.arg(
|
|
|
|
'--sort-key',
|
|
|
|
metavar='<sort_key>',
|
|
|
|
help='Chassis field that will be used for sorting.')
|
|
|
|
@cliutils.arg(
|
|
|
|
'--sort-dir',
|
|
|
|
metavar='<sort_dir>',
|
|
|
|
choices=['asc', 'desc'],
|
|
|
|
help='Sort direction: one of "asc" (the default) or "desc".')
|
2013-09-26 11:13:29 +01:00
|
|
|
def do_chassis_list(cc, args):
|
|
|
|
"""List chassis."""
|
2014-09-09 11:50:07 +01:00
|
|
|
if args.detail:
|
|
|
|
fields = res_fields.CHASSIS_FIELDS
|
|
|
|
field_labels = res_fields.CHASSIS_FIELD_LABELS
|
|
|
|
else:
|
|
|
|
fields = res_fields.CHASSIS_LIST_FIELDS
|
|
|
|
field_labels = res_fields.CHASSIS_LIST_FIELD_LABELS
|
|
|
|
|
2014-08-15 16:12:19 +02:00
|
|
|
params = utils.common_params_for_list(args, fields, field_labels)
|
|
|
|
|
|
|
|
chassis = cc.chassis.list(**params)
|
2014-08-14 15:53:21 +02:00
|
|
|
cliutils.print_list(chassis, fields,
|
|
|
|
field_labels=field_labels,
|
|
|
|
sortby_index=None)
|
2013-09-26 11:13:29 +01:00
|
|
|
|
|
|
|
|
2014-07-03 16:54:36 +03:00
|
|
|
@cliutils.arg(
|
|
|
|
'-d', '--description',
|
|
|
|
metavar='<description>',
|
|
|
|
help='Free text description of the chassis')
|
|
|
|
@cliutils.arg(
|
|
|
|
'-e', '--extra',
|
|
|
|
metavar="<key=value>",
|
|
|
|
action='append',
|
|
|
|
help="Record arbitrary key/value metadata. "
|
|
|
|
"Can be specified multiple times")
|
2013-09-26 11:13:29 +01:00
|
|
|
def do_chassis_create(cc, args):
|
|
|
|
"""Create a new chassis."""
|
|
|
|
field_list = ['description', 'extra']
|
|
|
|
fields = dict((k, v) for (k, v) in vars(args).items()
|
|
|
|
if k in field_list and not (v is None))
|
|
|
|
fields = utils.args_array_to_dict(fields, 'extra')
|
|
|
|
chassis = cc.chassis.create(**fields)
|
|
|
|
|
|
|
|
field_list.append('uuid')
|
|
|
|
data = dict([(f, getattr(chassis, f, '')) for f in field_list])
|
2014-02-10 18:45:12 +02:00
|
|
|
cliutils.print_dict(data, wrap=72)
|
2013-09-26 11:13:29 +01:00
|
|
|
|
|
|
|
|
2014-07-03 16:54:36 +03:00
|
|
|
@cliutils.arg(
|
|
|
|
'chassis',
|
|
|
|
metavar='<chassis id>',
|
|
|
|
nargs='+',
|
|
|
|
help="UUID of chassis")
|
2013-09-26 11:13:29 +01:00
|
|
|
def do_chassis_delete(cc, args):
|
|
|
|
"""Delete a chassis."""
|
2013-10-03 14:02:05 +01:00
|
|
|
for c in args.chassis:
|
2013-11-19 18:35:06 +02:00
|
|
|
cc.chassis.delete(c)
|
2013-11-11 11:44:46 +01:00
|
|
|
print('Deleted chassis %s' % c)
|
2013-09-26 11:13:29 +01:00
|
|
|
|
|
|
|
|
2014-07-03 16:54:36 +03:00
|
|
|
@cliutils.arg('chassis', metavar='<chassis id>', help="UUID of chassis")
|
|
|
|
@cliutils.arg(
|
|
|
|
'op',
|
|
|
|
metavar='<op>',
|
|
|
|
choices=['add', 'replace', 'remove'],
|
|
|
|
help="Operations: 'add', 'replace' or 'remove'")
|
|
|
|
@cliutils.arg(
|
|
|
|
'attributes',
|
|
|
|
metavar='<path=value>',
|
|
|
|
nargs='+',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
help="Attributes to add/replace or remove "
|
|
|
|
"(only PATH is necessary on remove)")
|
2013-09-30 14:22:38 +01:00
|
|
|
def do_chassis_update(cc, args):
|
|
|
|
"""Update a chassis."""
|
|
|
|
patch = utils.args_array_to_patch(args.op, args.attributes[0])
|
2013-11-19 18:35:06 +02:00
|
|
|
chassis = cc.chassis.update(args.chassis, patch)
|
2013-09-30 14:22:38 +01:00
|
|
|
_print_chassis_show(chassis)
|
2013-10-15 12:09:49 +01:00
|
|
|
|
|
|
|
|
2014-09-09 11:50:07 +01:00
|
|
|
@cliutils.arg(
|
|
|
|
'--detail',
|
|
|
|
dest='detail',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Show detailed information about nodes.")
|
2014-05-01 15:22:20 +01:00
|
|
|
@cliutils.arg(
|
|
|
|
'--limit',
|
|
|
|
metavar='<limit>',
|
|
|
|
type=int,
|
|
|
|
help='Maximum number of nodes to return per request, '
|
|
|
|
'0 for no limit. Default is the maximum number used '
|
|
|
|
'by the Ironic API Service.')
|
|
|
|
@cliutils.arg(
|
|
|
|
'--marker',
|
|
|
|
metavar='<marker>',
|
|
|
|
help='Node UUID (e.g of the last node in the list from '
|
|
|
|
'a previous request). Returns the list of nodes '
|
|
|
|
'after this UUID.')
|
2014-08-15 16:12:19 +02:00
|
|
|
@cliutils.arg(
|
|
|
|
'--sort-key',
|
|
|
|
metavar='<sort_key>',
|
|
|
|
help='Node field that will be used for sorting.')
|
|
|
|
@cliutils.arg(
|
|
|
|
'--sort-dir',
|
|
|
|
metavar='<sort_dir>',
|
|
|
|
choices=['asc', 'desc'],
|
|
|
|
help='Sort direction: one of "asc" (the default) or "desc".')
|
2014-07-03 16:54:36 +03:00
|
|
|
@cliutils.arg('chassis', metavar='<chassis id>', help="UUID of chassis")
|
2013-10-15 12:09:49 +01:00
|
|
|
def do_chassis_node_list(cc, args):
|
|
|
|
"""List the nodes contained in the chassis."""
|
2014-09-09 11:50:07 +01:00
|
|
|
if args.detail:
|
|
|
|
fields = res_fields.NODE_FIELDS
|
|
|
|
field_labels = res_fields.NODE_FIELD_LABELS
|
|
|
|
else:
|
|
|
|
fields = res_fields.NODE_LIST_FIELDS
|
|
|
|
field_labels = res_fields.NODE_LIST_FIELD_LABELS
|
|
|
|
|
2014-08-15 16:12:19 +02:00
|
|
|
params = utils.common_params_for_list(args, fields, field_labels)
|
|
|
|
|
|
|
|
nodes = cc.chassis.list_nodes(args.chassis, **params)
|
2014-08-14 15:53:21 +02:00
|
|
|
cliutils.print_list(nodes, fields,
|
|
|
|
field_labels=field_labels,
|
|
|
|
sortby_index=None)
|