def start_vm(template_id, tag, count, node): from management_api import ManagementApi from management_api import NotFoundException mgmt_api = ManagementApi(host) new_ids = None try: new_ids = mgmt_api.start_vm(template_id, count, tag=tag, node=node) except NotFoundException: template_id_from_list = mgmt_api.search_template_by_name(template_id) if template_id_from_list: new_ids = mgmt_api.start_vm(template_id_from_list, count, tag=tag, node=node) else: click.echo("Template not found") exit(-1) if new_ids: click.echo("\nvms created") vms_created = [] for new_id in new_ids: vm_info = mgmt_api.show_vm(new_id) info_to_show = { 'id': new_id, 'state': vm_info.get('instance_state') } vms_created.append(info_to_show) from formatter import Formatter formatter = Formatter() click.echo(formatter.format_list_of_dicts(vms_created)) else: click.echo("\ncreate failed")
def show_vm(vm_id): from management_api import ManagementApi from management_api import NotFoundException mgmt_api = ManagementApi(host) try: vm = mgmt_api.show_vm(vm_id) except NotFoundException: click.echo("vm not found") exit(-1) click.echo("\nshowing vm %s\n" % vm_id) from formatter import Formatter formatter = Formatter() click.echo(formatter.format_dict(vm))