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


Python credentials.ServicePrincipalCredentials方法代码示例

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


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

示例1: __init__

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def __init__(self, config):
        self._config = config
        self.subscription_id = str(config.get('azure_subscription_id'))
        self._credentials = ServicePrincipalCredentials(
            client_id=config.get('azure_client_id'),
            secret=config.get('azure_secret'),
            tenant=config.get('azure_tenant')
        )

        self._access_token = config.get('azure_access_token')
        self._resource_client = None
        self._storage_client = None
        self._network_management_client = None
        self._subscription_client = None
        self._compute_client = None
        self._access_key_result = None
        self._block_blob_service = None
        self._table_service = None
        self._storage_account = None

        log.debug("azure subscription : %s", self.subscription_id) 
开发者ID:CloudVE,项目名称:cloudbridge,代码行数:23,代码来源:azure_client.py

示例2: get_blob_client

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def get_blob_client() -> blob.BlockBlobService:
    if not storage_resource_id:
        return blob.BlockBlobService(
            account_name=storage_account_name, account_key=storage_account_key, endpoint_suffix=storage_account_suffix)
    else:
        credentials = ServicePrincipalCredentials(
            client_id=client_id, secret=credential, tenant=tenant_id, resource="https://management.core.windows.net/")
        m = RESOURCE_ID_PATTERN.match(storage_resource_id)
        accountname = m.group("account")
        subscription = m.group("subscription")
        resourcegroup = m.group("resourcegroup")
        mgmt_client = StorageManagementClient(credentials, subscription)
        key = (mgmt_client.storage_accounts.list_keys(resource_group_name=resourcegroup, account_name=accountname)
               .keys[0].value)
        storage_client = CloudStorageAccount(accountname, key)
        return storage_client.create_block_blob_service() 
开发者ID:Azure,项目名称:aztk,代码行数:18,代码来源:config.py

示例3: get_credentials

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def get_credentials():
    subscription_id = os.environ.get(
        'AZURE_SUBSCRIPTION_ID',
        '11111111-1111-1111-1111-111111111111')  # your Azure Subscription Id
    credentials = ServicePrincipalCredentials(
        client_id=os.environ['AZURE_CLIENT_ID'],
        secret=os.environ['AZURE_CLIENT_SECRET'],
        tenant=os.environ['AZURE_TENANT_ID']
    )
    return credentials, subscription_id

# This script expects that the following environment vars are set:
#
# AZURE_TENANT_ID: with your Azure Active Directory tenant id or domain
# AZURE_CLIENT_ID: with your Azure Active Directory Application Client ID
# AZURE_CLIENT_SECRET: with your Azure Active Directory Application Secret
# AZURE_SUBSCRIPTION_ID: with your Azure Subscription Id
# 
开发者ID:Azure-Samples,项目名称:storage-python-manage,代码行数:20,代码来源:example.py

示例4: __init__

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def __init__(self, **kwargs):
        super(AzureSystem, self).__init__(**kwargs)
        self.client_id = kwargs.get("username")
        self.client_secret = kwargs.get("password")
        self.tenant = kwargs.get("tenant_id")
        self.subscription_id = kwargs.get("subscription_id")
        self.resource_group = kwargs['provisioning']['resource_group']  # default resource group
        self.storage_account = kwargs.get("storage_account")
        self.storage_key = kwargs.get("storage_key")
        self.template_container = kwargs['provisioning']['template_container']
        self.orphaned_discs_path = 'Microsoft.Compute/Images/templates/'
        self.region = kwargs["provisioning"]["region_api"].replace(' ', '').lower()

        self.credentials = ServicePrincipalCredentials(client_id=self.client_id,
                                                       secret=self.client_secret,
                                                       tenant=self.tenant) 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:18,代码来源:msazure.py

