예제 #1
0
파일: disk.py 프로젝트: vmware/vca-cli
def list_disks(ctx):
    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)
        disks = vdc.get_disks()
        result = []
        for disk in disks:
            attached_vms = ''
            if hasattr(disk, 'attached_vms') and \
               hasattr(disk.attached_vms, 'VmReference'):
                attached_vms = disk.attached_vms.VmReference.get('name')
            result.append({
                'name':
                disk.get('name'),
                'id':
                extract_id(disk.get('id')),
                'owner':
                disk.Owner.User.get('name'),
                'size':
                humanfriendly.format_size(int(disk.get('size'))),
                'size_bytes':
                disk.get('size'),
                'status':
                VCLOUD_STATUS_MAP.get(int(disk.get('status'))),
                'vms_attached':
                attached_vms
            })
        stdout(result, ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
예제 #2
0
    def test_008_delete_all_disks(self):

        logged_in_org = self.client.get_org()

        org = Org(self.client, resource=logged_in_org)
        v = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, href=v.get('href'))

        disks = vdc.get_disks()

        for disk in disks:
            print(("Deleting disk: " + disk.get('id')))
            taskObj = vdc.delete_disk(None, disk.get('id'))
            print(("Deleted VDC disk: " +
                   str(etree.tostring(taskObj, pretty_print=True), "utf-8")))

            #print("VDC Disk: " + str(disk))

            task = self.client.get_task_monitor().wait_for_status(
                task=taskObj,
                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
예제 #3
0
def list_disks(ctx):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disks = vdc.get_disks()
        result = []
        for disk in disks:
            attached_vms = ''
            if hasattr(disk, 'attached_vms') and \
               hasattr(disk.attached_vms, 'VmReference'):
                attached_vms = disk.attached_vms.VmReference.get('name')
            result.append({
                'name':
                disk.get('name'),
                'id':
                extract_id(disk.get('id')),
                'owner':
                disk.Owner.User.get('name'),
                'size':
                humanfriendly.format_size(int(disk.get('size'))),
                'size_bytes':
                disk.get('size'),
                'status':
                VCLOUD_STATUS_MAP.get(int(disk.get('status'))),
                'vms_attached':
                attached_vms
            })
        stdout(result, ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
def delete_disks(client):
    logging.info('INIT create_disk')

    logged_in_org = client.get_org()
    org = Org(client, resource=logged_in_org)
    v = org.get_vdc('OVD2')
    if v is None:
        raise errors.VDCNotFoundError(vappInfo.vdc)
    vdc = VDC(client, href=v.get('href'))
    disks = vdc.get_disks()

    print(etree.tostring(disks[0], pretty_print=True))
    #logging.info(disks[].get('href'))
    result = vdc.delete_disk('disk02')
    task = client.get_task_monitor().wait_for_status(
        task=result,
        timeout=60,
        poll_frequency=2,
        fail_on_status=None,
        expected_target_statuses=[
            TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
            TaskStatus.CANCELED
        ],
        callback=task_callback)
    st = task.get('status')
    if st == TaskStatus.SUCCESS.value:
        logging.info("__LOG__ created DISK")
        #cresult.created = True
    else:
        raise errors.VCDDiskDeletionError(
            etree.tostring(task, pretty_print=True))
def delete_disks(client):
    logging.info('INIT create_disk')

    logged_in_org = client.get_org()
    org = Org(client, resource=logged_in_org)
    v = org.get_vdc('OVD2')
    if v is None:
        raise errors.VDCNotFoundError(vappInfo.vdc)
    vdc = VDC(client, href=v.get('href'))
    disks = vdc.get_disks()

    print(etree.tostring(disks[0], pretty_print=True))
    #logging.info(disks[].get('href'))
    result = vdc.delete_disk('disk02')
    task = client.get_task_monitor().wait_for_status(task=result,
                                                     timeout=60,
                                                     poll_frequency=2,
                                                     fail_on_status=None,
                                                     expected_target_statuses=[
                                                         TaskStatus.SUCCESS,
                                                         TaskStatus.ABORTED,
                                                         TaskStatus.ERROR,
                                                         TaskStatus.CANCELED
                                                     ],
                                                     callback=task_callback)
    st = task.get('status')
    if st == TaskStatus.SUCCESS.value:
        logging.info("__LOG__ created DISK")
        #cresult.created = True
    else:
        raise errors.VCDDiskDeletionError(
            etree.tostring(task, pretty_print=True))
예제 #6
0
    def test_020_get_all_disks(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)

        disks = vdc.get_disks()

        assert len(disks) > 0
        assert disks[0].get('name') == self.config['vcd']['idisk_name']
예제 #7
0
    def test_020_get_all_disks(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)

        disks = vdc.get_disks()

        assert len(disks) > 0
        assert disks[0].get('name') == self.config['vcd']['idisk_name']
예제 #8
0
    def test_040_get_disk_by_id(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)

        disks = vdc.get_disks()
        assert len(disks) > 0

        fetched_disk = vdc.get_disk(disk_id=disks[0].get('id'))
        assert fetched_disk is not None
예제 #9
0
    def test_040_get_disk_by_id(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)

        disks = vdc.get_disks()
        assert len(disks) > 0

        fetched_disk = vdc.get_disk(disk_id=disks[0].get('id'))
        assert fetched_disk is not None
예제 #10
0
    def test_008_get_disk_by_id(self):

        logged_in_org = self.client.get_org()

        org = Org(self.client, resource=logged_in_org)
        v = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, href=v.get('href'))

        disks = vdc.get_disks()
        assert len(disks) > 0

        # get first disk using id
        fetched_disk = vdc.get_disk(None, disks[0].get('id'))
        assert fetched_disk is not None
예제 #11
0
    def test_008_get_disks(self):

        logged_in_org = self.client.get_org()
       
        org = Org(self.client, resource=logged_in_org)
        v = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, href=v.get('href'))
        
        disks = vdc.get_disks()
        
        for disk in disks:
            print (" Disk: " + str(etree.tostring(disk, pretty_print=True), "utf-8"))

        assert len(disks) > 0 

        assert disks[0].get('name') == self.config['vcd']['disk']
예제 #12
0
파일: disk.py 프로젝트: cosmotron/vcd-cli
def list_disks(ctx):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disks = vdc.get_disks()
        result = []
        for disk in disks:
            result.append({
                'name':
                disk.get('name'),
                'id':
                extract_id(disk.get('id')),
                'size_MB':
                disk.get('size'),
                'status':
                VCLOUD_STATUS_MAP.get(int(disk.get('status')))
            })
        stdout(result, ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
예제 #13
0
    def test_200_delete_all_disks(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)

        disks = vdc.get_disks()

        for disk in disks:
            result = vdc.delete_disk(disk_id=disk.get('id'))

            task = self.client.get_task_monitor().wait_for_status(
                task=result,
                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
예제 #14
0
    def test_200_delete_all_disks(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)

        disks = vdc.get_disks()

        for disk in disks:
            result = vdc.delete_disk(disk_id=disk.get('id'))

            task = self.client.get_task_monitor().wait_for_status(
                task=result,
                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