当前位置: 首页>>代码示例>>Python>>正文


Python compute.ComputeManagementClient方法代码示例

本文整理汇总了Python中azure.mgmt.compute.ComputeManagementClient方法的典型用法代码示例。如果您正苦于以下问题:Python compute.ComputeManagementClient方法的具体用法?Python compute.ComputeManagementClient怎么用?Python compute.ComputeManagementClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.mgmt.compute的用法示例。


在下文中一共展示了compute.ComputeManagementClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vm_action

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def vm_action(self, vm, action, auth_data):
        try:
            group_name = vm.id.split('/')[0]
            vm_name = vm.id.split('/')[1]
            credentials, subscription_id = self.get_credentials(auth_data)
            compute_client = ComputeManagementClient(credentials, subscription_id)
            if action == 'stop':
                compute_client.virtual_machines.power_off(group_name, vm_name)
            elif action == 'start':
                compute_client.virtual_machines.start(group_name, vm_name)
            elif action == 'reboot':
                compute_client.virtual_machines.restart(group_name, vm_name)
        except Exception as ex:
            self.log_exception("Error restarting the VM")
            return False, "Error restarting the VM: " + str(ex)

        return True, "" 
开发者ID:grycap,项目名称:im,代码行数:19,代码来源:Azure.py

示例2: create_azure_session

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [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) 
开发者ID:Chaffelson,项目名称:whoville,代码行数:22,代码来源:infra.py

示例3: _collect_allocated_vms

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def _collect_allocated_vms(self, allocated_vms):
        rows = []

        for subscription_id in self._subscription_ids:
            compute_client = ComputeManagementClient(self._credentials, str(subscription_id))
            for vm in compute_client.virtual_machines.list_all():
                rows.append([
                    subscription_id,
                    vm.location,
                    _extract_resource_group(vm.id),
                    vm.hardware_profile.vm_size,
                    1])

        df = DataFrame(data=rows, columns=_ALL_COLUMNS)

        groups = df.groupby(_BASE_COLUMNS).sum()

        for labels, value in groups.iterrows():
            allocated_vms.add_metric(labels, int(value.total)) 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:21,代码来源:allocated_vm_collector.py

示例4: get_instance_type_by_name

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def get_instance_type_by_name(instance_name, location, credentials, subscription_id):
        compute_client = ComputeManagementClient(credentials, subscription_id)
        instace_types = compute_client.virtual_machine_sizes.list(location)

        for instace_type in list(instace_types):
            if instace_type.name == instance_name:
                return instace_type

        return None 
开发者ID:grycap,项目名称:im,代码行数:11,代码来源:Azure.py

示例5: get_instance_type

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def get_instance_type(self, system, credentials, subscription_id):
        """
        Get the name of the instance type to launch to Azure

        Arguments:
           - radl(str): RADL document with the requirements of the VM to get the instance type
        Returns: a str with the name of the instance type to launch to Azure
        """
        instance_type_name = system.getValue('instance_type')

        location = self.DEFAULT_LOCATION
        if system.getValue('availability_zone'):
            location = system.getValue('availability_zone')

        (cpu, cpu_op, memory, memory_op, disk_free, disk_free_op) = self.get_instance_selectors(system)

        compute_client = ComputeManagementClient(credentials, subscription_id)
        instace_types = list(compute_client.virtual_machine_sizes.list(location))
        instace_types.sort(key=lambda x: (x.number_of_cores, x.memory_in_mb, x.resource_disk_size_in_mb))

        default = None
        for instace_type in instace_types:
            if instace_type.name == self.INSTANCE_TYPE:
                default = instace_type

            comparison = cpu_op(instace_type.number_of_cores, cpu)
            comparison = comparison and memory_op(instace_type.memory_in_mb, memory)
            comparison = comparison and disk_free_op(instace_type.resource_disk_size_in_mb, disk_free)

            if comparison:
                if not instance_type_name or instace_type.name == instance_type_name:
                    return instace_type

        return default 
开发者ID:grycap,项目名称:im,代码行数:36,代码来源:Azure.py

示例6: updateVMInfo

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def updateVMInfo(self, vm, auth_data):
        self.log_info("Get the VM info with the id: " + vm.id)
        group_name = vm.id.split('/')[0]
        vm_name = vm.id.split('/')[1]

        credentials, subscription_id = self.get_credentials(auth_data)

        try:
            compute_client = ComputeManagementClient(credentials, subscription_id)
            # Get one the virtual machine by name
            virtual_machine = compute_client.virtual_machines.get(group_name, vm_name, expand='instanceView')
        except Exception as ex:
            self.log_warn("The VM does not exists: %s" % str(ex))
            # check if the RG still exists
            if self.get_rg(group_name, credentials, subscription_id):
                self.log_info("But the RG %s does exits. Return OFF." % group_name)
                vm.state = VirtualMachine.OFF
                return (True, vm)

            self.log_exception("Error getting the VM info: " + vm.id)
            return (False, "Error getting the VM info: " + vm.id + ". " + str(ex))

        self.log_info("VM info: " + vm.id + " obtained.")
        vm.state = self.PROVISION_STATE_MAP.get(virtual_machine.provisioning_state, VirtualMachine.UNKNOWN)

        if (vm.state == VirtualMachine.RUNNING and virtual_machine.instance_view and
                len(virtual_machine.instance_view.statuses) > 1):
            vm.state = self.POWER_STATE_MAP.get(virtual_machine.instance_view.statuses[1].code, VirtualMachine.UNKNOWN)

        self.log_debug("The VM state is: " + vm.state)

        instance_type = self.get_instance_type_by_name(virtual_machine.hardware_profile.vm_size,
                                                       virtual_machine.location, credentials, subscription_id)
        self.update_system_info_from_instance(vm.info.systems[0], instance_type)

        # Update IP info
        self.setIPs(vm, virtual_machine.network_profile, credentials, subscription_id)
        self.add_dns_entries(vm, credentials, subscription_id)
        return (True, vm) 
