Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Azure interface #102

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions skylark/obj_store/azure_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os, uuid, time
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__, BlobBlock
from skylark.obj_store.azure_keys import azure_storage_credentials

from skylark.obj_store.object_store_interface import NoSuchObjectException, ObjectStoreInterface, ObjectStoreObject
from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError
Expand All @@ -20,19 +21,15 @@ class AzureInterface(ObjectStoreInterface):
def __init__(self, azure_region, container_name):
# TODO: the azure region should get corresponding os.getenv()
self.azure_region = azure_region
assert self.azure_region in azure_storage_credentials

self.container_name = container_name
self.bucket_name = self.container_name # For compatibility
self.pending_downloads, self.completed_downloads = 0, 0
self.pending_uploads, self.completed_uploads = 0, 0

# Retrieve the connection string for use with the application. The storage
# connection string is stored in an environment variable on the machine
# running the application called AZURE_STORAGE_CONNECTION_STRING. If the environment variable is
# created after the application is launched in a console or with Visual Studio,
# the shell or application needs to be closed and reloaded to take the
# environment variable into account.
self._connect_str = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
# Connection strings are stored in azure_keys.py
self._connect_str = azure_storage_credentials[self.azure_region]["connection_string"]
# Create the BlobServiceClient object which will be used to create a container client
self.blob_service_client = BlobServiceClient.from_connection_string(self._connect_str)

Expand Down
22 changes: 22 additions & 0 deletions skylark/obj_store/azure_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Azure account config
===
Performance: standard
subscription: skylark-azure-paras
redundancy: locally-redundant storage (LRS)
Routing Preferance: Microsoft Network Routing
"""
azure_storage_credentials = {
"eastus": {
"name": "skyeastus",
"connection_string": "DefaultEndpointsProtocol=https;AccountName=skyuseast;AccountKey=BgxPfOR5GB+0SR7B+qIgSly1Ih+M2xfOhtqxornE18N+2MyULBqH1QG7lmro/+o3UncwUuc8m4AduqFY3sC7UA==;EndpointSuffix=core.windows.net",
},
"westus": {
"name": "skyuswest",
"connection_string": "DefaultEndpointsProtocol=https;AccountName=skyuswest;AccountKey=vvBaJdH8ndD65f5VGuUTUSiHzKse82+ogr+1qfaEAXFjtcgm7WAol78eHPNE4liSE/79QrfoMxz3MtgA0iIXNw==;EndpointSuffix=core.windows.net",
},
"centralus": {
"name": "skycentralus",
"connection_string": "DefaultEndpointsProtocol=https;AccountName=skycentralus;AccountKey=xSIiDWw10JZHuS6reLJdzmebxBwctRwpd/hNOJ4C/ciKvy2ez57oRN7ZF5A3ETY495A2wcO+Lutf0feyEdWU2A==;EndpointSuffix=core.windows.net",
},
}
6 changes: 3 additions & 3 deletions skylark/test/test_azure_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


def test_azure_interface():
azure_interface = AzureInterface(f"us-east1", f"sky-us-east-2")
assert azure_interface.bucket_name == "sky-us-east-2"
assert azure_interface.azure_region == "us-east1"
azure_interface = AzureInterface(f"eastus", f"sky-us-east-1")
assert azure_interface.bucket_name == "sky-us-east-1"
assert azure_interface.azure_region == "eastus"
azure_interface.create_bucket()

# generate file and upload
Expand Down