Esempio n. 1
0
    def __init__(self, resourcegroup: str, storageaccount: str,
                 authenticationtype: str):
        self.resourcegroup = resourcegroup
        self.storageaccount = storageaccount
        self.authenticationtype = authenticationtype

        if self.authenticationtype not in AzureBlob.authenticationlist:
            raise exceptions.AzureError(
                "Authentication type provided is incorrect. It should be one out of {}"
                .format(AzureBlob.authenticationlist))
def getstorageaccounturl(storageaccountname, resourcegroup, storagetype):
    """Get the service url for specific storage account under a resource group for a particular storage type"""

    storagetypeset = ('blob', 'file', 'queue', 'table')
    if storagetype not in storagetypeset:
        raise exceptions.AzureError(
            "Storage Type passed is not correct. It should be one of {}".
            format(storagetypeset))

    acturlcmd = "az storage account show " + "--name " + storageaccountname + " --resource-group " + resourcegroup + " --query " + "primaryEndpoints." + storagetype
    processdict = bashprocess(acturlcmd)

    return processdict['output']
def getsqldatabaseconnectionstring(databasename: str, client: str,
                                   servername: str) -> str:
    """Get the connection string for the sql database to be used with client tool sqlcmd"""

    # Client tool validation
    clienttoolsallowed = ['sqlcmd', 'jdbc', 'odbc']
    if client not in clienttoolsallowed:
        raise exceptions.AzureError(
            "Client provided is incorrect. Please provide one of {}".format(
                clienttoolsallowed))

    connstr = "az sql db show-connection-string" + " --client " + client + " --name " + databasename + " --server " + servername
    processdict = bashprocess(connstr)

    return processdict['output']
Esempio n. 4
0
    def _create_ad_token(self):
        """Make sure Azure tenant, client id and secret are defined as environment variables"""

        ad_environment_variables = [
            'AZURE_TENANT_ID', 'AZURE_CLIENT_ID',
            'AZURE_CLIENT_CERTIFICATE_PATH'
        ]

        vars_undefined = [
            env for env in ad_environment_variables if env not in os.environ
        ]
        if vars_undefined:
            raise exceptions.AzureError(
                "Environment variables {}  are not defined. They are required to make a connection using service principal"
                .format(vars_undefined))
        else:
            # Derive the crednetial token and make it a class attribute
            self.credential_token = DefaultAzureCredential()
Esempio n. 5
0
 def _wait_for_bootstrap_vm(self, timeout=900):
     self.logging.info("Waiting up to %.2f minutes for VM %s to provision",
                       timeout / 60.0, self.bootstrap_vm_name)
     valid_vm_states = ["Creating", "Updating", "Succeeded"]
     for attempt in Retrying(stop=stop_after_delay(timeout),
                             wait=wait_exponential(max=30),
                             retry=retry_if_exception_type(AssertionError),
                             reraise=True):
         with attempt:
             vm = utils.retry_on_error()(
                 self.compute_client.virtual_machines.get)(
                     self.cluster_name, self.bootstrap_vm_name)
             if vm.provisioning_state not in valid_vm_states:
                 err_msg = 'VM "{}" entered invalid state: "{}"'.format(
                     self.bootstrap_vm_name, vm.provisioning_state)
                 self.logging.error(err_msg)
                 raise azure_exceptions.AzureError(err_msg)
             assert vm.provisioning_state == "Succeeded"
     return vm