Search code examples
rubyazureazure-storagefog

fog-azure-rm: creating Disks fails with uninitialized constant Azure::Core


I'm unable to create the disks in azure. Below are the steps I did to create but it is failing.

Versions:

fog-azure-rm (0.3.2)

ruby version 2.4.0

azure_storage_service = Fog::Storage::AzureRM.new(
  :tenant_id => '<Tenantid>',                                                      
  :client_id =>    '<Clientid>',                                                   
  :client_secret => '<ClientSecret>',                                              
  :subscription_id => '<Subscriptionid>'
)





 azure_storage_service.create_disk('disk_name',1023)

/usr/local/lib/ruby/gems/2.4.0/gems/fog-azure-rm-0.3.2/lib/fog/azurerm/requests/storage/create_page_blob.rb:13:in `rescue in create_page_blob': uninitialized constant Azure::Core (NameError)
    from /usr/local/lib/ruby/gems/2.4.0/gems/fog-azure-rm-0.3.2/lib/fog/azurerm/requests/storage/create_page_blob.rb:11:in `create_page_blob'
    from /usr/local/lib/ruby/gems/2.4.0/gems/fog-azure-rm-0.3.2/lib/fog/azurerm/requests/storage/create_disk.rb:37:in `create_disk'
    from createDisk.rb:12:in `<main>'

Solution

  • First of all, you need to require the Fog library by executing:

    require 'fog/azurerm'
    

    Next, if you use existing storage account, please add storage account and key to the connection. If I remove them from my code, I get same error log with you. The following codes work for me. Please replace * to your value.

    require 'fog/azurerm'
    azure_storage_service = Fog::Storage.new(
      :provider => 'AzureRM',
      :tenant_id => '*****',                                                       # Tenant id of Azure Active Directory Application
      :client_id =>    '*****************',                                                    # Client id of Azure Active Directory Application
      :client_secret => '************',                                               # Client Secret of Azure Active Directory Application
      :subscription_id => '***************',                                           # Subscription id of an Azure Account
      :azure_storage_account_name => 'shuiwindiag907',                            # Name of an Azure Storage Account
      :azure_storage_access_key => '************************',                               # Key of an Azure Storage Account
      :environment => 'AzureCloud' # Azure cloud environment. Default is AzureCloud.
    )
    
    azure_storage_service.create_disk('shui_test',5) ##By default the disk will be created in the container 'vhds'. If the container does not exist, please create it or set options[:container_name].
    

    More information please refer to this link.