def do_boot(cs, args): """Boot a new server.""" boot_args, boot_kwargs = _boot(cs, args) extra_boot_kwargs = utils.get_resource_manager_extra_kwargs(do_boot, args) boot_kwargs.update(extra_boot_kwargs) server = cs.servers.create(*boot_args, **boot_kwargs) # Keep any information (like adminPass) returned by create info = server._info server = cs.servers.get(info['id']) info.update(server._info) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = _find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = _find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_network_create(cs, args): """ Create a network """ network = cs.os_networksv2_python_novaclient_ext.create( args.label, args.cidr) utils.print_dict(network._info)
def do_cell_capacities(cs, args): """Get cell capacities for all cells or a given cell.""" cell = cs.cells.capacities(args.cell) print(_("Ram Available: %s MB") % cell.capacities["ram_free"]["total_mb"]) utils.print_dict(cell.capacities["ram_free"]["units_by_mb"], dict_property="Ram(MB)", dict_value="Units") print(_("\nDisk Available: %s MB") % cell.capacities["disk_free"]["total_mb"]) utils.print_dict(cell.capacities["disk_free"]["units_by_mb"], dict_property="Disk(MB)", dict_value="Units")
def do_address_create(cs, args): """ Add a new address to an instance """ addresses = cs.os_addresses_python_novaclient_ext.create(args.network_id, args.instance_id) utils.print_dict(addresses._info)
def do_pci_show(cs, args): """Display the details of the specified pci .""" pci = _find_pci(cs, args.pci) # Build up the dict info = pci._info.copy() utils.print_dict(info)
def do_boot(cs, args): """Boot a new server.""" name, image, flavor, metadata, files, key_name, reservation_id, \ min_count, max_count, user_data, availability_zone, \ security_groups = _boot(cs, args) server = cs.servers.create(args.name, image, flavor, meta=metadata, files=files, min_count=min_count, max_count=max_count, userdata=user_data, availability_zone=availability_zone, security_groups=security_groups, key_name=key_name) # Keep any information (like adminPass) returned by create info = server._info server = cs.servers.get(info['id']) info.update(server._info) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = _find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = _find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_co_boot(cs, args): """Boot a new server.""" boot_args, boot_kwargs = shell._boot(cs, args) if args.host and 'meta' in boot_kwargs: boot_kwargs['meta'].update({"co:target_host": args.host}) elif args.host: boot_kwargs['meta'] = {"co:target_host":args.host} extra_boot_kwargs = utils.get_resource_manager_extra_kwargs(do_co_boot, args) boot_kwargs.update(extra_boot_kwargs) server = cs.cobalt.create(*boot_args, **boot_kwargs) # Keep any information (like adminPass) returned by create info = server._info server = cs.servers.get(info['id']) info.update(server._info) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = shell._find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = shell._find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info) if args.poll: shell._poll_for_status(cs.servers.get, info['id'], 'building', ['active'])
def do_ip_association(cs, args): """ Show an IP association """ ip_association = cs.ip_associations_python_novaclient_ext.get( args.instance_id, args.ip_association_id) utils.print_dict(ip_association._info)
def do_network_create(cs, args): """ Create a network """ network = cs.os_networksv2_python_novaclient_ext.create(args.label, args.cidr) utils.print_dict(network._info)
def _print_server(cs, server): # By default when searching via name we will do a # findall(name=blah) and due a REST /details which is not the same # as a .get() and doesn't get the information about flavors and # images. This fix it as we redo the call with the id which does a # .get() to get all informations. if not 'flavor' in server._info: server = _find_server(cs, server.id) networks = server.networks info = server._info.copy() for network_label, address_list in networks.items(): info['%s network' % network_label] = ', '.join(address_list) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = _find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = _find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_ip_association_create(cs, args): """ Create an IP association """ ip_association = cs.ip_associations_python_novaclient_ext.create( args.instance_id, args.ip_association_id) utils.print_dict(ip_association._info)
def do_boot(cs, args): """Boot a new server.""" name, image, flavor, metadata, files, reservation_id, \ min_count, max_count = _boot(cs, args) server = cs.servers.create(args.name, image, flavor, meta=metadata, files=files, min_count=min_count, max_count=max_count) info = server._info flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = _find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = _find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_ipgroup_create(cs, args): """Create a new IP group.""" if args.server: server = _find_server(cs, args.server) else: server = None group = cs.ipgroups.create(args.name, server) utils.print_dict(group._info)
def do_charge_payment_type_create(cs, args): """ Create a charge payment_type record """ payment_type = cs.charge_payment_types.create(args.payment_type_name, args.payment_type_interval_unit, args.payment_type_interval_size, args.payment_type_is_prepaid) utils.print_dict(payment_type._info)
def do_charge_product_create(cs, args): """ Create a charge product record """ product = cs.charge_products.create(args.product_name, args.product_interval_unit, args.product_interval_size, args.product_is_prepaid) utils.print_dict(product._info)
def do_instance_action(cs, args): """Show an action.""" server = utils.find_resource(cs.servers, args.server) action_resource = cs.instance_action.get(server, args.request_id) action = action_resource._info if 'events' in action: action['events'] = pprint.pformat(action['events']) utils.print_dict(action)
def do_cell_capacities(cs, args): """Get cell capacities for all cells or a given cell.""" cell = cs.cells.capacities(args.cell) print("Ram Available: %s MB" % cell.capacities['ram_free']['total_mb']) utils.print_dict(cell.capacities['ram_free']['units_by_mb'], dict_property='Ram(MB)', dict_value="Units") print("\nDisk Available: %s MB" % cell.capacities['disk_free']['total_mb']) utils.print_dict(cell.capacities['disk_free']['units_by_mb'], dict_property='Disk(MB)', dict_value="Units")
def test_print_dict_dictionary(self): dict = {'k': {'foo': 'bar'}} utils.print_dict(dict) self.assertEqual( sys.stdout.getvalue(), '+----------+----------------+\n' '| Property | Value |\n' '+----------+----------------+\n' '| k | {"foo": "bar"} |\n' '+----------+----------------+\n')
def test_print_dict_list(self): dict = {'k': ['foo', 'bar']} utils.print_dict(dict) self.assertEqual('+----------+----------------+\n' '| Property | Value |\n' '+----------+----------------+\n' '| k | ["foo", "bar"] |\n' '+----------+----------------+\n', sys.stdout.getvalue())
def test_print_dict_dictionary(self): dict = {'k': {'foo': 'bar'}} utils.print_dict(dict) self.assertEqual(sys.stdout.getvalue(), '+----------+----------------+\n' '| Property | Value |\n' '+----------+----------------+\n' '| k | {"foo": "bar"} |\n' '+----------+----------------+\n')
def test_print_dict_list_dictionary(self): dict = {'k': [{'foo': 'bar'}]} utils.print_dict(dict) self.assertEqual('+----------+------------------+\n' '| Property | Value |\n' '+----------+------------------+\n' '| k | [{"foo": "bar"}] |\n' '+----------+------------------+\n', sys.stdout.getvalue())
def test_print_dict(self): dict = {'key': 'value'} utils.print_dict(dict) self.assertEqual('+----------+-------+\n' '| Property | Value |\n' '+----------+-------+\n' '| key | value |\n' '+----------+-------+\n', sys.stdout.getvalue())
def test_print_unicode_dict(self): dict = {'k': '\u2026'} utils.print_dict(dict) s = '\u2026' self.assertEqual('+----------+-------+\n' '| Property | Value |\n' '+----------+-------+\n' '| k | %s |\n' '+----------+-------+\n' % s, sys.stdout.getvalue())
def test_print_dict(self): dict = {"key": "value"} utils.print_dict(dict) self.assertEqual( sys.stdout.getvalue(), "+----------+-------+\n" "| Property | Value |\n" "+----------+-------+\n" "| key | value |\n" "+----------+-------+\n", )
def do_boot_for_account(cs, args): """Boot a new server in an account.""" name, image, flavor, ipgroup, metadata, files, reservation_id, \ min_count, max_count = _boot(cs, args) server = cs.accounts.create_instance_for(args.account, args.name, image, flavor, ipgroup=ipgroup, meta=metadata, files=files) utils.print_dict(server._info)
def test_print_dict_wrap(self): dict = {'key1': 'not wrapped', 'key2': 'this will be wrapped'} utils.print_dict(dict, wrap=16) self.assertEqual( '+----------+--------------+\n' '| Property | Value |\n' '+----------+--------------+\n' '| key1 | not wrapped |\n' '| key2 | this will be |\n' '| | wrapped |\n' '+----------+--------------+\n', sys.stdout.getvalue())
def do_instance_action(cs, args): """Show an action.""" if cs.api_version < api_versions.APIVersion("2.21"): server = shell._find_server(cs, args.server) else: server = shell._find_server(cs, args.server, raise_if_notfound=False) action_resource = cs.instance_action.get(server, args.request_id) action = action_resource._info if 'events' in action: action['events'] = pprint.pformat(action['events']) utils.print_dict(action)
def do_boot(cs, args): """Boot a new server.""" name, image, flavor, metadata, files, reservation_id, \ min_count, max_count = _boot(cs, args) server = cs.servers.create(args.name, image, flavor, meta=metadata, files=files, min_count=min_count, max_count=max_count) utils.print_dict(server._info)
def test_print_dict_list(self): dict = {"k": ["foo", "bar"]} utils.print_dict(dict) self.assertEqual( sys.stdout.getvalue(), "+----------+----------------+\n" "| Property | Value |\n" "+----------+----------------+\n" '| k | ["foo", "bar"] |\n' "+----------+----------------+\n", )
def test_print_dict_dictionary(self): dict = {"k": {"foo": "bar"}} utils.print_dict(dict) self.assertEqual( sys.stdout.getvalue(), "+----------+----------------+\n" "| Property | Value |\n" "+----------+----------------+\n" '| k | {"foo": "bar"} |\n' "+----------+----------------+\n", )
def do_boot(cs, args): """Boot a new server.""" name, image, flavor, ipgroup, metadata, files, reservation_id, \ min_count, max_count = _boot(cs, args) server = cs.servers.create(args.name, image, flavor, ipgroup=ipgroup, meta=metadata, files=files, min_count=min_count, max_count=max_count) utils.print_dict(server._info)
def test_print_large_dict_list(self): dict = {'k': ['foo1', 'bar1', 'foo2', 'bar2', 'foo3', 'bar3', 'foo4', 'bar4']} utils.print_dict(dict, wrap=40) self.assertEqual( '+----------+------------------------------------------+\n' '| Property | Value |\n' '+----------+------------------------------------------+\n' '| k | ["foo1", "bar1", "foo2", "bar2", "foo3", |\n' '| | "bar3", "foo4", "bar4"] |\n' '+----------+------------------------------------------+\n', sys.stdout.getvalue())
def test_print_dict_wrap(self): dict = {'key1': 'not wrapped', 'key2': 'this will be wrapped'} utils.print_dict(dict, wrap=16) self.assertEqual('+----------+--------------+\n' '| Property | Value |\n' '+----------+--------------+\n' '| key1 | not wrapped |\n' '| key2 | this will be |\n' '| | wrapped |\n' '+----------+--------------+\n', sys.stdout.getvalue())
def test_print_unicode_dict(self): dict = {'k': u'\u2026'} utils.print_dict(dict) if six.PY3: s = u'\u2026' else: s = encodeutils.safe_encode(u'\u2026') self.assertEqual('+----------+-------+\n' '| Property | Value |\n' '+----------+-------+\n' '| k | %s |\n' '+----------+-------+\n' % s, sys.stdout.getvalue())
def do_virtual_interface_create(cs, args): """ Add a new virtual interface to an instance """ addresses = cs.os_virtual_interfacesv2_python_novaclient_ext.create( args.network_id, args.instance_id) for address in addresses: addr_list = [ip_dict_formatter(a) for a in address["ip_addresses"]] addr_dict = {"id": address["id"], "mac_address": address["mac_address"], "ip_addresses": ','.join(addr_list)} utils.print_dict(addr_dict)
def do_virtual_interface_create(cs, args): """ Add a new virtual interface to an instance """ addresses = cs.os_virtual_interfacesv2_python_novaclient_ext.create( args.network_id, args.instance_id) for address in addresses: addr_list = [ip_dict_formatter(a) for a in address["ip_addresses"]] addr_dict = { "id": address["id"], "mac_address": address["mac_address"], "ip_addresses": ','.join(addr_list) } utils.print_dict(addr_dict)
def do_show(cs, args): """Show details about the given server.""" s = _find_server(cs, args.server) info = s._info.copy() addresses = info.pop('addresses') for addrtype in addresses: info['%s ip' % addrtype] = ', '.join(addresses[addrtype]) flavorId = info.get('flavorId', None) if flavorId: info['flavor'] = _find_flavor(cs, info.pop('flavorId')).name imageId = info.get('imageId', None) if imageId: info['image'] = _find_image(cs, info.pop('imageId')).name utils.print_dict(info)
def do_zone(cs, args): """Show or edit a child zone. No zone arg for this zone.""" zone = cs.zones.get(args.zone) # If we have some flags, update the zone zone_delta = {} if args.api_url: zone_delta['api_url'] = args.api_url if args.zone_username: zone_delta['username'] = args.zone_username if args.zone_password: zone_delta['password'] = args.zone_password if args.weight_offset: zone_delta['weight_offset'] = args.weight_offset if args.weight_scale: zone_delta['weight_scale'] = args.weight_scale if zone_delta: zone.update(**zone_delta) else: utils.print_dict(zone._info)
def do_backup_schedule(cs, args): """ Show or edit the backup schedule for a server. With no flags, the backup schedule will be shown. If flags are given, the backup schedule will be modified accordingly. """ server = _find_server(cs, args.server) # If we have some flags, update the backup backup = {} if args.daily: backup['daily'] = getattr(backup_schedules, 'BACKUP_DAILY_%s' % args.daily.upper()) if args.weekly: backup['weekly'] = getattr(backup_schedules, 'BACKUP_WEEKLY_%s' % args.weekly.upper()) if args.enabled is not None: backup['enabled'] = args.enabled if backup: server.backup_schedule.update(**backup) else: utils.print_dict(server.backup_schedule._info)
def _print_image(image): info = image._info.copy() # ignore links, we don't need to present those info.pop('links') # try to replace a server entity to just an id server = info.pop('server', None) try: info['server'] = server['id'] except (KeyError, TypeError): pass # break up metadata and display each on its own row metadata = info.pop('metadata', {}) try: for key, value in metadata.items(): _key = 'metadata %s' % key info[_key] = value except AttributeError: pass utils.print_dict(info)
def do_boot(cs, args): """Boot a new server.""" name, image, flavor, metadata, files, key_name, reservation_id, \ min_count, max_count, user_data, availability_zone, \ security_groups, block_device_mapping, nics = _boot(cs, args) server = cs.servers.create(args.name, image, flavor, meta=metadata, files=files, min_count=min_count, max_count=max_count, userdata=user_data, availability_zone=availability_zone, security_groups=security_groups, key_name=key_name, block_device_mapping=block_device_mapping, nics=nics) # Keep any information (like adminPass) returned by create info = server._info server = cs.servers.get(info['id']) info.update(server._info) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = _find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = _find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_gc_boot(cs, args): """Boot a new server.""" boot_args, boot_kwargs = shell._boot(cs, args) if args.host and 'meta' in boot_kwargs: boot_kwargs['meta'].update({"gc:target_host": args.host}) elif args.host: boot_kwargs['meta'] = {"gc:target_host": args.host} extra_boot_kwargs = utils.get_resource_manager_extra_kwargs( do_gc_boot, args) boot_kwargs.update(extra_boot_kwargs) server = cs.gridcentric.create(*boot_args, **boot_kwargs) # Keep any information (like adminPass) returned by create info = server._info server = cs.servers.get(info['id']) info.update(server._info) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') info['flavor'] = shell._find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') info['image'] = shell._find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info) if args.poll: shell._poll_for_status(cs.servers.get, info['id'], 'building', ['active'])
def _print_server(cs, server, minimal=False): # (dscannell): Note that the follow method was taken from the # main novaclient code base. We duplicate it here to protect ourselves # changes in the method signatures between versions of the novaclient. # By default when searching via name we will do a # findall(name=blah) and due a REST /details which is not the same # as a .get() and doesn't get the information about flavors and # images. This fix it as we redo the call with the id which does a # .get() to get all informations. if not 'flavor' in server._info: server = shell._find_server(cs, server.id) networks = server.networks info = server._info.copy() for network_label, address_list in networks.items(): info['%s network' % network_label] = ', '.join(address_list) flavor = info.get('flavor', {}) flavor_id = flavor.get('id', '') if minimal: info['flavor'] = flavor_id else: info['flavor'] = shell._find_flavor(cs, flavor_id).name image = info.get('image', {}) image_id = image.get('id', '') if minimal: info['image'] = image_id else: info['image'] = shell._find_image(cs, image_id).name info.pop('links', None) info.pop('addresses', None) utils.print_dict(info)
def do_network(cs, args): """ Show a network """ network = cs.os_networksv2_python_novaclient_ext.get(args.network_id) utils.print_dict(network._info)
def do_zone_add(cs, args): """Add a new child zone.""" zone = cs.zones.create(args.zone_name, args.api_url, args.zone_username, args.zone_password, args.weight_offset, args.weight_scale) utils.print_dict(zone._info)