2014-11-20 20:02:08 -08:00
|
|
|
# Copyright 2014
|
|
|
|
# The Cloudscaling Group, Inc.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2014-11-26 12:47:22 +09:00
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from magnumclient.openstack.common import cliutils as utils
|
|
|
|
|
|
|
|
|
|
|
|
def _print_list_field(field):
|
|
|
|
return lambda obj: ', '.join(getattr(obj, field))
|
|
|
|
|
|
|
|
|
|
|
|
def _show_container(container):
|
|
|
|
utils.print_dict(container._info)
|
|
|
|
|
2014-11-20 20:02:08 -08:00
|
|
|
|
2014-11-26 13:11:47 -07:00
|
|
|
def _show_bay(bay):
|
2014-12-16 23:18:45 -07:00
|
|
|
del bay._info['links']
|
2014-11-26 13:11:47 -07:00
|
|
|
utils.print_dict(bay._info)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-12-15 12:57:54 -07:00
|
|
|
def _show_baymodel(baymodel):
|
2014-12-16 23:15:02 -07:00
|
|
|
del baymodel._info['links']
|
2014-12-15 12:57:54 -07:00
|
|
|
utils.print_dict(baymodel._info)
|
|
|
|
|
|
|
|
|
2014-12-07 10:00:04 -07:00
|
|
|
def _show_node(node):
|
|
|
|
utils.print_dict(node._info)
|
|
|
|
|
|
|
|
|
2014-12-17 02:18:39 -07:00
|
|
|
def _show_pod(node):
|
|
|
|
utils.print_dict(node._info)
|
|
|
|
|
|
|
|
|
2014-11-26 13:11:47 -07:00
|
|
|
def do_bay_list(cs, args):
|
2014-12-01 23:15:16 +05:30
|
|
|
"""Print a list of available bays."""
|
2014-11-26 13:11:47 -07:00
|
|
|
bays = cs.bays.list()
|
2014-12-16 23:20:43 -07:00
|
|
|
columns = ('uuid', 'name', 'node_count')
|
2014-11-26 13:11:47 -07:00
|
|
|
utils.print_list(bays, columns,
|
|
|
|
{'versions': _print_list_field('versions')})
|
|
|
|
|
|
|
|
|
|
|
|
@utils.arg('--name',
|
|
|
|
metavar='<name>',
|
|
|
|
help='Name of the bay to create.')
|
2014-12-17 16:08:03 -07:00
|
|
|
@utils.arg('--baymodel_id',
|
|
|
|
metavar='<baymodel_id>',
|
|
|
|
help='The bay model ID.')
|
2014-12-04 17:54:28 -07:00
|
|
|
@utils.arg('--node_count',
|
|
|
|
metavar='<node_count>',
|
|
|
|
help='The bay node count.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_bay_create(cs, args):
|
2014-11-26 13:11:47 -07:00
|
|
|
"""Create a bay."""
|
|
|
|
opts = {}
|
|
|
|
opts['name'] = args.name
|
2014-12-17 16:08:03 -07:00
|
|
|
opts['baymodel_id'] = args.baymodel_id
|
2014-12-04 17:54:28 -07:00
|
|
|
opts['node_count'] = args.node_count
|
2014-11-26 13:11:47 -07:00
|
|
|
|
|
|
|
bay = cs.bays.create(**opts)
|
2014-12-16 23:15:02 -07:00
|
|
|
_show_baymodel(bay)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-11-26 13:11:47 -07:00
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the bay to delete.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_bay_delete(cs, args):
|
2014-11-26 13:11:47 -07:00
|
|
|
"""Delete a bay."""
|
2014-12-01 10:34:18 -07:00
|
|
|
cs.bays.delete(args.id)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-12-01 23:34:34 +05:30
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the bay to show.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_bay_show(cs, args):
|
2014-12-01 23:34:34 +05:30
|
|
|
bay = cs.bays.get(args.id)
|
|
|
|
_show_bay(bay)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-12-15 12:57:54 -07:00
|
|
|
@utils.arg('--name',
|
|
|
|
metavar='<name>',
|
|
|
|
help='Name of the bay to create.')
|
|
|
|
@utils.arg('--image_id',
|
|
|
|
metavar='<image_id>',
|
|
|
|
help='The name or UUID of the base image to customize for the bay.')
|
|
|
|
@utils.arg('--keypair_id',
|
|
|
|
metavar='<keypair_id>',
|
|
|
|
help='The name or UUID of the SSH keypair to load into the'
|
|
|
|
' Bay nodes.')
|
|
|
|
@utils.arg('--external_network_id',
|
|
|
|
metavar='<external_network_id>',
|
|
|
|
help='The external Neutron network ID to connect to this bay'
|
|
|
|
' model.')
|
|
|
|
@utils.arg('--dns_nameserver',
|
|
|
|
metavar='<dns_nameserver>',
|
|
|
|
help='The DNS nameserver to use for this Bay.')
|
2014-12-17 15:45:04 -07:00
|
|
|
@utils.arg('--flavor_id',
|
|
|
|
metavar='<flavor_id>',
|
|
|
|
help='The nova flavor id to use when launching the bay.')
|
2014-12-15 12:57:54 -07:00
|
|
|
def do_baymodel_create(cs, args):
|
|
|
|
"""Create a bay."""
|
|
|
|
opts = {}
|
|
|
|
opts['name'] = args.name
|
2014-12-17 15:45:04 -07:00
|
|
|
opts['flavor_id'] = args.flavor_id
|
2014-12-15 12:57:54 -07:00
|
|
|
opts['image_id'] = args.image_id
|
|
|
|
opts['keypair_id'] = args.keypair_id
|
|
|
|
opts['external_network_id'] = args.external_network_id
|
|
|
|
opts['dns_nameserver'] = args.dns_nameserver
|
|
|
|
|
|
|
|
bay = cs.baymodels.create(**opts)
|
|
|
|
_show_baymodel(bay)
|
|
|
|
|
|
|
|
|
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the bay to delete.')
|
|
|
|
def do_baymodel_delete(cs, args):
|
|
|
|
"""Delete a bay."""
|
|
|
|
cs.baymodels.delete(args.id)
|
|
|
|
|
|
|
|
|
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the bay to show.')
|
|
|
|
def do_baymodel_show(cs, args):
|
|
|
|
baymodel = cs.baymodels.get(args.id)
|
2014-12-16 23:15:02 -07:00
|
|
|
_show_baymodel(baymodel)
|
2014-12-15 12:57:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
def do_baymodel_list(cs, args):
|
|
|
|
"""Print a list of bay models."""
|
|
|
|
nodes = cs.baymodels.list()
|
2014-12-16 23:17:44 -07:00
|
|
|
columns = ('uuid', 'name')
|
2014-12-15 12:57:54 -07:00
|
|
|
utils.print_list(nodes, columns,
|
|
|
|
{'versions': _print_list_field('versions')})
|
|
|
|
|
|
|
|
|
2014-12-07 10:00:04 -07:00
|
|
|
def do_node_list(cs, args):
|
|
|
|
"""Print a list of configured nodes."""
|
|
|
|
nodes = cs.nodes.list()
|
|
|
|
columns = ('uuid', 'type', 'image_id')
|
|
|
|
utils.print_list(nodes, columns,
|
|
|
|
{'versions': _print_list_field('versions')})
|
|
|
|
|
|
|
|
|
|
|
|
@utils.arg('--type',
|
|
|
|
metavar='<type>',
|
|
|
|
help='Type of node to create (virt or bare).')
|
|
|
|
@utils.arg('--image_id',
|
|
|
|
metavar='<image_id>',
|
|
|
|
help='The name or UUID of the base image to use for the node.')
|
|
|
|
def do_node_create(cs, args):
|
|
|
|
"""Create a node."""
|
|
|
|
opts = {}
|
|
|
|
opts['type'] = args.type
|
|
|
|
opts['image_id'] = args.image_id
|
|
|
|
|
|
|
|
node = cs.nodes.create(**opts)
|
|
|
|
_show_node(node)
|
|
|
|
|
|
|
|
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_pod_list(cs, args):
|
2014-12-17 02:18:39 -07:00
|
|
|
"""Print a list of registered pods."""
|
|
|
|
pods = cs.pods.list()
|
|
|
|
columns = ('uuid', 'name')
|
|
|
|
utils.print_list(pods, columns,
|
|
|
|
{'versions': _print_list_field('versions')})
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-12-17 02:18:39 -07:00
|
|
|
@utils.arg('--name',
|
|
|
|
metavar='<name>',
|
|
|
|
help='Name of the pod to create.')
|
|
|
|
@utils.arg('--pod-file',
|
|
|
|
metavar='<pod-file>',
|
|
|
|
help='Name of the pod file to use for creating PODs.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_pod_create(cs, args):
|
2014-12-17 02:18:39 -07:00
|
|
|
"""Create a pod."""
|
|
|
|
opts = {}
|
|
|
|
opts['name'] = args.name
|
|
|
|
opts['pod_data'] = open(args.pod_file).read()
|
|
|
|
|
|
|
|
node = cs.pods.create(**opts)
|
|
|
|
_show_pod(node)
|
2014-11-20 20:02:08 -08:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-12-17 02:18:39 -07:00
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the pod to delete.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_pod_delete(cs, args):
|
2014-12-17 02:18:39 -07:00
|
|
|
"""Delete a pod."""
|
|
|
|
cs.pods.delete(args.id)
|
2014-11-20 20:02:08 -08:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-12-17 02:18:39 -07:00
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<bay_id>',
|
|
|
|
help='ID of the bay to show.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_pod_show(cs, args):
|
2014-12-17 02:18:39 -07:00
|
|
|
pod = cs.pods.get(args.id)
|
|
|
|
_show_pod(pod)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
def do_service_list(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_service_create(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_service_delete(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_service_show(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-11-26 12:47:22 +09:00
|
|
|
#
|
|
|
|
# Containers
|
|
|
|
# ~~~~~~~~~~
|
|
|
|
# container-create [--json <file>]
|
|
|
|
#
|
|
|
|
# container-list
|
|
|
|
#
|
|
|
|
# container-delete --id <container_id>
|
|
|
|
#
|
|
|
|
# container-show --id <container_id> [--json]
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-reboot
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-stop
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-start
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-pause
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-unpause
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-logs
|
|
|
|
#
|
|
|
|
# TODO(yuanying): container-execute
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
@utils.arg('--json',
|
|
|
|
default=sys.stdin,
|
|
|
|
type=argparse.FileType('r'),
|
|
|
|
help='JSON representation of container.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_container_create(cs, args):
|
2014-11-26 12:47:22 +09:00
|
|
|
"""Create a container."""
|
|
|
|
container = json.loads(args.json.read())
|
|
|
|
_show_container(cs.containers.create(**container))
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
def do_container_list(cs, args):
|
2014-11-26 12:47:22 +09:00
|
|
|
"""Print a list of available containers."""
|
|
|
|
containers = cs.containers.list()
|
2014-11-28 13:51:54 +09:00
|
|
|
columns = ('container_id', 'name', 'desc')
|
2014-11-26 12:47:22 +09:00
|
|
|
utils.print_list(containers, columns,
|
|
|
|
{'versions': _print_list_field('versions')})
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-11-26 12:47:22 +09:00
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<container_id>',
|
|
|
|
help='ID of the container to delete.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_container_delete(cs, args):
|
2014-12-01 23:15:16 +05:30
|
|
|
"""Delete a container."""
|
2014-11-26 12:47:22 +09:00
|
|
|
cs.containers.delete(args.id)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
2014-11-26 12:47:22 +09:00
|
|
|
@utils.arg('--id',
|
|
|
|
metavar='<container_id>',
|
|
|
|
help='ID of the container to show.')
|
|
|
|
@utils.arg('--json',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Print JSON representation of the container.')
|
2014-11-20 20:02:08 -08:00
|
|
|
def do_container_show(cs, args):
|
2014-11-26 12:47:22 +09:00
|
|
|
"""Show details of a container."""
|
|
|
|
container = cs.containers.get(args.id)
|
|
|
|
if args.json:
|
|
|
|
print(json.dumps(container._info))
|
|
|
|
else:
|
|
|
|
_show_container(container)
|
2014-11-20 20:02:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
def do_container_reboot(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_stop(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_start(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_pause(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_unpause(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_logs(cs, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def do_container_execute(cs, args):
|
|
|
|
pass
|