Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
def do_zone_info(cs, args):
    """Get this zones name and capabilities."""
    zone = cs.zones.info()
    utils.print_dict(zone._info)
Example #11
0
def do_diagnostics(cs, args):
    """Retrieve server diagnostics."""
    utils.print_dict(cs.servers.diagnostics(args.server)[1])
Example #12
0
def do_ipgroup_show(cs, args):
    """Show details about a particular IP group."""
    group = _find_ipgroup(cs, args.group)
    utils.print_dict(group._info)
Example #13
0
def do_image_create(cs, args):
    """Create a new image by taking a snapshot of a running server."""
    server = _find_server(cs, args.server)
    image = cs.images.create(server, args.name)
    utils.print_dict(image._info)
Example #14
0
def _print_volume_snapshot(cs, snapshot):
    utils.print_dict(snapshot._info)
Example #15
0
def _print_volume(cs, volume):
    utils.print_dict(volume._info)
Example #16
0
def _print_image(image):
    links = image.links
    info = image._info.copy()
    info.pop('links')
    utils.print_dict(info)