class Object

Constants

ALLOWED_STANDARD_REPLICATION
API_VERSION
AS_SKU_ALIGNED
AS_SKU_CLASSIC
AZURE_ENDPOINTS
AZURE_RESOURCE
COPY_STATUS

State of the copy operation

DEFAULT_ADDRESS_PREFIXES
DISK_PREFIX
ENDPOINT_PREFIX
ENVIRONMENT_AZURE_CHINA_CLOUD
ENVIRONMENT_AZURE_CLOUD
ENVIRONMENT_AZURE_GERMAN_CLOUD
ENVIRONMENT_AZURE_US_GOVERNMENT
ERROR_CODE_NOT_FOUND
ERROR_CODE_PARENT_RESOURCE_NOT_FOUND
ERROR_CODE_RESOURCE_GROUP_NOT_FOUND
ERROR_CODE_RESOURCE_NOT_FOUND

MsRestAzure::AzureOperationError class Error Codes

EXTERNAL_ENDPOINTS
FAULT_DOMAIN_COUNT
GLOBAL
HASH_OF_4MB_EMPTY_CONTENT

The hash value of 4MB empty content

HTTP_NOT_FOUND
INSTANCE_VIEW
LOCATION
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

MICROSOFT_PEERING
NESTED_ENDPOINTS
NETWORK_SECURITY_GROUP
PLATFORM_LINUX
PREMIUM_STORAGE
PRIMARY_NIC_INDEX
PUBLIC_IP
RESOURCE_GROUP_NAME
RESOURCE_NAME
RESOURCE_PROVIDER_NAMESPACE
RESOURCE_TYPE
REST_CLIENT_API_VERSION
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.

STANDARD_STORAGE
SUBNET
TEMPORARY_STORAGE_ACCOUNT_TAG_KEY

The tag key and tag value for creating a temporary storage account for generalized image

TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE
UPDATE_DOMAIN_COUNT
UPLOAD_BLOB_WORKER_THREAD_COUNT
VM_NAME_POSITION
VPN
WHITE_SPACE
WINDOWS

Public Instance Methods

active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 75
def active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD)
  case environment
  when ENVIRONMENT_AZURE_CHINA_CLOUD
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings
  when ENVIRONMENT_AZURE_US_GOVERNMENT
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings
  when ENVIRONMENT_AZURE_GERMAN_CLOUD
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_german_settings
  else
    MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
  end
end
current_time() click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 125
def current_time
  time = Time.now.to_f.to_s
  time.split(/\W+/).join
end
get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 120
def get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD)
  protocol = enable_https ? 'https' : 'http'
  "#{protocol}://#{storage_account_name}.blob#{storage_endpoint_suffix(environment)}"
end
get_circuit_name_from_id(circuit_id) click to toggle source

Pick Express Route Circuit name from Id(String)

# File lib/fog/azurerm/utilities/general.rb, line 41
def get_circuit_name_from_id(circuit_id)
  circuit_id.split('/')[8]
end
get_end_point_type(endpoint_type) click to toggle source

Extract Endpoint type from (String)

# 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) click to toggle source
# 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_image_name(id) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 177
def get_image_name(id)
  id.split('/').last
end
get_record_set_from_id(id) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 21
def get_record_set_from_id(id)
  id.split('/')[8]
end
get_record_type(type) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 45
def get_record_type(type)
  type.split('/').last
end
get_resource_from_resource_id(resource_id, position) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 63
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) click to toggle source

Pick Resource Group name from Azure Resource Id(String)

# File lib/fog/azurerm/utilities/general.rb, line 2
def get_resource_group_from_id(id)
  id.split('/')[4]
end
get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) click to toggle source

Extract Traffic Manager Profile Name from Endpoint id(String)

# 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) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source

Pick Virtual Network name from Subnet Resource Id(String)

# 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) click to toggle source

Parse storage blob/container to a hash

# File lib/fog/azurerm/utilities/general.rb, line 131
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) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 49
def raise_azure_exception(exception, msg)
  description = exception.is_a?(Azure::Core::Http::HTTPError) ? exception.description : exception.error_message
  exception_message = "Exception in #{msg} #{description} Type: #{exception.class}\n#{exception.backtrace.join('\n')}"

  Fog::Logger.debug exception.backtrace
  raise exception_message
end
random_string(length) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 71
def random_string(length)
  (0...length).map { ('a'..'z').to_a[rand(26)] }.join
end
resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 88
def resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD)
  case environment
  when ENVIRONMENT_AZURE_CHINA_CLOUD
    MsRestAzure::AzureEnvironments::AzureChina.resource_manager_endpoint_url
  when ENVIRONMENT_AZURE_US_GOVERNMENT
    MsRestAzure::AzureEnvironments::AzureUSGovernment.resource_manager_endpoint_url
  when ENVIRONMENT_AZURE_GERMAN_CLOUD
    MsRestAzure::AzureEnvironments::AzureGermanCloud.resource_manager_endpoint_url
  else
    MsRestAzure::AzureEnvironments::Azure.resource_manager_endpoint_url
  end
end
resource_not_found?(azure_operation_error) click to toggle source
# File lib/fog/azurerm/utilities/general.rb, line 162
def resource_not_found?(azure_operation_error)
  is_found = false
  if azure_operation_error.response.status == HTTP_NOT_FOUND
    if azure_operation_error.body['code']
      is_found = azure_operation_error.body['code'] == ERROR_CODE_NOT_FOUND
    elsif azure_operation_error.body['error']
      is_found = azure_operation_error.body['error']['code'] == ERROR_CODE_NOT_FOUND ||
                 azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_GROUP_NOT_FOUND ||
                 azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_NOT_FOUND ||
                 azure_operation_error.body['error']['code'] == ERROR_CODE_PARENT_RESOURCE_NOT_FOUND
    end
  end
  is_found
end
storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD) click to toggle source

storage_endpoint_suffix is nil in ms_rest_azure 0.6.2 Reference the issue: github.com/Azure/azure-sdk-for-ruby/issues/603

# File lib/fog/azurerm/utilities/general.rb, line 103
def storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD)
  case environment
  when ENVIRONMENT_AZURE_CHINA_CLOUD
    # MsRestAzure::AzureEnvironments::AzureChina.storage_endpoint_suffix
    '.core.chinacloudapi.cn'
  when ENVIRONMENT_AZURE_US_GOVERNMENT
    # MsRestAzure::AzureEnvironments::AzureUSGovernment.storage_endpoint_suffix
    '.core.usgovcloudapi.net'
  when ENVIRONMENT_AZURE_GERMAN_CLOUD
    # MsRestAzure::AzureEnvironments::AzureGermanCloud.storage_endpoint_suffix
    '.core.cloudapi.de'
  else
    # MsRestAzure::AzureEnvironments::Azure.storage_endpoint_suffix
    '.core.windows.net'
  end
end
validate_params(required_params, input_params) click to toggle source

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

# File lib/fog/azurerm/utilities/general.rb, line 58
def validate_params(required_params, input_params)
  missing_params = required_params.select { |param| param unless input_params.key?(param) }
  raise(ArgumentError, "Missing Parameters: #{missing_params.join(', ')} required for this operation") if missing_params.any?
end