开发者ID:grycap,项目名称:im,代码行数:41,代码来源:Azure.py

示例7: alterVM

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def alterVM(self, vm, radl, auth_data):
        try:
            group_name = vm.id.split('/')[0]
            vm_name = vm.id.split('/')[1]
            credentials, subscription_id = self.get_credentials(auth_data)
            compute_client = ComputeManagementClient(credentials, subscription_id)

            # Deallocating the VM (resize prepare)
            async_vm_deallocate = compute_client.virtual_machines.deallocate(group_name, vm_name)
            async_vm_deallocate.wait()

            instance_type = self.get_instance_type(radl.systems[0], credentials, subscription_id)
            vm_parameters = " { 'hardware_profile': { 'vm_size': %s } } " % instance_type.name

            async_vm_update = compute_client.virtual_machines.create_or_update(group_name,
                                                                               vm_name,
                                                                               vm_parameters)
            async_vm_update.wait()

            # Start the VM
            async_vm_start = compute_client.virtual_machines.start(group_name, vm_name)
            async_vm_start.wait()

            return self.updateVMInfo(vm, auth_data)
        except Exception as ex:
            self.log_exception("Error altering the VM")
            return False, "Error altering the VM: " + str(ex)

        return (True, "") 
开发者ID:grycap,项目名称:im,代码行数:31,代码来源:Azure.py

示例8: get_client

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def get_client(self, subscription_id: str):
        return ComputeManagementClient(self.credentials.get_credentials('arm'),
                                       subscription_id=subscription_id) 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:5,代码来源:virtualmachines.py

示例9: __init__

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [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() 
开发者ID:microsoft,项目名称:msticpy,代码行数:13,代码来源:azure_data.py

示例10: __init__

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [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/') 
开发者ID:apache,项目名称:incubator-dlab,代码行数:15,代码来源:actions_lib.py

示例11: compute_client

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def compute_client(self):
        self.log('Getting compute client')
        if not self._compute_client:
            self._compute_client = self.get_mgmt_svc_client(ComputeManagementClient,
                                                            self._cloud_environment.endpoints.resource_manager,
                                                            '2017-03-30')
            self._register('Microsoft.Compute')
        return self._compute_client 
开发者ID:hortonworks,项目名称:ansible-hortonworks,代码行数:10,代码来源:azure_rm.py

示例12: compute_client

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def compute_client(self):
        """
        Uses client from cli so that users can use az login to get their credentials

        Returns:
             Compute Client
        """
        if not self.client:
            self.client = get_client_from_cli_profile(ComputeManagementClient)
        return self.client 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:12,代码来源:azure_resource.py

示例13: create_connection_from_config

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [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 
开发者ID:bloomberg,项目名称:powerfulseal,代码行数:29,代码来源:azure_driver.py

示例14: set_bootDiagnostics

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def set_bootDiagnostics():
    credentials, subscription_id = get_credentials()
    compute_client = ComputeManagementClient(credentials, subscription_id)

    # Set Boot diagnostics for the virtual machine
    az_storage_uri = 'https://{}.blob.core.windows.net/'.format(az_storage_account_name)
    
    async_vm_update = compute_client.virtual_machines.create_or_update(
        az_resource_group_name,
        az_vm_name,
        {
            'location': az_location,
            'diagnostics_profile': {
                'boot_diagnostics': {
                    'enabled': True,
                    'additional_properties': {},
                    'storage_uri': az_storage_uri
                }
            }
        }
    )
    print('\nConfiguring Boot diagnostics. Please wait...')
    async_vm_update.wait()
    
    # Get the virtual machine by name
    print('\nBoot diagnostics status')
    virtual_machine = compute_client.virtual_machines.get(
        az_resource_group_name,
        az_vm_name,
        expand='instanceview'
    )

    return virtual_machine.diagnostics_profile.boot_diagnostics
# endregion

# region execute function 
开发者ID:nutanix,项目名称:blueprints,代码行数:38,代码来源:azure_enable_bootDiagnostics.py

示例15: compute_client

# 需要导入模块: from azure.mgmt import compute [as 别名]
# 或者: from azure.mgmt.compute import ComputeManagementClient [as 别名]
def compute_client(self):
        self.log('Getting compute client')
        if not self._compute_client:
            self._compute_client = ComputeManagementClient(
                self.azure_credentials,
                self.subscription_id,
                base_url=self._cloud_environment.endpoints.resource_manager,
                api_version='2017-03-30'
            )
            self._register('Microsoft.Compute')
        return self._compute_client 
开发者ID:PacktPublishing,项目名称:Ansible-2-Cloud-Automation-Cookbook,代码行数:13,代码来源:azure_rm.py


注:本文中的azure.mgmt.compute.ComputeManagementClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。