Top Level Namespace
Defined Under Namespace
Modules: Fog
Constant Summary collapse
- LOCATION =
'eastus'.freeze
- 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 =
2
- UPDATE_DOMAIN_COUNT =
5
- WINDOWS =
'windows'.freeze
- VPN =
'Vpn'.freeze
- MICROSOFT_PEERING =
'MicrosoftPeering'.freeze
- RESOURCE_GROUP_NAME =
4
- RESOURCE_PROVIDER_NAMESPACE =
6
- RESOURCE_TYPE =
7
- RESOURCE_NAME =
8
- ENDPOINT_PREFIX =
'Microsoft.Network/trafficManagerProfiles'.freeze
- DISK_PREFIX =
'Microsoft.Compute/disks'.freeze
- 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
- PRIMARY_NIC_INDEX =
0
- ENVIRONMENT_AZURE_CLOUD =
'AzureCloud'.freeze
- ENVIRONMENT_AZURE_CHINA_CLOUD =
'AzureChinaCloud'.freeze
- ENVIRONMENT_AZURE_US_GOVERNMENT =
'AzureUSGovernment'.freeze
- ENVIRONMENT_AZURE_GERMAN_CLOUD =
'AzureGermanCloud'.freeze
- ERROR_CODE_RESOURCE_NOT_FOUND =
MsRestAzure::AzureOperationError class Error Codes
'ResourceNotFound'.freeze
- ERROR_CODE_NOT_FOUND =
'NotFound'.freeze
- ERROR_CODE_RESOURCE_GROUP_NOT_FOUND =
'ResourceGroupNotFound'.freeze
- ERROR_CODE_PARENT_RESOURCE_NOT_FOUND =
'ParentResourceNotFound'.freeze
- PLATFORM_LINUX =
'linux'.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
- REST_CLIENT_API_VERSION =
%w[2014-04-01-preview 2016-05-01].freeze
- AS_SKU_CLASSIC =
'Classic'.freeze
- AS_SKU_ALIGNED =
'Aligned'.freeze
- TEMPORARY_STORAGE_ACCOUNT_TAG_KEY =
The tag key and tag value for creating a temporary storage account for generalized image
'generalized_image'.freeze
- TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE =
'delete'.freeze
- HTTP_NOT_FOUND =
404
- INSTANCE_VIEW =
'instanceView'.freeze
- WHITE_SPACE =
' '.freeze
Instance Method Summary collapse
- #active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
- #current_time ⇒ Object
- #get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
-
#get_circuit_name_from_id(circuit_id) ⇒ Object
Pick Express Route Circuit name from Id(String).
-
#get_end_point_type(endpoint_type) ⇒ Object
Extract Endpoint type from (String).
- #get_hash_from_object(object) ⇒ Object
- #get_image_name(id) ⇒ Object
- #get_record_set_from_id(id) ⇒ Object
- #get_record_type(type) ⇒ Object
- #get_resource_from_resource_id(resource_id, position) ⇒ Object
-
#get_resource_group_from_id(id) ⇒ Object
Pick Resource Group name from Azure Resource Id(String).
- #get_subscription_id(id) ⇒ Object
-
#get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) ⇒ Object
Extract Traffic Manager Profile Name from Endpoint id(String).
- #get_type_from_recordset_type(type) ⇒ Object
-
#get_virtual_machine_from_id(vme_id) ⇒ Object
Pick Virtual Machine name from Virtual Machine Extension Id(String).
-
#get_virtual_network_from_id(subnet_id) ⇒ Object
Pick Virtual Network name from Subnet Resource Id(String).
-
#parse_storage_object(object) ⇒ Object
Parse storage blob/container to a hash.
- #raise_azure_exception(exception, msg) ⇒ Object
- #random_string(length) ⇒ Object
- #resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
- #resource_not_found?(azure_operation_error) ⇒ Boolean
-
#storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
storage_endpoint_suffix is nil in ms_rest_azure 0.6.2 Reference the issue: github.com/Azure/azure-sdk-for-ruby/issues/603.
-
#validate_params(required_params, input_params) ⇒ Object
Make sure if input_params(Hash) contains all keys present in required_params(Array).
Instance Method Details
#active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fog/azurerm/utilities/general.rb', line 78 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 ⇒ Object
128 129 130 131 |
# File 'lib/fog/azurerm/utilities/general.rb', line 128 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) ⇒ Object
123 124 125 126 |
# File 'lib/fog/azurerm/utilities/general.rb', line 123 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) ⇒ Object
Pick Express Route Circuit name from Id(String)
43 44 45 |
# File 'lib/fog/azurerm/utilities/general.rb', line 43 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)
19 20 21 |
# File 'lib/fog/azurerm/utilities/general.rb', line 19 def get_end_point_type(endpoint_type) endpoint_type.split('/')[2] end |
#get_hash_from_object(object) ⇒ Object
31 32 33 34 35 |
# File 'lib/fog/azurerm/utilities/general.rb', line 31 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) ⇒ Object
180 181 182 |
# File 'lib/fog/azurerm/utilities/general.rb', line 180 def get_image_name(id) id.split('/').last end |
#get_record_set_from_id(id) ⇒ Object
23 24 25 |
# File 'lib/fog/azurerm/utilities/general.rb', line 23 def get_record_set_from_id(id) id.split('/')[8] end |
#get_record_type(type) ⇒ Object
47 48 49 |
# File 'lib/fog/azurerm/utilities/general.rb', line 47 def get_record_type(type) type.split('/').last end |
#get_resource_from_resource_id(resource_id, position) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/fog/azurerm/utilities/general.rb', line 66 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)
4 5 6 |
# File 'lib/fog/azurerm/utilities/general.rb', line 4 def get_resource_group_from_id(id) id.split('/')[4] end |
#get_subscription_id(id) ⇒ Object
184 185 186 |
# File 'lib/fog/azurerm/utilities/general.rb', line 184 def get_subscription_id(id) id.split('/')[2] end |
#get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) ⇒ Object
Extract Traffic Manager Profile Name from Endpoint id(String)
38 39 40 |
# File 'lib/fog/azurerm/utilities/general.rb', line 38 def get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) endpoint_id.split('/')[8] end |
#get_type_from_recordset_type(type) ⇒ Object
27 28 29 |
# File 'lib/fog/azurerm/utilities/general.rb', line 27 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)
14 15 16 |
# File 'lib/fog/azurerm/utilities/general.rb', line 14 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)
9 10 11 |
# File 'lib/fog/azurerm/utilities/general.rb', line 9 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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fog/azurerm/utilities/general.rb', line 134 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
51 52 53 54 55 56 57 58 |
# File 'lib/fog/azurerm/utilities/general.rb', line 51 def raise_azure_exception(exception, msg) raise Fog::AzureRM::CustomAzureCoreHttpError.new(exception) if exception.is_a?(Azure::Core::Http::HTTPError) raise exception unless exception.is_a?(MsRestAzure::AzureOperationError) azure_operation_error = Fog::AzureRM::CustomAzureOperationError.new(msg, exception) azure_operation_error.print_subscription_limits_information if !azure_operation_error.request.nil? && !azure_operation_error.response.nil? raise azure_operation_error end |
#random_string(length) ⇒ Object
74 75 76 |
# File 'lib/fog/azurerm/utilities/general.rb', line 74 def random_string(length) (0...length).map { ('a'..'z').to_a[rand(26)] }.join end |
#resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fog/azurerm/utilities/general.rb', line 91 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) ⇒ Boolean
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/fog/azurerm/utilities/general.rb', line 165 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) ⇒ Object
storage_endpoint_suffix is nil in ms_rest_azure 0.6.2 Reference the issue: github.com/Azure/azure-sdk-for-ruby/issues/603
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fog/azurerm/utilities/general.rb', line 106 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) ⇒ Object
Make sure if input_params(Hash) contains all keys present in required_params(Array)
61 62 63 64 |
# File 'lib/fog/azurerm/utilities/general.rb', line 61 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 |