Exemplo n.º 1
0
def info(ctx, task_id):
    try:
        client = ctx.obj['client']
        result = client.get_resource('%s/task/%s' % (client._uri, task_id))
        stdout(task_to_dict(result), ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 2
0
def info(ctx, task_id):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        result = client.get_resource('%s/task/%s' % (client._uri, task_id))
        stdout(task_to_dict(result), ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 3
0
def info(ctx, task_id):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        result = client.get_resource(f"{client.get_api_uri()}/task/{task_id}")
        stdout(task_to_dict(result), ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
Exemplo n.º 4
0
    def add_vm(self):
        params = self.params
        source_vapp_resource = self.get_source_resource()
        target_vm_name = params.get('target_vm_name')
        hostname = params.get('hostname')
        source_vm_name = params.get('source_vm_name')
        target_vapp = params.get('target_vapp')
        vmpassword = params.get('vmpassword')
        vmpassword_auto = params.get('vmpassword_auto')
        vmpassword_reset = params.get('vmpassword_reset')
        network = params.get('network')
        power_on = params.get('power_on')
        ip_allocation_mode = params.get('ip_allocation_mode')
        cust_script = params.get('cust_script')
        storage_profile_name = params.get('storage_profile')
        storage_profile = None
        all_eulas_accepted = params.get('all_eulas_accepted')
        response = dict()
        response['msg'] = dict()
        response['changed'] = False

        if storage_profile_name:
            storage_profile = self.get_storage_profile(storage_profile_name)

        try:
            self.vdc.get_vapp(target_vapp)
        except EntityNotFoundException:
            spec = {
                'source_vm_name': source_vm_name,
                'vapp': source_vapp_resource,
                'target_vm_name': target_vm_name,
                'hostname': hostname,
                'password': vmpassword,
                'password_auto': vmpassword_auto,
                'password_reset': vmpassword_reset,
                'ip_allocation_mode': ip_allocation_mode,
                'network': network,
                'cust_script': cust_script,
                'storage_profile': storage_profile,
                'power_on': power_on
            }

            params = self.to_instantiate_vm_template_params(spec)

            if all_eulas_accepted is not None:
                params.append(E.AllEULAsAccepted(all_eulas_accepted))

            add_vms_task = self.client.post_linked_resource(
                self.vdc.resource, RelationType.ADD,
                'application/vnd.vmware.vcloud.instantiateVmTemplateParams+xml',
                params)
            result = self.execute_task(add_vms_task)
            result = task_to_dict(result)
            if isinstance(result.get('details'), StringElement):
                del result['details']
            response['msg'].update(result)
            response['changed'] = True

        else:
            response['warnings'] = "Vapp {} is already present.".format(
                target_vapp)

        return response