zoukankan      html  css  js  c++  java
  • 【转载】使用VHDUpload上传VHD文件到云存储,并在Azure VM中加挂Azure Drive

    1.上传VHD文件到Azure Blob Storage

    VHDUpload程序的源代码在Windows Azure Training Kit目录Labs\ExploringWindowsAzureStorageVS2010\Source\Assets\VHDUpload,先编译成VHDUpload.exe。然后上传

    Uploads a virtual hard disk (VHD) file to Windows Azure page blob service.

    usage: VHDUPLOAD vhdFilePath blobUri accountName accountKey

      vhdFilePath  - path to virtual hard disk (VHD) file
      blobUri      - destination page blob relative URI (i.e. container/blobname)
      accountName  - storage account name (use devstorage for storage emulator)
      accountKey   - storage account primary key (omit for storage smulator)

    VHDUpload上传过程如下所示:


    2. 自写命令行程序Mount Drive

    主要代码如下(请修改成相应的存储帐户和存储密钥,并编译成EXE):

    [csharp] view plaincopy
    1. class Program  
    2.    {  
    3.        const string sMainStorageName = "StorageAccountName";  
    4.        const string sMainStorageKey = "StorageKey";  
    5.   
    6.        static void Main(string[] args)  
    7.        {  
    8.            string sVHDPathName = string.Empty;  
    9.            string sOperation = string.Empty;  
    10.            bool IfUnmount = false;  
    11.            if (args.Count() == 0)  
    12.            {  
    13.                Console.WriteLine("Syntax: MountAzureDrive ContainerName/Disk.VHD");  
    14.                return;  
    15.            }  
    16.   
    17.            try  
    18.            {  
    19.                sVHDPathName = args[0];  
    20.                if (args.Length > 1)  
    21.                {  
    22.                    sOperation = args[1];  
    23.                    if (args[1] == "/u")  
    24.                        IfUnmount = true;  
    25.                }  
    26.   
    27.                var cloudDriveBlobPath = string.Format("http://{0}.blob.core.windows.net/{1}", sMainStorageName, sVHDPathName);  
    28.                StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(sMainStorageName, sMainStorageKey);  
    29.                // LocalResource localCache = RoleEnvironment.GetLocalResource(sMainLocalStorageName);  
    30.                //  Char[] backSlash = { '\\' };  
    31.                //String localCachePath = localCache.RootPath.TrimEnd(backSlash);  
    32.                //CloudDrive.InitializeCache(localCachePath, localCache.MaximumSizeInMegabytes);  
    33.   
    34.   
    35.                //string cachePath = @"C:\Resources\LocalStorage";   //for VM role  
    36.   
    37.                //Console.WriteLine("Local Cache initialized.....{0}", cachePath);  
    38.                //try  
    39.                //{  
    40.                //    CloudDrive.InitializeCache(cachePath, 10);  
    41.                //}  
    42.                //catch (Exception e)  
    43.                //{  
    44.                //    Console.WriteLine(e.Message);  
    45.                //}  
    46.   
    47.                if (IfUnmount)  
    48.                {  
    49.                    Console.WriteLine("UnMount Drive " + cloudDriveBlobPath);  
    50.                    CloudDrive mountDrive = new CloudDrive(new Uri(cloudDriveBlobPath), credentials);  
    51.   
    52.                    Console.WriteLine("Calling Cloud Drive UnMount API....", 0);  
    53.                    mountDrive.Unmount();  
    54.                    Console.WriteLine("Finished Cloud Drive UnMount .");  
    55.                }  
    56.                else  
    57.                {  
    58.                    Console.WriteLine("Mount Drive " + cloudDriveBlobPath);  
    59.                    CloudDrive mountDrive = new CloudDrive(new Uri(cloudDriveBlobPath), credentials);  
    60.   
    61.                    Console.WriteLine("Calling Cloud Drive Mount API....", 0);  
    62.                    string driveLetter = mountDrive.Mount(0, DriveMountOptions.FixFileSystemErrors | DriveMountOptions.Force);  
    63.                    Console.WriteLine("Finished Cloud Drive Mounting at Drive :" + driveLetter, 0);  
    64.   
    65.                }  
    66.   
    67.            }  
    68.            catch (Exception ex)  
    69.            {  
    70.                Console.WriteLine(ex.Message);  
    71.            }  
    72.        }  
    73.    }  


    3. 在虚拟机里执行Mount动作

    使用上述命令行:


    下图的E盘是Mount之后的效果。(VM Role里实验通过)


    原文:

    http://blog.csdn.net/lihonggen0/article/details/7419738


  • 相关阅读:
    抽象类和接口
    Thread线程
    ArrayList、Vector和LinkedList
    Java并发编程:Callable、Future和FutureTask
    java开发JDBC连接数据库代码
    @Async的简单用法总结
    微信/企业微信的分享功能
    IOS11 底部输入框被手机输入法遮住
    MySQL 数据库设计总结
    Java 多个文件压缩下载
  • 原文地址:https://www.cnblogs.com/dlbrant/p/2430042.html
Copyright © 2011-2022 走看看