예제 #1
0
    def set_storage_account(self,
                            storage_account_name,
                            create=False,
                            location_or_affinity_group='Anywhere US'):
        """Set the storage account used by storage API objects.

        Setting to DEVSTORE_ACCOUNT will switch to the local storage
        emulator.
        For anything except switching to dev storage this requires the API
        to have been initialised with an appropriate management Windows
        Azure Service Mangement certificate.
        If the create flag is True and the storage account does not exist
        it will be created in the specified location or affinity group.
        May produce WAError exceptions due to authentication issues or when
        the storage account limit is reached.
        """
        if self.storage_account == storage_account_name:
            return
        storage_account_key = None
        if storage_account_name == DEVSTORE_ACCOUNT:
            self.blobs = BlobStorage(DEVSTORE_BLOB_HOST, DEVSTORE_ACCOUNT,
                                     DEVSTORE_SECRET_KEY)
            self.tables = TableStorage(DEVSTORE_BLOB_HOST, DEVSTORE_ACCOUNT,
                                       DEVSTORE_SECRET_KEY)
            self.queues = QueueStorage(DEVSTORE_BLOB_HOST, DEVSTORE_ACCOUNT,
                                       DEVSTORE_SECRET_KEY)
            self.data_connection_string = create_data_connection_string(
                DEVSTORE_ACCOUNT, DEVSTORE_SECRET_KEY)
            self.storage_account = storage_account_name
            return

        if not self.wasm:
            raise WAError(
                'Windows Azure Service Management API not available.')
        if storage_account_name not in self.wasm.list_storage_accounts():
            if create:
                request = self.wasm.create_storage_account(
                    storage_account_name,
                    'PyAzure storage: %s' % get_azure_time(),
                    location_or_affinity_group,
                    'Storage account created by PyAzure')
                self.wasm.wait_for_request(request)
            else:
                raise WAError('Unknown storage account')
        storage_account_key, _, _ = self.wasm.get_storage_account_keys(
            storage_account_name)
        self.blobs = BlobStorage(CLOUD_BLOB_HOST, storage_account_name,
                                 storage_account_key)
        self.tables = TableStorage(CLOUD_TABLE_HOST, storage_account_name,
                                   storage_account_key)
        self.queues = QueueStorage(CLOUD_QUEUE_HOST, storage_account_name,
                                   storage_account_key)
        self.storage_account = storage_account_name
        self.data_connection_string = create_data_connection_string(
            storage_account_name, storage_account_key)
예제 #2
0
 def __init__(self,
              blob_host,
              table_host,
              queue_host,
              account_name,
              secret_key,
              use_path_style_uris=True):
     # create local proxies to table, queue and blobs
     self.blob_proxy = BlobStorage(blob_host, account_name, secret_key,
                                   use_path_style_uris)
     self.table_proxy = TableStorage(table_host, account_name, secret_key,
                                     use_path_style_uris)
     self.queue_proxy = QueueStorage(queue_host, account_name, secret_key,
                                     use_path_style_uris)
예제 #3
0
    def __init__(self,
                 storage_account_name=DEVSTORE_ACCOUNT,
                 storage_account_key=None,
                 use_path_style_uris=False,
                 management_cert_path=None,
                 management_key_path=None,
                 subscription_id=None):
        self.storage_account = storage_account_name
        if storage_account_name == DEVSTORE_ACCOUNT:
            blob_host = DEVSTORE_BLOB_HOST
            queue_host = DEVSTORE_QUEUE_HOST
            table_host = DEVSTORE_TABLE_HOST
            if not storage_account_key:
                storage_account_key = DEVSTORE_SECRET_KEY
        else:
            blob_host = CLOUD_BLOB_HOST
            queue_host = CLOUD_QUEUE_HOST
            table_host = CLOUD_TABLE_HOST

        if management_cert_path and subscription_id:
            self.wasm = WASM(management_cert_path, subscription_id,
                             management_key_path)
        else:
            self.wasm = None

        if not storage_account_key:
            if not self.wasm:
                raise WAError('Windows Azure Service Management API ' +
                              'not available.')
            storage_account_key, _, _ = self.wasm.get_storage_account_keys(
                storage_account_name)

        self.blobs = BlobStorage(blob_host, storage_account_name,
                                 storage_account_key, use_path_style_uris)
        self.tables = TableStorage(table_host, storage_account_name,
                                   storage_account_key, use_path_style_uris)
        self.queues = QueueStorage(queue_host, storage_account_name,
                                   storage_account_key, use_path_style_uris)
        self.WAError = WAError
        self.data_connection_string = create_data_connection_string(
            storage_account_name, storage_account_key)