本文整理汇总了Python中c7n_azure.session.Session.client方法的典型用法代码示例。如果您正苦于以下问题:Python Session.client方法的具体用法?Python Session.client怎么用?Python Session.client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c7n_azure.session.Session
的用法示例。
在下文中一共展示了Session.client方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_api_version
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_api_version(self):
"""Verify we retrieve the correct API version for a resource type"""
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
resource = next(client.resources.list())
self.assertTrue(re.match('\\d{4}-\\d{2}-\\d{2}',
s.resource_api_version(resource.id)) is not None)
示例2: setup_account
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def setup_account():
# Find actual name of storage account provisioned in our test environment
s = Session()
client = s.client('azure.mgmt.storage.StorageManagementClient')
accounts = list(client.storage_accounts.list())
matching_account = [a for a in accounts if a.name.startswith("cctstorage")]
return matching_account[0]
示例3: test_tag_trim_does_nothing_if_space_available
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_tag_trim_does_nothing_if_space_available(self):
"""Verifies tag trim returns without trimming tags
if the resource has space equal to or greater than
the space value.
"""
s = Session()
client = s.client('azure.mgmt.compute.ComputeManagementClient')
vm = client.virtual_machines.get('test_vm', 'cctestvm')
start_tags = vm.tags
# verify there is at least 1 space for a tag
self.assertLess(len(start_tags), 15)
# trim for space for 1 tag
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag-trim',
'space': 1}
],
})
p.run()
# verify that tags are unchanged
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertEqual(vm.tags, start_tags)
示例4: test_add_or_update_single_tag
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_add_or_update_single_tag(self):
"""Verifies we can add a new tag to a VM and not modify
an existing tag on that resource
"""
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag',
'tag': 'tag1',
'value': 'value1'}
],
})
p.run()
# verify that the a new tag is added without modifying existing tags
s = Session()
client = s.client('azure.mgmt.compute.ComputeManagementClient')
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertEqual(vm.tags, {'tag1': 'value1', 'testtag': 'testvalue'})
示例5: test_auto_tag_add_creator_tag
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_auto_tag_add_creator_tag(self, utcnow_mock):
"""Adds CreatorEmail to a resource group
"""
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'auto-tag-user',
'tag': 'CreatorEmail'},
],
})
p.run()
# verify CreatorEmail tag set
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0]
self.assertTrue(re.match(self.EMAIL_REGEX, rg.tags['CreatorEmail']))
示例6: test_get_client_overrides
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_get_client_overrides(self, mock):
# Reload the module to re-import patched function
reload(sys.modules['c7n_azure.session'])
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
self.assertFalse(client._client.config.retry_policy.policy.respect_retry_after_header)
self.assertIsNotNone(client._client.orig_send)
client._client.send()
self.assertTrue(mock.called)
示例7: test_remove_tags
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_remove_tags(self):
"""Verifies we can delete multiple tags from a resource
group without modifying existing tags.
"""
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'tag',
'tags': {'pre-existing-1': 'to-keep', 'pre-existing-2': 'to-keep',
'added-1': 'to-delete', 'added-2': 'to-delete'}},
],
})
p.run()
# verify initial tag set
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0]
start_tags = rg.tags
self.assertTrue('pre-existing-1' in start_tags)
self.assertTrue('pre-existing-2' in start_tags)
self.assertTrue('added-1' in start_tags)
self.assertTrue('added-2' in start_tags)
p = self.load_policy({
'name': 'test-azure-remove-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'untag',
'tags': ['added-1', 'added-2']}
],
})
p.run()
# verify tags removed and pre-existing tags not removed
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0] # NOQA
end_tags = rg.tags
self.assertTrue('pre-existing-1' in end_tags)
self.assertTrue('pre-existing-2' in end_tags)
self.assertTrue('added-1' not in end_tags)
self.assertTrue('added-2' not in end_tags)
示例8: test_tag_trim_space_0_removes_all_tags_but_preserve
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_tag_trim_space_0_removes_all_tags_but_preserve(self):
"""Verifies tag trim removes all other tags but tags
listed in preserve
"""
# Add tags to trim
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag',
'tags': {'tag-to-trim1': 'value1', 'tag-to-trim2': 'value2',
'tag-to-trim3': 'value3'}}
],
})
p.run()
# verify initial tags contain more than testtag
s = Session()
client = s.client('azure.mgmt.compute.ComputeManagementClient')
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertTrue('tag-to-trim1' in vm.tags)
self.assertTrue('tag-to-trim2' in vm.tags)
self.assertTrue('tag-to-trim3' in vm.tags)
self.assertTrue('testtag' in vm.tags)
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag-trim',
'space': 0,
'preserve': ['testtag']
}
],
})
p.run()
# verify all tags trimmed but testtag
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertEqual(vm.tags, {'testtag': 'testvalue'})
示例9: test_tag_trim_removes_tags_for_space
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_tag_trim_removes_tags_for_space(self):
"""Verifies tag trim removes tags when the space value
and number of tags on the resource are greater than the max
tag value (15)
"""
# Add tags to trim
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag',
'tags': {'tag-to-trim1': 'value1', 'tag-to-trim2': 'value2'}}
],
})
p.run()
# verify more than 1 tag on resource
s = Session()
client = s.client('azure.mgmt.compute.ComputeManagementClient')
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertTrue(len(vm.tags) > 1)
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'tag-trim',
'space': 14,
'preserve': ['testtag']
}
],
})
p.run()
# verify that tags were trimmed to
# have 14 spaces and 1 preserved
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertEqual(len(vm.tags), 1)
示例10: test_add_or_update_tags
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_add_or_update_tags(self):
"""Adds tags to an empty resource group, then updates one
tag and adds a new tag
"""
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'tag',
'tags': {'pre-existing-1': 'unmodified', 'pre-existing-2': 'unmodified'}},
],
})
p.run()
# verify initial tag set
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0]
self.assertEqual(rg.tags,
{'pre-existing-1': 'unmodified', 'pre-existing-2': 'unmodified'})
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'tag',
'tags': {'tag1': 'value1', 'pre-existing-1': 'modified'}}
],
})
p.run()
# verify modified tags
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0] # NOQA
self.assertEqual(
rg.tags,
{'tag1': 'value1', 'pre-existing-1': 'modified', 'pre-existing-2': 'unmodified'})
示例11: test_deploy_webapp
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_deploy_webapp(self):
s = Session()
web_client = s.client('azure.mgmt.web.WebSiteManagementClient')
service_plan = web_client.app_service_plans.get(
CONST_GROUP_NAME, 'cloud-custodian-test')
self.assertIsNotNone(service_plan)
webapp_name = 'test-deploy-webapp'
self.functionapp_util.deploy_webapp(webapp_name,
CONST_GROUP_NAME,
service_plan,
'cloudcustodiantest')
wep_app = web_client.web_apps.get(CONST_GROUP_NAME, webapp_name)
self.assertIsNotNone(wep_app)
示例12: test_auto_tag_update_false_noop_for_existing_tag
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_auto_tag_update_false_noop_for_existing_tag(self, utcnow_mock):
"""Adds CreatorEmail to a resource group
"""
# setup by adding an existing CreatorEmail tag
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'tag',
'tag': 'CreatorEmail',
'value': 'do-not-modify'},
],
})
p.run()
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.resourcegroup',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'test_vm'}
],
'actions': [
{'type': 'auto-tag-user',
'tag': 'CreatorEmail',
'update': False,
'days': 10}
],
})
p.run()
# verify CreatorEmail tag was not modified
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
rg = [rg for rg in client.resource_groups.list() if rg.name == 'test_vm'][0]
self.assertEqual(rg.tags['CreatorEmail'], 'do-not-modify')
示例13: test_removal_does_not_raise_on_nonexistent_tag
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_removal_does_not_raise_on_nonexistent_tag(self):
"""Verifies attempting to delete a tag that is
not on the resource does not throw an error
"""
p = self.load_policy({
'name': 'test-azure-tag',
'resource': 'azure.vm',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'eq',
'value_type': 'normalize',
'value': 'cctestvm'}
],
'actions': [
{'type': 'untag',
'tags': ['tag-does-not-exist']},
],
})
# verify initial tag set
s = Session()
client = s.client('azure.mgmt.compute.ComputeManagementClient')
vm = client.virtual_machines.get('test_vm', 'cctestvm')
start_tags = vm.tags
self.assertTrue('tag-does-not-exist' not in start_tags)
raised = False
try:
p.run()
except KeyError:
raised = True
# verify no exception raised and no changes to tags on resource
vm = client.virtual_machines.get('test_vm', 'cctestvm')
self.assertFalse(raised)
self.assertEqual(vm.tags, start_tags)
示例14: test_api_version
# 需要导入模块: from c7n_azure.session import Session [as 别名]
# 或者: from c7n_azure.session.Session import client [as 别名]
def test_api_version(self):
"""Verify we retrieve the correct API version for a resource type"""
s = Session()
client = s.client('azure.mgmt.resource.ResourceManagementClient')
resource = next(client.resources.list())
self.assertEqual('2018-04-01', s.resource_api_version(resource.id))