示例5: create_azure_session

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [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

示例6: __init__

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def __init__(self, application_id, application_secret, tenant_id, metric_name):
        """
        Constructor. Access is granted to what Microsoft calls a service principal / Azure Active Directory
        Application / app registration. Read more about this topic at
        https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal.
        This page will guide you how to obtain an application_id, and application_secret, and the tenant_id of
        your Azure Active Directory.
        
        In addition, the application requires "Reader" permissions on _each individual_ reservation _order_ to be
        able to retrieve the information of the actual reservations within the reservation orders.
        
        :param application_id: The application ID that is created during the Azure app registration.
        :param application_secret: The application secret that is created during the Azure app registration.
        :param tenant_id: The ID of your Azure Active Directory instance
        :param metric_name: Name of the timeseries
        """
        self._metric_name = metric_name
        self._credentials = ServicePrincipalCredentials(client_id=application_id,
                                                        secret=application_secret,
                                                        tenant=tenant_id) 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:22,代码来源:reserved_vm_collector.py

示例7: __init__

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def __init__(self, application_id, application_secret, tenant_id, subscription_ids, metric_name):
        """
        Constructor. Access is granted to what Microsoft calls a service principal / Azure Active Directory
        Application / app registration. Read more about this topic at
        https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal.
        This page will guide you how to obtain an application_id, and application_secret, and the tenant_id of
        your Azure Active Directory. Please do not forget to grant "Reader" permissions to the app for all
        subscriptions that you want to monitor.
        
        :param application_id: The application ID that is created during the Azure app registration.
        :param application_secret: The application secret that is created during the Azure app registration.
        :param tenant_id: The ID of your Azure Active Directory instance
        :param subscription_ids: A _sequence_ of subscription IDs that shall be monitored. The application_id
                                 required "Reader" permissions on each subscription.
        :param metric_name: Name of the timeseries
        """
        self._metric_name = metric_name
        self._subscription_ids = subscription_ids
        self._credentials = ServicePrincipalCredentials(
            client_id=application_id,
            secret=application_secret,
            tenant=tenant_id) 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:24,代码来源:allocated_vm_collector.py

示例8: engine_status

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def engine_status(cls, **kwargs):
        try:
            credentials = ServicePrincipalCredentials(client_id=kwargs.get('client_id'),
                                                      secret=kwargs.get('secret'),
                                                      tenant=kwargs.get('tenant'))
        except AuthenticationError:
            logger.exception('Invalid credentials for {} Azure Provisioner'.format(cls.name))
            return config.get('PROVISIONER_ERROR_STATE')
        except Exception:
            logger.exception('{} Azure Provisioner validation failed.'.format(cls.name))
            return config.get('PROVISIONER_UNKNOWN_STATE')
        client = ContainerServiceClient(credentials, kwargs.get('subscription_id'))
        try:
            list(client.managed_clusters.list_by_resource_group(kwargs.get('resource_group_name')))
        except CloudError as e:
            logger.exception('Invalid parameters for {} Azure Provisioner: {}'.format(cls.name, e.message))
            return config.get('PROVISIONER_ERROR_STATE')
        except Exception:
            logger.exception('{} Azure Provisioner validation failed.'.format(cls.name))
            return config.get('PROVISIONER_UNKNOWN_STATE')
        return config.get('PROVISIONER_OK_STATE') 
开发者ID:Mirantis,项目名称:kqueen,代码行数:23,代码来源:aks.py

示例9: run

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def run(job, **kwargs):
    resource = kwargs.pop("resources").first()

    server_name = resource.attributes.get(field__name="azure_server_name").value
    database_name = resource.attributes.get(field__name="azure_database_name").value
    resource_group = resource.attributes.get(field__name="resource_group_name").value
    rh_id = resource.attributes.get(field__name="azure_rh_id").value
    rh = AzureARMHandler.objects.get(id=rh_id)

    set_progress("Connecting To Azure...")
    credentials = ServicePrincipalCredentials(
        client_id=rh.client_id, secret=rh.secret, tenant=rh.tenant_id
    )
    client = mariadb.MariaDBManagementClient(credentials, rh.serviceaccount)
    set_progress("Connection to Azure established")

    set_progress("Deleting database %s from %s..." % (server_name, database_name))
    client.databases.delete(resource_group, server_name, database_name).wait()

    set_progress("Deleting server %s..." % server_name)
    client.servers.delete(resource_group, server_name).wait()

    return "", "", "" 
开发者ID:CloudBoltSoftware,项目名称:cloudbolt-forge,代码行数:25,代码来源:delete.py

示例10: run

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def run(job, **kwargs):
    resource = kwargs.pop("resources").first()

    server_name = resource.attributes.get(field__name="azure_server_name").value
    database_name = resource.attributes.get(field__name="azure_database_name").value
    resource_group = resource.attributes.get(field__name="resource_group_name").value
    rh_id = resource.attributes.get(field__name="azure_rh_id").value
    rh = AzureARMHandler.objects.get(id=rh_id)

    set_progress("Connecting To Azure...")
    credentials = ServicePrincipalCredentials(
        client_id=rh.client_id, secret=rh.secret, tenant=rh.tenant_id
    )
    client = postgresql.PostgreSQLManagementClient(credentials, rh.serviceaccount)
    set_progress("Connection to Azure established")

    set_progress("Deleting database %s from %s..." % (server_name, database_name))
    client.databases.delete(resource_group, server_name, database_name).wait()

    set_progress("Deleting server %s..." % server_name)
    client.servers.delete(resource_group, server_name).wait()

    return "", "", "" 
开发者ID:CloudBoltSoftware,项目名称:cloudbolt-forge,代码行数:25,代码来源:delete.py

示例11: _get_client

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def _get_client(handler):
    """
    Get the client using newer methods from the CloudBolt main repo if this CB is running
    a version greater than 9.2.1. These internal methods implicitly take care of much of the other
    features in CloudBolt such as proxy and ssl verification.
    Otherwise, manually instantiate clients without support for those other CloudBolt settings.
    """
    if CB_VERSION_93_PLUS:
        from resourcehandlers.azure_arm.azure_wrapper import configure_arm_client

        wrapper = handler.get_api_wrapper()
        sql_client = configure_arm_client(wrapper, sql.SqlManagementClient)
    else:
        # TODO: Remove once versions <= 9.2.1 are no longer supported.
        credentials = ServicePrincipalCredentials(
            client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id
        )
        sql_client = sql.SqlManagementClient(credentials, handler.serviceaccount)

    set_progress("Connection to Azure established")

    return sql_client 
开发者ID:CloudBoltSoftware,项目名称:cloudbolt-forge,代码行数:24,代码来源:create.py

示例12: _get_client

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def _get_client(handler):
    """
    Get the client using newer methods from the CloudBolt main repo if this CB is running
    a version greater than 9.2. These internal methods implicitly take care of much of the other
    features in CloudBolt such as proxy and ssl verification.
    Otherwise, manually instantiate clients without support for those other CloudBolt settings.
    """
    if CB_VERSION_93_PLUS:
        from resourcehandlers.azure_arm.azure_wrapper import configure_arm_client

        wrapper = handler.get_api_wrapper()
        cosmosdb_client = configure_arm_client(wrapper, cosmosdb.CosmosDB)
    else:
        # TODO: Remove once versions <= 9.2 are no longer supported.
        credentials = ServicePrincipalCredentials(
            client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id
        )
        cosmosdb_client = cosmosdb.CosmosDB(credentials, handler.serviceaccount)

    set_progress("Connection to Azure established")

    return cosmosdb_client 
开发者ID:CloudBoltSoftware,项目名称:cloudbolt-forge,代码行数:24,代码来源:create.py

示例13: _get_client

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def _get_client(handler):
    """
    Get the client using newer methods from the CloudBolt main repo if this CB is running
    a version greater than 9.2.2. These internal methods implicitly take care of much of the other
    features in CloudBolt such as proxy and ssl verification.
    Otherwise, manually instantiate clients without support for those other CloudBolt settings.
    """
    set_progress("Connecting to Azure...")

    if CB_VERSION_93_PLUS:
        from resourcehandlers.azure_arm.azure_wrapper import configure_arm_client

        wrapper = handler.get_api_wrapper()
        mysql_client = configure_arm_client(wrapper, mysql.MySQLManagementClient)
    else:
        # TODO: Remove once versions <= 9.2.2 are no longer supported.
        credentials = ServicePrincipalCredentials(
            client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id
        )
        mysql_client = mysql.MySQLManagementClient(credentials, handler.serviceaccount)

    set_progress("Connection to Azure established")

    return mysql_client 
开发者ID:CloudBoltSoftware,项目名称:cloudbolt-forge,代码行数:26,代码来源:create.py

示例14: __init__

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [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) 
开发者ID:Azure-Samples,项目名称:resource-manager-python-template-deployment,代码行数:19,代码来源:deployer.py

示例15: get_credentials

# 需要导入模块: from azure.common import credentials [as 别名]
# 或者: from azure.common.credentials import ServicePrincipalCredentials [as 别名]
def get_credentials(self, auth_data):
        auths = auth_data.getAuthInfo(self.type)
        if not auths:
            raise Exception("No auth data has been specified to Azure.")
        else:
            auth = auths[0]

        if 'subscription_id' in auth and 'username' in auth and 'password' in auth:
            subscription_id = auth['subscription_id']

            if self.credentials and self.auth.compare(auth_data, self.type):
                return self.credentials, subscription_id
            else:
                self.auth = auth_data
                self.credentials = UserPassCredentials(auth['username'], auth['password'])
        elif 'subscription_id' in auth and 'client_id' in auth and 'secret' in auth and 'tenant' in auth:
            subscription_id = auth['subscription_id']

            if self.credentials and self.auth.compare(auth_data, self.type):
                return self.credentials, subscription_id
            else:
                self.auth = auth_data
                self.credentials = ServicePrincipalCredentials(client_id=auth['client_id'],
                                                               secret=auth['secret'],
                                                               tenant=auth['tenant'])
        else:
            raise Exception("No correct auth data has been specified to Azure: "
                            "subscription_id, username and password or"
                            "subscription_id, client_id, secret and tenant")

        return self.credentials, subscription_id 
开发者ID:grycap,项目名称:im,代码行数:33,代码来源:Azure.py


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