def do_server_detach_network(client, args): """ Detach the virtual network fron a virtual server """ kwargs = {'net_id': args.net} if args.reserve: kwargs['reserve'] = True guest = client.guests.perform_action(args.id, 'detachnetwork', **kwargs) utils.print_dict(guest)
def do_server_change_bandwidth(client, args): """ Change server network bandwidth in Mbps """ guest = client.guests.perform_action(args.id, 'change-bandwidth', index=args.index, bandwidth=args.bw) utils.print_dict(guest)
def do_server_send_keys(client, args): """ Show monitor info of a virtual server """ guest = client.guests.perform_action(args.id, 'sendkeys', keys=args.keys, duration=args.hold) utils.print_dict(guest)
def do_server_show(client, args): """ Show a virtual server """ kwargs = {} if args.with_meta: kwargs['with_meta'] = True guest = client.guests.get(args.id, **kwargs) utils.print_dict(guest)
def do_baremetal_update(client, args): """ Update baremetal """ kwargs = {} if args.name: kwargs['name'] = args.name if args.desc: kwargs['description'] = args.desc if args.ncpu: kwargs['cpu_count'] = args.ncpu if args.ncpu_nodes: kwargs['node_count'] = args.ncpu_nodes if args.cpu_mhz: kwargs['cpu_mhz'] = args.cpu_mhz if args.cpu_desc: kwargs['cpu_desc'] = args.cpu_desc if args.cpu_cache_size: kwargs['cpu_cache'] = args.cpu_cache_size if args.mem_size: kwargs['mem_size'] = args.mem_size if args.rack: kwargs['rack'] = args.rack if args.slots: kwargs['slots'] = args.slots if args.ipmi_ip: kwargs['ipmi_ip_addr'] = args.ipmi_ip # if args.ipmi_username: # kwargs['ipmi_username'] = args.ipmi_username if args.ipmi_password: kwargs['ipmi_password'] = args.ipmi_password baremetal = client.baremetals.update(args.id, **kwargs) utils.print_dict(baremetal)
def do_network_update(client, args): """ Update a virtual network """ kwargs = {} if args.name is not None: kwargs['name'] = args.name if args.start_ip is not None: kwargs['guest_ip_start'] = args.start_ip if args.end_ip is not None: kwargs['guest_ip_end'] = args.end_ip if args.netmask is not None: kwargs['guest_ip_mask'] = args.netmask if args.desc is not None: kwargs['description'] = args.desc if args.gateway is not None: kwargs['guest_gateway'] = args.gateway if args.dns is not None: kwargs['guest_dns'] = args.dns if args.dhcp is not None: kwargs['guest_dhcp'] = args.dhcp if args.domain is not None: kwargs['guest_domain'] = args.domain #if args.vlan is not None: # kwargs['vlan_id'] = args.vlan if len(kwargs) == 0: raise Exception("Empty data", "empty data") net = client.networks.update(args.id, **kwargs) utils.print_dict(net)
def do_server_restore_snapshot(client, args): """ Restore snapshot """ kwargs = {} if args.timestamp: kwargs['timestamp'] = args.timestamp guest = client.guests.perform_action(args.id, 'restore-snapshot', **kwargs) utils.print_dict(guest)
def do_secgroup_set_rules(client, args): """ Set security rules from a security group """ kwargs = parse_secgroup_rules(args) if len(kwargs) == 0: raise Exception('No rule to set') sg = client.secgroups.perform_action(args.id, 'set-rules', **kwargs) utils.print_dict(sg)
def do_endpoint_create(client, args): """ register a service endpoint in a region """ s = client.services.get_by_id_or_name(args.service) try: client.endpoints.get_service_endpoint_in_region( s['id'], args.region, args.zone) raise Exception('Service "%s" has an endpoint in region "%s/%s"' % (s['name'], args.region, args.zone)) except exceptions.NotFound: pass kwargs = {} if args.zone is not None: kwargs['region'] = '%s/%s' % (args.region, args.zone) else: kwargs['region'] = args.region kwargs['service_id'] = s['id'] kwargs['publicurl'] = args.url if args.internal_url: kwargs['internalurl'] = args.internal_url else: kwargs['internalurl'] = args.url if args.admin_url: kwargs['adminurl'] = args.admin_url else: kwargs['adminurl'] = args.url endpoint = client.endpoints.create(**kwargs) utils.print_dict(endpoint)
def do_docker_image_upload(client, args): """ upload docker image from bottom to top, print_dict the top image info """ from yunionclient.api import glanceutils import subprocess (layers, tmp_file) = glanceutils.get_image_layers(args.file) image = None for layer in reversed(layers): # layer format {'id': <layer-id>, 'pid': <layer's parent id>, # 'file': <path of the tar>, 'name': <name of image, if exists>} image = client.images.get_image_by_docker_id(layer['id']) if len(image) == 1: #print 'got same image on glance, skip to continue' continue kwargs = {} kwargs['docker_id'] = layer['id'] kwargs['docker_parent_id'] = layer['pid'] if layer == layers[0]: # if it's the top layer, use the specified name cover the layer's original name layer['name'] = args.name if args.tag: # if has tag, assign to it kwargs['tag'] = args.tag image = client.images.upload(layer['file'], layer['name'], 'docker', args.public, kwargs) subprocess.check_call(['sudo', 'rm', '-rf', tmp_file]) utils.print_dict(image)
def do_instance_price(client, args): """ get price of an instance """ from yunionclient.api.price_infos import InstanceSpec spec = InstanceSpec(args.brand, args.region, args.zone, args.instance_type, args.disk_type, args.disk_size_gb) info = client.price_infos.get_price(spec.get_specs()) utils.print_dict(info)
def do_dns_remove_records(client, args): """ Remove DNS records from a domain name """ kwargs = parse_dns_arguments(args) if len(kwargs) == 0: raise Exception('No records to remove') dns = client.dns.perform_action(args.id, 'remove-records', **kwargs) utils.print_dict(dns)
def do_dns_add_records(client, args): """ Add DNS records to a dns name """ kwargs = parse_dns_arguments(args) if len(kwargs) == 0: raise Exception('No record to add') dns = client.dns.perform_action(args.id, 'add-records', **kwargs) utils.print_dict(dns)
def do_notifycontact_verify_channel(client, args): params = { 'channel': args.channel, 'token': args.token } nc = client.notifycontacts.perform_action(args.id, 'verify_channel', **params) utils.print_dict(nc)
def do_server_set_apptags(client, args): """ Set Application Tags like cpu_bound/io_bound used in scheduler """ kwargs = {} kwargs['tags'] = args.tags guest = client.guests.perform_action(args.id, 'set_apptags', **kwargs) utils.print_dict(guest)
def do_disk_change_owner(client, args): """ Show details of a virtual disk """ kwargs = {} kwargs['tenant'] = args.tenant kwargs['user'] = args.user disk = client.disks.perform_action(args.id, 'change-owner', **kwargs) utils.print_dict(disk)
def do_server_io_throttle(client, args): """ Do io throttle for a virtual server """ guest = client.guests.perform_action(args.id, 'io-throttle', throughput=args.throughput, iops=args.iops) utils.print_dict(guest)
def do_secgroup_add_rules(client, args): """ Add security rules to a security group """ kwargs = parse_secgroup_rules(args) if len(kwargs) == 0: raise Exception('No rule to add') sg = client.secgroups.perform_action(args.id, 'add-rules', **kwargs) utils.print_dict(sg)
def do_server_start(client, args): """ Start a virtual server """ kwargs = {} if args.qemu_version: kwargs['qemu_version'] = args.qemu_version guest = client.guests.perform_action(args.id, 'start', **kwargs) utils.print_dict(guest)
def do_baremetal_maintenance(client, args): """ Put a baremetal into maintenance mode """ kwargs = {} if args.force_reboot: kwargs['force_reboot'] = True obj = client.baremetals.perform_action(args.id, 'maintenance', **kwargs) utils.print_dict(obj)
def do_server_change_owner(client, args): """ Change owner of a virtual server """ kwargs = {} kwargs['tenant'] = args.tenant kwargs['user'] = args.user guest = client.guests.perform_action(args.id, 'change-owner', **kwargs) utils.print_dict(guest)
def do_group_create(client, args): """ Create a guest group (VM cluster) """ kwargs = {} kwargs['name'] = args.name if args.desc is not None: kwargs['description'] = args.desc if args.service_type is not None: kwargs['service_type'] = args.service_type if args.parent is not None: kwargs['parent'] = args.parent if args.zone: kwargs['zone'] = args.zone if args.tenant: kwargs['tenant'] = args.tenant if args.user: kwargs['user'] = args.user if args.scheduler_hint_memory: kwargs['sched_hint_memory'] = args.scheduler_hint_memory if args.scheduler_hint_exit_network: kwargs['sched_hint_exit_network'] = True if args.scheduler_hint_max_count: kwargs['sched_hint_max_count'] = args.scheduler_hint_max_count if args.scheduler_hint_disk_size: kwargs['sched_hint_disk_size'] = args.scheduler_hint_disk_size if args.system: kwargs['is_system'] = True if args.sched_strategy: kwargs['sched_strategy'] = args.sched_strategy group = client.groups.create(**kwargs) utils.print_dict(group)
def do_notifycontact_request_verify(client, args): params = { 'channel': args.channel, 'address': args.address, } nc = client.notifycontacts.perform_action(args.id, 'request_verify', **params) utils.print_dict(nc)
def do_group_eip_add(client, args): """ Request an EIP to the virtual network of a virtual group """ kwargs = {} if args.eip: kwargs['eip'] = args.eip group = client.groups.perform_action(args.id, 'addeip', **kwargs) utils.print_dict(group)
def do_group_eip_remove(client, args): """ Remove all or specified EIPs from a virtual group """ kwargs = {} if args.eip: kwargs['eip'] = args.eip group = client.groups.perform_action(args.id, 'deleip', **kwargs) utils.print_dict(group)
def do_template_update(client, args): """ Update a tempalte """ kwargs = {} if args.name: kwargs['name'] = args.name if args.title: kwargs['title'] = args.title if args.body: if os.path.exists(args.body): with open(args.body) as f: kwargs['body'] = f.read() else: kwargs['body'] = args.body if args.signature: kwargs['body'] += args.signature if args.desc: kwargs['description'] = args.desc if args.enable and not args.disable: kwargs['enabled'] = True elif not args.enable and args.disable: kwargs['enabled'] = False if len(kwargs) == 0: raise Exception('No data to update') temp = client.notify_templates.update(args.id, **kwargs) utils.print_dict(temp)
def do_wire_create_network(client, args): """ Create a virtual network over a wire """ kwargs = {} kwargs['name'] = args.name kwargs['guest_ip_start'] = args.start_ip kwargs['guest_ip_end'] = args.end_ip kwargs['guest_ip_mask'] = args.netmask #kwargs['wire_id'] = args.id if args.desc is not None: kwargs['description'] = args.desc if args.gateway is not None: kwargs['guest_gateway'] = args.gateway if args.dns is not None: kwargs['guest_dns'] = args.dns if args.dhcp is not None: kwargs['guest_dhcp'] = args.dhcp if args.domain is not None: kwargs['guest_domain'] = args.domain if args.type: kwargs['server_type'] = args.type #if args.vlan is not None: # kwargs['vlan_id'] = args.vlan net = client.wires.create_descendent( args.id, yunionclient.api.networks.NetworkManager, **kwargs) utils.print_dict(net)
def do_network_reserve_ip(client, args): """ Reserve an IP address from pool """ kwargs = {'ip': args.ip} if args.notes: kwargs['notes'] = args.notes net = client.networks.perform_action(args.id, 'reserve-ip', **kwargs) utils.print_dict(net)
def do_server_join_group(client, args): """ Join a virtual server into a group """ if args.tag and len(args.tag) > 0: tag = args.tag else: tag = None groupguest = client.groupguests.attach(args.group, args.id, tag=tag) utils.print_dict(groupguest)
def do_network_add_dns_update_target(client, args): """ Add a dns update target to a network """ kwargs = {'server': args.dns} kwargs['key'] = args.key kwargs['secret'] = args.secret net = client.networks.perform_action(args.id, 'add-dns-update-target', **kwargs) utils.print_dict(net)