예제 #1
0
def create(ctx, name, size, description, storage_profile, iops):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disk_resource = vdc.create_disk(name=name,
                                        size=humanfriendly.parse_size(size),
                                        description=description,
                                        storage_profile_name=storage_profile,
                                        iops=iops)
        stdout(disk_resource.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
예제 #2
0
파일: disk.py 프로젝트: vmware/vca-cli
def create(ctx, name, size, description, storage_profile, iops):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disk_resource = vdc.create_disk(
            name=name,
            size=humanfriendly.parse_size(size),
            description=description,
            storage_profile_name=storage_profile,
            iops=iops)
        stdout(disk_resource.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
예제 #3
0
    def test_010_create_disk(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)

        result = vdc.create_disk(
            name=self.config['vcd']['idisk_name'],
            size=self.config['vcd']['idisk_size'],
            description=self.config['vcd']['idisk_description'])

        task = self.client.get_task_monitor().wait_for_status(
            task=result.Tasks.Task[0],
            timeout=30,
            poll_frequency=2,
            fail_on_status=None,
            expected_target_statuses=[
                TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                TaskStatus.CANCELED
            ],
            callback=None)

        assert task.get('status') == TaskStatus.SUCCESS.value
예제 #4
0
    def test_010_create_disk(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)

        result = vdc.create_disk(
            name=self.config['vcd']['idisk_name'],
            size=self.config['vcd']['idisk_size'],
            description=self.config['vcd']['idisk_description'])

        task = self.client.get_task_monitor().wait_for_status(
            task=result.Tasks.Task[0],
            timeout=30,
            poll_frequency=2,
            fail_on_status=None,
            expected_target_statuses=[
                TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                TaskStatus.CANCELED
            ],
            callback=None)

        assert task.get('status') == TaskStatus.SUCCESS.value
예제 #5
0
class Disk(VcdAnsibleModule):
    def __init__(self, **kwargs):
        super(Disk, self).__init__(**kwargs)
        logged_in_org = self.client.get_org()
        self.org = Org(self.client, resource=logged_in_org)
        vdc = self.org.get_vdc(self.params.get('vdc'))
        self.vdc = VDC(self.client, href=vdc.get('href'))

    def manage_states(self):
        state = self.params.get('state')
        if state == 'present':
            return self.create()

        if state == 'absent':
            return self.delete()

        if state == 'update':
            return self.update()

    def create(self):
        disk_name = self.params.get('disk_name')
        disk_id = self.params.get('disk_id')
        size = self.params.get('size')
        description = self.params.get('description')
        storage_profile = self.params.get('storage_profile')
        bus_type = self.params.get('bus_type')
        bus_sub_type = self.params.get('bus_sub_type')
        iops = self.params.get('iops')
        response = dict()
        response['changed'] = False

        try:
            self.vdc.get_disk(name=disk_name, disk_id=disk_id)
        except EntityNotFoundException:
            create_disk_task = self.vdc.create_disk(
                name=disk_name,
                size=size,
                bus_type=bus_type,
                bus_sub_type=bus_sub_type,
                description=description,
                iops=iops,
                storage_profile_name=storage_profile)
            self.execute_task(create_disk_task.Tasks.Task[0])
            response['msg'] = 'Disk {} has been created.'.format(disk_name)
            response['changed'] = True
        else:
            response['msg'] = "Disk {} is already present.".format(disk_name)

        return response

    def update(self):
        disk_name = self.params.get('disk_name')
        disk_id = self.params.get('disk_id')
        new_disk_name = self.params.get('new_disk_name')
        new_size = self.params.get('new_size')
        new_description = self.params.get('new_description')
        new_storage_profile = self.params.get('new_storage_profile')
        new_iops = self.params.get('new_iops')
        response = dict()
        response['changed'] = False

        update_disk_task = self.vdc.update_disk(
            name=disk_name,
            disk_id=disk_id,
            new_name=new_disk_name,
            new_size=new_size,
            new_iops=new_iops,
            new_description=new_description,
            new_storage_profile_name=new_storage_profile)
        self.execute_task(update_disk_task)
        response['msg'] = 'Disk {} has been updated.'.format(disk_name)
        response['changed'] = True

        return response

    def delete(self):
        disk_name = self.params.get('disk_name')
        disk_id = self.params.get('disk_id')
        response = dict()
        response['changed'] = False

        try:
            self.vdc.get_disk(name=disk_name, disk_id=disk_id)
        except EntityNotFoundException:
            response['msg'] = "Disk {} is not present.".format(disk_name)
        else:
            delete_disk_task = self.vdc.delete_disk(name=disk_name,
                                                    disk_id=disk_id)
            self.execute_task(delete_disk_task)
            response['msg'] = 'Disk {} has been deleted.'.format(disk_name)
            response['changed'] = True

        return response