GetPageBlobReference() public method

Gets a reference to a page blob in this container.
public GetPageBlobReference ( string blobAddressUri ) : Microsoft.WindowsAzure.StorageClient.CloudPageBlob
blobAddressUri string The name of the blob, or the absolute URI to the blob.
return Microsoft.WindowsAzure.StorageClient.CloudPageBlob
コード例 #1
0
        public static string MountDrive(string containerName, string vhdName, int driveSize, int driveLocalReadCacheSize)
        {
            var client = GetCloudClientInstance();

            // Create the container for the drive if it does not already exist.
            var container = new CloudBlobContainer(containerName, client);
            if (container.CreateIfNotExist())
            {
                container.SetPermissions(new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessType.Off});
            }

            var cloudDrive = new CloudDrive(container.GetPageBlobReference(vhdName).Uri, client.Credentials);
            try
            {
                cloudDrive.Create(driveSize);
            }
            catch (CloudDriveException ex)
            {
                Logger.Info(string.Format("Cloud drive already exists. Uri: {0}", cloudDrive.Uri), ex);
            }

            string pathToDrive = cloudDrive.Mount(driveLocalReadCacheSize, DriveMountOptions.Force);
            return pathToDrive;
        }
コード例 #2
0
        public void CreateDriveEx()
        {
            try
            {
                CloudBlobClient client = _account.CreateCloudBlobClient();

                // Create the container for the drive if it does not already exist.
                CloudBlobContainer container = new CloudBlobContainer("mydrives", client);
                container.CreateIfNotExist();

                // Get a reference to the page blob that will back the drive.
                CloudPageBlob pageBlob = container.GetPageBlobReference(_vhdName);
                _cloudDrive = new CloudDrive(pageBlob.Uri, _account.Credentials);

                //_cloudDrive = _account.CreateCloudDrive(_vhdName);
                _logger.Log("using account " + _account.BlobEndpoint + " to create " + _vhdName);
                var rv = _cloudDrive.CreateIfNotExist(DISK_SIZE);
                _logger.Log("done create drive");
            }
            catch (Exception ex)
            {
                _logger.Log("error on CreateDrive", ex);
            }
        }
コード例 #3
0
        private void OnInitialize()
        {
            var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf);

            cloudStorageAccount     = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(ConfigurationSettingsKeys.StorageConnectionString));
            log.Info("Storage account selected: {0}",cloudStorageAccount.BlobEndpoint);
            
            cloudBlobClient         = cloudStorageAccount.CreateCloudBlobClient();
            log.Info("Storage client created");

            var containerName       = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageContainerName,"ravendb");

            // In order to force a connection we just enumerate all available containers:
            var availableContainers = cloudBlobClient.ListContainers().ToArray();

            foreach (var container in availableContainers)
            {
                log.Info("Available container: {0}",container.Name);
            }

            if (!availableContainers.Any(c => c.Name.Equals(containerName)))
            {
                log.Info("Container {0} does not exist, creating",containerName);

                // Container does not exist:
                cloudBlobClient.GetContainerReference(containerName).Create();
            }

            cloudBlobContainer      = cloudBlobClient.GetContainerReference(containerName);
            log.Info("Container {0} selected",cloudBlobContainer.Name);

            localCache              = RoleEnvironment.GetLocalResource(ConfigurationSettingsKeys.StorageCacheResource);
            log.Info("Cache resource retrieved: {0}, path: {1}",localCache.Name,localCache.RootPath);
            CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);
            log.Info("Cache initialized: {0} mb",localCache.MaximumSizeInMegabytes);

            var driveName           = string.Format("{0}{1}.vhd", selfInstance.InstanceType, selfInstance.InstanceIndex).ToLowerInvariant();
            log.Info("Virtual drive name: {0}",driveName);
            
            var pageBlob            = cloudBlobContainer.GetPageBlobReference(driveName);
            log.Info("Virtual drive blob: {0}",pageBlob.Uri);

            cloudDrive              = cloudStorageAccount.CreateCloudDrive(pageBlob.Uri.ToString());
            log.Info("Virtual drive created: {0}",cloudDrive.Uri);

            var storageSize         = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageSize, 50000);
            log.Info("Storage size: {0} mb",storageSize);

            cloudDrive.CreateIfNotExist(storageSize);
            log.Info("Virtual drive initialized: {0}",cloudDrive.Uri);

            var mountedDirectoryPath = cloudDrive.Mount(storageSize, DriveMountOptions.None);
            log.Info("Virtual drive mounted at: {0}",mountedDirectoryPath);

            mountedDirectory = new DirectoryInfo(mountedDirectoryPath);

            log.Info("Ensuring drive is available: {0}",mountedDirectoryPath);
            UpdateTestFile();

            log.Info("Storage initialization succeeded");
        }