Exemple #1
0
 def test_03_get_vdc_access(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)
     control_access = vdc.get_access_settings()
     assert len(control_access.AccessSettings.AccessSetting) == 2
Exemple #2
0
 def test_03_get_vdc_access(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)
     control_access = vdc.get_access_settings()
     assert len(control_access.AccessSettings.AccessSetting) == 2
Exemple #3
0
def list_acl(ctx, vdc_name):
    try:
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        vdc_resource = org.get_vdc(vdc_name)
        vdc = VDC(client, resource=vdc_resource)

        acl = vdc.get_access_settings()
        stdout(access_settings_to_list(acl,
                                       ctx.obj['profiles'].get('org_in_use')),
               ctx,
               sort_headers=False)
    except Exception as e:
        stderr(e, ctx)
Exemple #4
0
def list_acl(ctx, vdc_name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        vdc_resource = org.get_vdc(vdc_name)
        vdc = VDC(client, resource=vdc_resource)

        acl = vdc.get_access_settings()
        stdout(
            access_settings_to_list(acl,
                                    ctx.obj['profiles'].get('org_in_use')),
            ctx)
    except Exception as e:
        stderr(e, ctx)
Exemple #5
0
def info(ctx, name):
    try:
        client = ctx.obj['client']
        in_use_org_name = ctx.obj['profiles'].get('org_in_use')
        in_use_vdc = ctx.obj['profiles'].get('vdc_in_use')
        org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, href=org_href)
        vdc_resource = org.get_vdc(name)
        vdc = VDC(client, resource=vdc_resource)
        access_settings = None
        try:
            access_settings = vdc.get_access_settings()
        except MissingLinkException:
            pass
        result = vdc_to_dict(vdc_resource,
                             access_settings_to_dict(access_settings))
        result['in_use'] = in_use_vdc == name
        result['org'] = in_use_org_name
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Exemple #6
0
def info(ctx, name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        in_use_org_name = ctx.obj['profiles'].get('org_in_use')
        in_use_vdc = ctx.obj['profiles'].get('vdc_in_use')
        org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, href=org_href)
        vdc_resource = org.get_vdc(name)
        vdc = VDC(client, resource=vdc_resource)
        access_settings = None
        try:
            access_settings = vdc.get_access_settings()
        except OperationNotSupportedException:
            pass
        result = vdc_to_dict(vdc_resource,
                             access_settings_to_dict(access_settings))
        result['in_use'] = in_use_vdc == name
        result['org'] = in_use_org_name
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Exemple #7
0
 def test_0050_vdc_acl(self):
     """Test the methods related to access control list in vdc.py.
     This test passes if all the acl operations are successful.
     """
     logger = Environment.get_default_logger()
     vdc = VDC(TestOrgVDC._client,
               href=get_non_admin_href(TestOrgVDC._new_vdc_href))
     vdc_name = TestOrgVDC._new_vdc_name
     vapp_user_name = Environment.get_username_for_role_in_test_org(
         CommonRoles.VAPP_USER)
     console_user_name = Environment.get_username_for_role_in_test_org(
         CommonRoles.CONSOLE_ACCESS_ONLY)
     # remove all
     logger.debug('Removing all access control from vdc ' + vdc_name)
     control_access = vdc.remove_access_settings(remove_all=True)
     self.assertFalse(hasattr(control_access, 'AccessSettings'))
     # add
     logger.debug('Adding 2 access control rule to vdc ' + vdc_name)
     vdc.reload()
     control_access = vdc.add_access_settings(
         access_settings_list=[{
             'name': vapp_user_name,
             'type': 'user'
         }, {
             'name': console_user_name,
             'type': 'user',
             'access_level': 'ReadOnly'
         }])
     self.assertEqual(len(control_access.AccessSettings.AccessSetting), 2)
     # get
     logger.debug('Fetching access control rules for vdc ' + vdc_name)
     vdc.reload()
     control_access = vdc.get_access_settings()
     self.assertEqual(len(control_access.AccessSettings.AccessSetting), 2)
     # remove
     logger.debug('Removing 1 access control rule for vdc ' + vdc_name)
     control_access = vdc.remove_access_settings(
         access_settings_list=[{
             'name': vapp_user_name,
             'type': 'user'
         }])
     self.assertEqual(len(control_access.AccessSettings.AccessSetting), 1)
     # share
     logger.debug('Sharing vdc ' + vdc_name + ' with everyone in the org')
     vdc.reload()
     control_access = vdc.share_with_org_members()
     self.assertEqual(control_access.IsSharedToEveryone.text, 'true')
     self.assertEqual(control_access.EveryoneAccessLevel.text, 'ReadOnly')
     # unshare
     logger.debug('Un-sharing vdc ' + vdc_name +
                  ' from everyone in the org')
     vdc.reload()
     control_access = vdc.unshare_from_org_members()
     self.assertEqual(control_access.IsSharedToEveryone.text, 'false')
     # re-share, before performing any other ACL operation to avoid
     # running into https://github.com/vmware/pyvcloud/issues/279
     logger.debug('Re-sharing vdc ' + vdc_name + ' with everyone in the ' +
                  'org')
     vdc.reload()
     control_access = vdc.share_with_org_members()
     self.assertEqual(control_access.IsSharedToEveryone.text, 'true')
     self.assertEqual(control_access.EveryoneAccessLevel.text, 'ReadOnly')
     # remove the last access setting
     logger.debug('Removing the last remaining access control from'
                  ' vdc ' + vdc_name)
     vdc.reload()
     control_access = vdc.remove_access_settings(remove_all=True)
     self.assertFalse(hasattr(control_access, 'AccessSettings'))
