Top Level Namespace

Defined Under Namespace

Modules: Fog

Constant Summary collapse

AZURE_RESOURCE =
'https://management.azure.com'.freeze
DEFAULT_ADDRESS_PREFIXES =
['10.2.0.0/16'].freeze
SUBNET =
'Subnet'.freeze
PUBLIC_IP =
'Public-IP-Address'.freeze
NETWORK_SECURITY_GROUP =
'Network-Security-Group'.freeze
STANDARD_STORAGE =
'Standard'.freeze
PREMIUM_STORAGE =
'Premium'.freeze
ALLOWED_STANDARD_REPLICATION =
%w(LRS ZRS GRS RAGRS).freeze
API_VERSION =
'2016-06-01'.freeze
FAULT_DOMAIN_COUNT =
3.freeze
UPDATE_DOMAIN_COUNT =
5.freeze
WINDOWS =
'windows'.freeze
VPN =
'Vpn'.freeze
MICROSOFT_PEERING =
'MicrosoftPeering'.freeze
RESOURCE_GROUP_NAME =
4
RESOURCE_PROVIDER_NAMESPACE =
6
RESOURCE_TYPE =
7
RESOURCE_NAME =
8
AZURE_ENDPOINTS =
'azureEndpoints'.freeze
EXTERNAL_ENDPOINTS =
'externalEndpoints'.freeze
NESTED_ENDPOINTS =
'nestedEndpoints'.freeze
GLOBAL =
'global'.freeze
UPLOAD_BLOB_WORKER_THREAD_COUNT =
8
VM_NAME_POSITION =
8
CLOUD =

Set a CLOUD value from ‘Azure’, ‘AzureChina’, ‘AzureGermanCloud’ and ‘AzureUSGovernment’

'Azure'.freeze
AZURE_GLOBAL_RM_ENDPOINT_URL =
'https://management.azure.com/'.freeze
AZURE_CHINA_RM_ENDPOINT_URL =
'https://management.chinacloudapi.cn'.freeze
GERMAN_CLOUD_RM_ENDPOINT_URL =
'https://management.microsoftazure.de'.freeze
US_GOVERNMENT_RM_ENDPOINT_URL =
'https://management.usgovcloudapi.net'.freeze
LOCATION =
'eastus'.freeze
COPY_STATUS =

State of the copy operation

{
  # The copy completed successfully.
  SUCCESS: 'success',
  # The copy is in progress
  PENDING: 'pending'
}.freeze
SINGLE_BLOB_PUT_THRESHOLD =

msdn.microsoft.com/en-us/library/azure/dd179451.aspx The maximum size for a block blob created via Put Blob is 64 MB. But for better performance, this size should be 32 MB. If your blob is larger than 32 MB, you must upload it as a set of blocks.

32 * 1024 * 1024
MAXIMUM_CHUNK_SIZE =

Block blob: msdn.microsoft.com/en-us/library/azure/dd135726.aspx Page blob: msdn.microsoft.com/en-us/library/azure/ee691975.aspx Each block/page can be a different size, up to a maximum of 4 MB

4 * 1024 * 1024
HASH_OF_4MB_EMPTY_CONTENT =

The hash value of 4MB empty content

'b5cfa9d6c8febd618f91ac2843d50a1c'.freeze
IAAS_VM_BACKUP_REQUEST =
'IaasVMBackupRequest'.freeze
WHITE_SPACE =
' '.freeze
CONFIGURE_BACKUP =
'ConfigureBackup'.freeze
PROTECTION_STOPPED =
'ProtectionStopped'.freeze

Instance Method Summary collapse

Instance Method Details

#active_directory_service_settingsObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fog/azurerm/utilities/general.rb', line 89

def active_directory_service_settings
  case CLOUD
  when 'AzureChina'
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings
  when 'AzureGermanCloud'
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_german_settings
  when 'AzureUSGovernment'
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings
  else
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
  end
end

#current_timeObject



115
116
117
118
# File 'lib/fog/azurerm/utilities/general.rb', line 115

def current_time
  time = Time.now.to_f.to_s
  time.split(/\W+/).join
end


85
86
87
# File 'lib/fog/azurerm/utilities/general.rb', line 85

def get_blob_link()
  "http://#{}.blob.core.windows.net"
end

#get_circuit_name_from_id(circuit_id) ⇒ Object

Pick Express Route Circuit name from Id(String)



46
47
48
# File 'lib/fog/azurerm/utilities/general.rb', line 46

def get_circuit_name_from_id(circuit_id)
  circuit_id.split('/')[8]
end

#get_end_point_type(endpoint_type) ⇒ Object

Extract Endpoint type from (String)



17
18
19
# File 'lib/fog/azurerm/utilities/general.rb', line 17

def get_end_point_type(endpoint_type)
  endpoint_type.split('/')[2]
end

#get_hash_from_object(object) ⇒ Object



29
30
31
32
33
# File 'lib/fog/azurerm/utilities/general.rb', line 29

