Exemple #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)
Exemple #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)
Exemple #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)
Exemple #4
0
class AzureStorage():

    blob_proxy = None
    table_proxy = None
    queue_proxy = None

    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)

    ## blob operations
    def create_container(self, container_name, is_public=False):
        return self.blob_proxy.create_container(container_name, is_public)

    def delete_container(self, container_name):
        return self.blob_proxy.delete_container(container_name)

    def list_containers(self):
        return self.blob_proxy.list_containers()

    def list_blobs(self, container_name):
        return self.blob_proxy.list_blobs(container_name)

    def put_blob(self,
                 container_name,
                 blob_name,
                 data,
                 content_type=None,
                 metadata={}):
        return self.blob_proxy.put_blob(container_name, blob_name, data,
                                        content_type, metadata)

    def set_metadata(self, container_name, blob_name, metadata):
        return self.blob_proxy.set_metadata(container_name, blob_name,
                                            metadata)

    def get_blob(self, container_name, blob_name, offset=None, size=None):
        return self.blob_proxy.get_blob(container_name, blob_name, offset,
                                        size)

    def get_metadata(self, container_name, blob_name):
        return self.blob_proxy.get_metadata(container_name, blob_name)

    def delete_blob(self, container_name, blob_name):
        return self.blob_proxy.delete_blob(container_name, blob_name)

    ## queue operations
    def create_queue(self, name):
        return self.queue_proxy.create_queue(name)

    def delete_queue(self, name):
        return self.queue_proxy.delete_queue(name)

    def put_message(self, queue_name, payload):
        return self.queue_proxy.put_message(queue_name, payload)

    def get_message(self, queue_name):
        return self.queue_proxy.get_message(queue_name)

    def delete_message(self, queue_name, message):
        return self.queue_proxy.delete_message(queue_name, message)

    ## table operations
    def create_table(self, name):
        return self.table_proxy.create_table(name)

    def delete_table(self, name):
        return self.table_proxy.delete_table(name)

    def list_tables(self):
        return self.table_proxy.list_tables()

    def get_entity(self, table_name, partition_key, row_key):
        return self.table_proxy.get_entity(table_name, partition_key, row_key)

    def get_all(self, table_name):
        return self.table_proxy.get_all(table_name)
class AzureStorage():
    
    blob_proxy = None
    table_proxy = None
    queue_proxy = None
    
    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)

    ## blob operations
    def create_container(self, container_name, is_public = False):
        return self.blob_proxy.create_container(container_name, is_public)
        
    def delete_container(self, container_name):
        return self.blob_proxy.delete_container(container_name)
        
    def list_containers(self):
        return self.blob_proxy.list_containers()
        
    def list_blobs(self, container_name):
        self.blob_proxy.list_blobs(container_name)
        
    def put_blob(self, container_name, blob_name, data, content_type = None):
        self.blob_proxy.put_blob(container_name, blob_name, data, content_type)
        
    def get_blob(self, container_name, blob_name):
        return self.blob_proxy.get_blob(container_name, blob_name)
        
    def delete_blob(self, container_name, blob_name):
        return self.blob_proxy.delete_blob(container_name, blob_name)
    
    ## queue operations
    def create_queue(self, name):
        return self.queue_proxy.create_queue(name)
        
    def delete_queue(self, name):
        return self.queue_proxy.delete_queue(name)
        
    def put_message(self, queue_name, payload):
        return self.queue_proxy.put_message(queue_name, payload)
        
    def get_message(self, queue_name):
        return self.queue_proxy.get_message(queue_name)
        
    def delete_message(self, queue_name, message):
        return self.queue_proxy.delete_message(queue_name, message)
    
    ## table operations
    def create_table(self, name):
        return self.table_proxy.create_table(name)
    
    def delete_table(self, name):
        return self.table_proxy.delete_table(name)
    
    def list_tables(self):
        return self.table_proxy.list_tables()
    
    def get_entity(self, table_name, partition_key, row_key):
        return self.table_proxy.get_entity(table_name, partition_key, row_key)
    
    def get_all(self, table_name):
        return self.table_proxy.get_all(table_name)
 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)