Exemple #8
0
    def test_0050_vdc_acl(self):
        """Test the methods related to access control list in vdc.py.

        This test passes if all the acl operations are successful.
        """
        logger = Environment.get_default_logger()
        vdc = VDC(TestOrgVDC._client, href=TestOrgVDC._new_vdc_href)
        vdc_name = TestOrgVDC._new_vdc_name

        vapp_user_name = Environment.get_username_for_role_in_test_org(
            CommonRoles.VAPP_USER)
        console_user_name = Environment.get_username_for_role_in_test_org(
            CommonRoles.CONSOLE_ACCESS_ONLY)

        # remove all
        logger.debug('Removing all access control from vdc ' + vdc_name)
        control_access = vdc.remove_access_settings(remove_all=True)
        self.assertFalse(hasattr(control_access, 'AccessSettings'))

        # add
        logger.debug('Adding 2 access control rule to vdc ' + vdc_name)
        vdc.reload()
        control_access = vdc.add_access_settings(
            access_settings_list=[{
                'name': vapp_user_name,
                'type': 'user'
            }, {
                'name': console_user_name,
                'type': 'user',
                'access_level': 'ReadOnly'
            }])
        self.assertEqual(len(control_access.AccessSettings.AccessSetting), 2)

        # get
        logger.debug('Fetching access control rules for vdc ' + vdc_name)
        vdc.reload()
        control_access = vdc.get_access_settings()
        self.assertEqual(len(control_access.AccessSettings.AccessSetting), 2)

        # remove
        logger.debug('Removing 1 access control rule for vdc ' + vdc_name)
        control_access = vdc.remove_access_settings(
            access_settings_list=[{
                'name': vapp_user_name,
                'type': 'user'
            }])
        self.assertEqual(len(control_access.AccessSettings.AccessSetting), 1)

        # share
        logger.debug('Sharing vdc ' + vdc_name + ' with everyone in the org')
        vdc.reload()
        control_access = vdc.share_with_org_members()
        self.assertEqual(control_access.IsSharedToEveryone.text, 'true')
        self.assertEqual(control_access.EveryoneAccessLevel.text, 'ReadOnly')

        # unshare
        logger.debug(
            'Un-sharing vdc ' + vdc_name + ' from everyone in the org')
        vdc.reload()
        control_access = vdc.unshare_from_org_members()
        self.assertEqual(control_access.IsSharedToEveryone.text, 'false')

        # re-share, before performing any other ACL operation to avoid
        # running into https://github.com/vmware/pyvcloud/issues/279
        logger.debug('Re-sharing vdc ' + vdc_name + ' with everyone in the ' +
                     'org')
        vdc.reload()
        control_access = vdc.share_with_org_members()
        self.assertEqual(control_access.IsSharedToEveryone.text, 'true')
        self.assertEqual(control_access.EveryoneAccessLevel.text, 'ReadOnly')

        # remove the last access setting
        logger.debug('Removing the last remaining access control from'
                     ' vdc ' + vdc_name)
        vdc.reload()
        control_access = vdc.remove_access_settings(remove_all=True)
        self.assertFalse(hasattr(control_access, 'AccessSettings'))