def get_hash_from_object(object)
  hash = {}
  object.instance_variables.each { |attr| hash[attr.to_s.delete('@')] = object.instance_variable_get(attr) }
  hash
end

#get_record_set_from_id(id) ⇒ Object



21
22
23
# File 'lib/fog/azurerm/utilities/general.rb', line 21

def get_record_set_from_id(id)
  id.split('/')[8]
end

#get_record_type(type) ⇒ Object



50
51
52
# File 'lib/fog/azurerm/utilities/general.rb', line 50

def get_record_type(type)
  type.split('/').last
end

#get_resource_from_resource_id(resource_id, position) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/fog/azurerm/utilities/general.rb', line 73

def get_resource_from_resource_id(resource_id, position)
  data = resource_id.split('/') unless resource_id.nil?

  raise 'Invalid Resource ID' if data.count < 9 && data.count != 5

  data[position]
end

#get_resource_group_from_id(id) ⇒ Object

Pick Resource Group name from Azure Resource Id(String)



2
3
4
# File 'lib/fog/azurerm/utilities/general.rb', line 2

def get_resource_group_from_id(id)
  id.split('/')[4]
end

#get_server_name_from_id(database_id) ⇒ Object

Get server name from ID (String)



41
42
43
# File 'lib/fog/azurerm/utilities/general.rb', line 41

def get_server_name_from_id(database_id)
  database_id.split('/')[8]
end

#get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) ⇒ Object

Extract Traffic Manager Profile Name from Endpoint id(String)



36
37
38
# File 'lib/fog/azurerm/utilities/general.rb', line 36

def get_traffic_manager_profile_name_from_endpoint_id(endpoint_id)
  endpoint_id.split('/')[8]
end

#get_type_from_recordset_type(type) ⇒ Object



25
26
27
# File 'lib/fog/azurerm/utilities/general.rb', line 25

def get_type_from_recordset_type(type)
  type.split('/')[2]
end

#get_virtual_machine_from_id(vme_id) ⇒ Object

Pick Virtual Machine name from Virtual Machine Extension Id(String)



12
13
14
# File 'lib/fog/azurerm/utilities/general.rb', line 12

def get_virtual_machine_from_id(vme_id)
  vme_id.split('/')[VM_NAME_POSITION]
end

#get_virtual_network_from_id(subnet_id) ⇒ Object

Pick Virtual Network name from Subnet Resource Id(String)



7
8
9
# File 'lib/fog/azurerm/utilities/general.rb', line 7

def get_virtual_network_from_id(subnet_id)
  subnet_id.split('/')[8]
end

#parse_storage_object(object) ⇒ Object

Parse storage blob/container to a hash



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/fog/azurerm/utilities/general.rb', line 121

def parse_storage_object(object)
  data = {}
  if object.is_a? Hash
    object.each do |k, v|
      if k == 'properties'
        v.each do |j, l|
          data[j] = l
        end
      else
        data[k] = v
      end
    end
  else
    object.instance_variables.each do |p|
      kname = p.to_s.delete('@')
      if kname == 'properties'
        properties = object.instance_variable_get(p)
        properties.each do |k, v|
          data[k.to_s] = v
        end
      else
        data[kname] = object.instance_variable_get(p)
      end
    end
  end

  data['last_modified'] = Time.parse(data['last_modified'])
  data['etag'].delete!('"')
  data
end

#raise_azure_exception(exception, msg) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/fog/azurerm/utilities/general.rb', line 54

def raise_azure_exception(exception, msg)
  message = if exception.respond_to? 'body'
              "Exception in #{msg} #{exception.body['error']['message'] unless exception.body['error']['message'].nil?} Type: #{exception.class}\n#{exception.backtrace.join("\n")}"
            else
              "#{exception.inspect}\n#{exception.backtrace.join("\n")}"
            end
  Fog::Logger.debug exception.backtrace
  raise message
end

#random_string(length) ⇒ Object



81
82
83
# File 'lib/fog/azurerm/utilities/general.rb', line 81

def random_string(length)
  (0...length).map { ('a'..'z').to_a[rand(26)] }.join
end

#resource_manager_endpoint_urlObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fog/azurerm/utilities/general.rb', line 102

def resource_manager_endpoint_url
  case CLOUD
  when 'AzureChina'
    AZURE_CHINA_RM_ENDPOINT_URL
  when 'AzureGermanCloud'
    GERMAN_CLOUD_RM_ENDPOINT_URL
  when 'AzureUSGovernment'
    US_GOVERNMENT_RM_ENDPOINT_URL
  else
    AZURE_GLOBAL_RM_ENDPOINT_URL
  end
end

#validate_params(required_params, input_params) ⇒ Object

Make sure if input_params(Hash) contains all keys present in required_params(Array)



65
66
67
68
69
70
71
# File 'lib/fog/azurerm/utilities/general.rb', line 65

def validate_params(required_params, input_params)
  missing_params = required_params.select { |param| param unless input_params.key?(param) }

  if missing_params.any?
    raise(ArgumentError, "Missing Parameters: #{missing_params.join(', ')} required for this operation")
  end
end