本文整理汇总了Python中pyvcloud.vcd.vdc.VDC.add_access_settings方法的典型用法代码示例。如果您正苦于以下问题:Python VDC.add_access_settings方法的具体用法?Python VDC.add_access_settings怎么用?Python VDC.add_access_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.vdc.VDC
的用法示例。
在下文中一共展示了VDC.add_access_settings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import add_access_settings [as 别名]
def add(ctx, vdc_name, access_list):
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)
vdc.add_access_settings(
access_settings_list=acl_str_to_list_of_dict(access_list))
stdout('Access settings added to vdc \'%s\'.' % vdc_name, ctx)
except Exception as e:
stderr(e, ctx)
示例2: test_02_add_vdc_access
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import add_access_settings [as 别名]
def test_02_add_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.add_access_settings(
access_settings_list=[
{'name': self.config['vcd']['access_user'], 'type': 'user'},
{'name': self.config['vcd']['access_user1'], 'type': 'user',
'access_level': 'ReadOnly'}
])
assert len(control_access.AccessSettings.AccessSetting) == 2
示例3: test_0050_vdc_acl
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import add_access_settings [as 别名]
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'))