本文整理汇总了Python中azure.mgmt.resource.ResourceManagementClient方法的典型用法代码示例。如果您正苦于以下问题:Python resource.ResourceManagementClient方法的具体用法?Python resource.ResourceManagementClient怎么用?Python resource.ResourceManagementClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.mgmt.resource
的用法示例。
在下文中一共展示了resource.ResourceManagementClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_resource_group
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def create_resource_group(credentials, subscription_id, **kwargs):
"""
Create a resource group
:param credentials: msrestazure.azure_active_directory.AdalAuthentication
:param subscription_id: str
:param **resource_group: str
:param **region: str
"""
resource_client = ResourceManagementClient(credentials, subscription_id)
resource_client.resource_groups.list()
for i in range(3):
try:
resource_group = resource_client.resource_groups.create_or_update(
resource_group_name=kwargs.get("resource_group", DefaultSettings.resource_group),
parameters={
'location': kwargs.get("region", DefaultSettings.region),
})
except CloudError as e:
if i == 2:
raise AccountSetupError("Unable to create resource group in region {}".format(
kwargs.get("region", DefaultSettings.region)))
print(e.message)
print("Please try again.")
kwargs["resource_group"] = prompt_with_default("Azure Region", DefaultSettings.region)
return resource_group.id
示例2: create_mgmt_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def create_mgmt_client(credentials, subscription, location='westus'):
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.eventhub import EventHubManagementClient
resource_client = ResourceManagementClient(credentials, subscription)
rg_name = 'pytest-{}'.format(uuid.uuid4())
resource_group = resource_client.resource_groups.create_or_update(
rg_name, {'location': location})
eh_client = EventHubManagementClient(credentials, subscription)
namespace = 'pytest-{}'.format(uuid.uuid4())
creator = eh_client.namespaces.create_or_update(
resource_group.name,
namespace)
create.wait()
return resource_group, eh_client
示例3: create_azure_session
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def create_azure_session(token, service):
assert service in ['compute', 'network', 'security', 'storage', 'resource']
assert isinstance(token, ServicePrincipalCredentials)
platform = config.profile.get('platform')
if 'subscription' in platform and platform['subscription']:
sub_id = platform['subscription']
else:
raise ValueError("Subscription ID not in Azure Platform Definition")
if service == 'compute':
from azure.mgmt.compute import ComputeManagementClient
return ComputeManagementClient(token, sub_id)
if service == 'network':
from azure.mgmt.network import NetworkManagementClient
return NetworkManagementClient(token, sub_id)
if service == 'storage':
from azure.mgmt.storage import StorageManagementClient
return StorageManagementClient(token, sub_id)
if service == 'resource':
from azure.mgmt.resource import ResourceManagementClient
return ResourceManagementClient(token, sub_id)
示例4: __init__
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def __init__(self, subscription_id, resource_group, pub_ssh_key_path='~/.ssh/id_rsa.pub'):
self.subscription_id = subscription_id
self.resource_group = resource_group
self.dns_label_prefix = self.name_generator.haikunate()
pub_ssh_key_path = os.path.expanduser(pub_ssh_key_path)
# Will raise if file not exists or not enough permission
with open(pub_ssh_key_path, 'r') as pub_ssh_file_fd:
self.pub_ssh_key = pub_ssh_file_fd.read()
self.credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
self.client = ResourceManagementClient(
self.credentials, self.subscription_id)
示例5: get_rg
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def get_rg(group_name, credentials, subscription_id):
"""
Get the RG named group_name, if it not exists return None
"""
try:
resource_client = ResourceManagementClient(credentials, subscription_id)
return resource_client.resource_groups.get(group_name)
except CloudError as cex:
if cex.status_code == 404:
return None
else:
raise cex
示例6: finalize
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def finalize(self, vm, last, auth_data):
credentials, subscription_id = self.get_credentials(auth_data)
try:
resource_client = ResourceManagementClient(credentials, subscription_id)
if vm.id:
self.log_info("Terminate VM: %s" % vm.id)
group_name = vm.id.split('/')[0]
# Delete Resource group and everything in it
if self.get_rg(group_name, credentials, subscription_id):
deleted, msg = self.delete_resource_group(group_name, resource_client)
if not deleted:
return False, "Error terminating the VM: %s" % msg
else:
self.log_info("RG: %s does not exist. Do not remove." % group_name)
else:
self.log_warn("No VM ID. Ignoring")
# if it is the last VM delete the RG of the Inf
if last:
if self.get_rg("rg-%s" % vm.inf.id, credentials, subscription_id):
deleted, msg = self.delete_resource_group("rg-%s" % vm.inf.id, resource_client)
if not deleted:
return False, "Error terminating the VM: %s" % msg
else:
self.log_info("RG: %s does not exist. Do not remove." % "rg-%s" % vm.inf.id)
except Exception as ex:
self.log_exception("Error terminating the VM")
return False, "Error terminating the VM: " + str(ex)
return True, ""
示例7: resource_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def resource_client(self):
"""Return a resource client."""
return ResourceManagementClient(self.credentials, self.subscription_id)
示例8: test_resource_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def test_resource_client(self, _):
"""Test the resource_client property."""
obj = AzureClientFactory(
subscription_id=FAKE.uuid4(),
tenant_id=FAKE.uuid4(),
client_id=FAKE.uuid4(),
client_secret=FAKE.word(),
cloud=random.choice(self.clouds),
)
self.assertTrue(isinstance(obj.resource_client, ResourceManagementClient))
示例9: __init__
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def __init__(self, connect: bool = False):
"""Initialize connector for Azure Python SDK."""
self.connected = False
self.credentials: Optional[ServicePrincipalCredentials] = None
self.sub_client: Optional[SubscriptionClient] = None
self.resource_client: Optional[ResourceManagementClient] = None
self.network_client: Optional[NetworkManagementClient] = None
self.monitoring_client: Optional[MonitorManagementClient] = None
self.compute_client: Optional[ComputeManagementClient] = None
if connect is True:
self.connect()
示例10: __init__
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def __init__(self):
os.environ['AZURE_AUTH_LOCATION'] = '/root/azure_auth.json'
self.compute_client = get_client_from_auth_file(ComputeManagementClient)
self.resource_client = get_client_from_auth_file(ResourceManagementClient)
self.network_client = get_client_from_auth_file(NetworkManagementClient)
self.storage_client = get_client_from_auth_file(StorageManagementClient)
self.datalake_client = get_client_from_auth_file(DataLakeStoreAccountManagementClient)
self.authorization_client = get_client_from_auth_file(AuthorizationManagementClient)
self.sp_creds = json.loads(open(os.environ['AZURE_AUTH_LOCATION']).read())
self.dl_filesystem_creds = lib.auth(tenant_id=json.dumps(self.sp_creds['tenantId']).replace('"', ''),
client_secret=json.dumps(self.sp_creds['clientSecret']).replace('"', ''),
client_id=json.dumps(self.sp_creds['clientId']).replace('"', ''),
resource='https://datalake.azure.net/')
示例11: _get_resource_group_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def _get_resource_group_client(profile_credentials, subscription_id):
return ResourceManagementClient(profile_credentials, subscription_id)
示例12: resource_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def resource_client(self):
"""
Uses client from cli so that users can use az login to get their credentials
Returns:
Resource Client
"""
if not self.client:
self.client = get_client_from_cli_profile(ResourceManagementClient)
return self.client
示例13: resource_client
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def resource_client(self):
return ResourceManagementClient(self.credentials, self.subscription_id)
示例14: create_connection_from_config
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def create_connection_from_config():
""" Creates a new Azure api connection """
resource_client = None
compute_client = None
network_client = None
try:
os.environ['AZURE_AUTH_LOCATION']
except KeyError:
try:
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
except KeyError:
sys.exit("No Azure Connection Defined")
else:
resource_client = ResourceManagementClient(credentials, subscription_id)
compute_client = ComputeManagementClient(credentials, subscription_id)
network_client = NetworkManagementClient(credentials, subscription_id)
else:
resource_client = get_client_from_auth_file(ResourceManagementClient)
compute_client = get_client_from_auth_file(ComputeManagementClient)
network_client = get_client_from_auth_file(NetworkManagementClient)
return resource_client, compute_client, network_client
示例15: __init__
# 需要导入模块: from azure.mgmt import resource [as 别名]
# 或者: from azure.mgmt.resource import ResourceManagementClient [as 别名]
def __init__(self, provider_config, cluster_name):
NodeProvider.__init__(self, provider_config, cluster_name)
kwargs = {}
if "subscription_id" in provider_config:
kwargs["subscription_id"] = provider_config["subscription_id"]
try:
self.compute_client = get_client_from_cli_profile(
client_class=ComputeManagementClient, **kwargs)
self.network_client = get_client_from_cli_profile(
client_class=NetworkManagementClient, **kwargs)
self.resource_client = get_client_from_cli_profile(
client_class=ResourceManagementClient, **kwargs)
except CLIError as e:
if str(e) != "Please run 'az login' to setup account.":
raise
else:
logger.info("CLI profile authentication failed. Trying MSI")
credentials = MSIAuthentication()
self.compute_client = ComputeManagementClient(
credentials=credentials, **kwargs)
self.network_client = NetworkManagementClient(
credentials=credentials, **kwargs)
self.resource_client = ResourceManagementClient(
credentials=credentials, **kwargs)
self.lock = RLock()
# cache node objects
self.cached_nodes = {}