# encoding: utf-8 # Code generated by Microsoft (R) AutoRest Code Generator 0.11.0.0 # Changes may cause incorrect behavior and will be lost if the code is # regenerated. module Azure::ARM::Compute # # VirtualMachineImages # class VirtualMachineImages include Azure::ARM::Compute::Models include MsRestAzure # # Creates and initializes a new instance of the VirtualMachineImages class. # @param client service class for accessing basic functionality. # def initialize(client) @client = client end # @return reference to the ComputeManagementClient attr_reader :client # # Gets a virtual machine image. # @param location [String] # @param publisher_name [String] # @param offer [String] # @param skus [String] # @param version [String] # @param [Hash{String => String}] The hash of custom headers need to be # applied to HTTP request. # # @return [Concurrent::Promise] Promise object which allows to get HTTP # response. # def get(location, publisher_name, offer, skus, version, custom_headers = nil) fail ArgumentError, 'location is nil' if location.nil? fail ArgumentError, 'publisher_name is nil' if publisher_name.nil? fail ArgumentError, 'offer is nil' if offer.nil? fail ArgumentError, 'skus is nil' if skus.nil? fail ArgumentError, 'version is nil' if version.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? # Construct URL path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions/{version}" path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}') path['{publisherName}'] = ERB::Util.url_encode(publisher_name) if path.include?('{publisherName}') path['{offer}'] = ERB::Util.url_encode(offer) if path.include?('{offer}') path['{skus}'] = ERB::Util.url_encode(skus) if path.include?('{skus}') path['{version}'] = ERB::Util.url_encode(version) if path.include?('{version}') path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}') url = URI.join(@client.base_url, path) properties = {} properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil? unless url.query.nil? url.query.split('&').each do |url_item| url_items_parts = url_item.split('=') properties[url_items_parts[0]] = url_items_parts[1] end end properties.reject!{ |key, value| value.nil? } url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&') fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/') url = URI.parse(corrected_url) connection = Faraday.new(:url => url) do |faraday| faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02 faraday.use :cookie_jar faraday.adapter Faraday.default_adapter end request_headers = Hash.new # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil? unless custom_headers.nil? custom_headers.each do |key, value| request_headers[key] = value end end # Send Request promise = Concurrent::Promise.new do connection.get do |request| request.headers = request_headers @client.credentials.sign_request(request) unless @client.credentials.nil? end end promise = promise.then do |http_response| status_code = http_response.status response_content = http_response.body unless (status_code == 200) error_model = JSON.load(response_content) fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model) end # Create Result result = MsRestAzure::AzureOperationResponse.new(connection, http_response) result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = JSON.load(response_content) unless response_content.to_s.empty? unless parsed_response.nil? parsed_response = VirtualMachineImage.deserialize_object(parsed_response) end result.body = parsed_response rescue Exception => e fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content) end end result end promise.execute end # # Gets a list of virtual machine image offers. # @param location [String] # @param publisher_name [String] # @param [Hash{String => String}] The hash of custom headers need to be # applied to HTTP request. # # @return [Concurrent::Promise] Promise object which allows to get HTTP # response. # def list_offers(location, publisher_name, custom_headers = nil) fail ArgumentError, 'location is nil' if location.nil? fail ArgumentError, 'publisher_name is nil' if publisher_name.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? # Construct URL path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers" path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}') path['{publisherName}'] = ERB::Util.url_encode(publisher_name) if path.include?('{publisherName}') path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}') url = URI.join(@client.base_url, path) properties = {} properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil? unless url.query.nil? url.query.split('&').each do |url_item| url_items_parts = url_item.split('=') properties[url_items_parts[0]] = url_items_parts[1] end end properties.reject!{ |key, value| value.nil? } url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&') fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/') url = URI.parse(corrected_url) connection = Faraday.new(:url => url) do |faraday| faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02 faraday.use :cookie_jar faraday.adapter Faraday.default_adapter end request_headers = Hash.new # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil? unless custom_headers.nil? custom_headers.each do |key, value| request_headers[key] = value end end # Send Request promise = Concurrent::Promise.new do connection.get do |request| request.headers = request_headers @client.credentials.sign_request(request) unless @client.credentials.nil? end end promise = promise.then do |http_response| status_code = http_response.status response_content = http_response.body unless (status_code == 200) error_model = JSON.load(response_content) fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model) end # Create Result result = MsRestAzure::AzureOperationResponse.new(connection, http_response) result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = JSON.load(response_content) unless response_content.to_s.empty? unless parsed_response.nil? deserializedArray = []; parsed_response.each do |element| unless element.nil? element = VirtualMachineImageResource.deserialize_object(element) end deserializedArray.push(element); end parsed_response = deserializedArray; end result.body = parsed_response rescue Exception => e fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content) end end result end promise.execute end # # Gets a list of virtual machine image publishers. # @param location [String] # @param [Hash{String => String}] The hash of custom headers need to be # applied to HTTP request. # # @return [Concurrent::Promise] Promise object which allows to get HTTP # response. # def list_publishers(location, custom_headers = nil) fail ArgumentError, 'location is nil' if location.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? # Construct URL path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers" path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}') path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}') url = URI.join(@client.base_url, path) properties = {} properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil? unless url.query.nil? url.query.split('&').each do |url_item| url_items_parts = url_item.split('=') properties[url_items_parts[0]] = url_items_parts[1] end end properties.reject!{ |key, value| value.nil? } url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&') fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/') url = URI.parse(corrected_url) connection = Faraday.new(:url => url) do |faraday| faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02 faraday.use :cookie_jar faraday.adapter Faraday.default_adapter end request_headers = Hash.new # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil? unless custom_headers.nil? custom_headers.each do |key, value| request_headers[key] = value end end # Send Request promise = Concurrent::Promise.new do connection.get do |request| request.headers = request_headers @client.credentials.sign_request(request) unless @client.credentials.nil? end end promise = promise.then do |http_response| status_code = http_response.status response_content = http_response.body unless (status_code == 200) error_model = JSON.load(response_content) fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model) end # Create Result result = MsRestAzure::AzureOperationResponse.new(connection, http_response) result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = JSON.load(response_content) unless response_content.to_s.empty? unless parsed_response.nil? deserializedArray = []; parsed_response.each do |element| unless element.nil? element = VirtualMachineImageResource.deserialize_object(element) end deserializedArray.push(element); end parsed_response = deserializedArray; end result.body = parsed_response rescue Exception => e fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content) end end result end promise.execute end # # Gets a list of virtual machine image skus. # @param location [String] # @param publisher_name [String] # @param offer [String] # @param [Hash{String => String}] The hash of custom headers need to be # applied to HTTP request. # # @return [Concurrent::Promise] Promise object which allows to get HTTP # response. # def list_skus(location, publisher_name, offer, custom_headers = nil) fail ArgumentError, 'location is nil' if location.nil? fail ArgumentError, 'publisher_name is nil' if publisher_name.nil? fail ArgumentError, 'offer is nil' if offer.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? # Construct URL path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus" path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}') path['{publisherName}'] = ERB::Util.url_encode(publisher_name) if path.include?('{publisherName}') path['{offer}'] = ERB::Util.url_encode(offer) if path.include?('{offer}') path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}') url = URI.join(@client.base_url, path) properties = {} properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil? unless url.query.nil? url.query.split('&').each do |url_item| url_items_parts = url_item.split('=') properties[url_items_parts[0]] = url_items_parts[1] end end properties.reject!{ |key, value| value.nil? } url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&') fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/') url = URI.parse(corrected_url) connection = Faraday.new(:url => url) do |faraday| faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02 faraday.use :cookie_jar faraday.adapter Faraday.default_adapter end request_headers = Hash.new # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil? unless custom_headers.nil? custom_headers.each do |key, value| request_headers[key] = value end end # Send Request promise = Concurrent::Promise.new do connection.get do |request| request.headers = request_headers @client.credentials.sign_request(request) unless @client.credentials.nil? end end promise = promise.then do |http_response| status_code = http_response.status response_content = http_response.body unless (status_code == 200) error_model = JSON.load(response_content) fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model) end # Create Result result = MsRestAzure::AzureOperationResponse.new(connection, http_response) result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = JSON.load(response_content) unless response_content.to_s.empty? unless parsed_response.nil? deserializedArray = []; parsed_response.each do |element| unless element.nil? element = VirtualMachineImageResource.deserialize_object(element) end deserializedArray.push(element); end parsed_response = deserializedArray; end result.body = parsed_response rescue Exception => e fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content) end end result end promise.execute end # # Gets a list of virtual machine images. # @param location [String] # @param publisher_name [String] # @param offer [String] # @param skus [String] # @param filter [String] The filter to apply on the operation. # @param top [Integer] # @param orderby [String] # @param [Hash{String => String}] The hash of custom headers need to be # applied to HTTP request. # # @return [Concurrent::Promise] Promise object which allows to get HTTP # response. # def list(location, publisher_name, offer, skus, filter = nil, top = nil, orderby = nil, custom_headers = nil) fail ArgumentError, 'location is nil' if location.nil? fail ArgumentError, 'publisher_name is nil' if publisher_name.nil? fail ArgumentError, 'offer is nil' if offer.nil? fail ArgumentError, 'skus is nil' if skus.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? # Construct URL path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions" path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}') path['{publisherName}'] = ERB::Util.url_encode(publisher_name) if path.include?('{publisherName}') path['{offer}'] = ERB::Util.url_encode(offer) if path.include?('{offer}') path['{skus}'] = ERB::Util.url_encode(skus) if path.include?('{skus}') path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}') url = URI.join(@client.base_url, path) properties = {} properties['$filter'] = ERB::Util.url_encode(filter.to_s) unless filter.nil? properties['$top'] = ERB::Util.url_encode(top.to_s) unless top.nil? properties['$orderby'] = ERB::Util.url_encode(orderby.to_s) unless orderby.nil? properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil? unless url.query.nil? url.query.split('&').each do |url_item| url_items_parts = url_item.split('=') properties[url_items_parts[0]] = url_items_parts[1] end end properties.reject!{ |key, value| value.nil? } url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&') fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/') url = URI.parse(corrected_url) connection = Faraday.new(:url => url) do |faraday| faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02 faraday.use :cookie_jar faraday.adapter Faraday.default_adapter end request_headers = Hash.new # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil? unless custom_headers.nil? custom_headers.each do |key, value| request_headers[key] = value end end # Send Request promise = Concurrent::Promise.new do connection.get do |request| request.headers = request_headers @client.credentials.sign_request(request) unless @client.credentials.nil? end end promise = promise.then do |http_response| status_code = http_response.status response_content = http_response.body unless (status_code == 200) error_model = JSON.load(response_content) fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model) end # Create Result result = MsRestAzure::AzureOperationResponse.new(connection, http_response) result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = JSON.load(response_content) unless response_content.to_s.empty? unless parsed_response.nil? deserializedArray = []; parsed_response.each do |element| unless element.nil? element = VirtualMachineImageResource.deserialize_object(element) end deserializedArray.push(element); end parsed_response = deserializedArray; end result.body = parsed_response rescue Exception => e fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content) end end result end promise.execute end end end