當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。