1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge branch 'master' into db_grant_access

This commit is contained in:
Evan Light 2014-08-11 16:41:50 -04:00
commit 1a934826f6
157 changed files with 2963 additions and 407 deletions

View file

@ -35,7 +35,7 @@ module Fog
def get(key, &block)
requires :directory
data = service.get_namespace(directory.key + key, :parse => false)#, &block)
data = service.get_namespace(directory.key + key, :parse => false, &block)
file_data = data.headers.merge({
:body => data.body,
:key => key

View file

@ -2,8 +2,13 @@ module Fog
module Storage
class Atmos
class Real
def get_namespace(namespace = '', options = {})
def get_namespace(namespace = '', options = {}, &block)
options = options.reject {|key, value| value.nil?}
if block_given?
options[:response_block] = Proc.new
end
request({
:expects => 200,
:method => 'GET',

View file

@ -6,7 +6,7 @@ module Fog
def reset
@block_device_mapping = {}
@context = []
@contexts = ['blockDeviceMapping', 'groupSet', 'iamInstanceProfile']
@contexts = ['blockDeviceMapping', 'groupSet', 'iamInstanceProfile', 'networkInterfaceSet']
@spot_instance_request = { 'launchSpecification' => { 'iamInstanceProfile' => {}, 'blockDeviceMapping' => [], 'groupSet' => [] } }
@response = { 'spotInstanceRequestSet' => [] }
end
@ -34,7 +34,9 @@ module Fog
when 'deviceName', 'status', 'volumeId'
@block_device_mapping[name] = value
when 'groupId'
@spot_instance_request['launchSpecification']['groupSet'] << value
if !@context.include?('networkInterfaceSet')
@spot_instance_request['launchSpecification']['groupSet'] << value
end
when 'arn', 'name'
@spot_instance_request['launchSpecification']['iamInstanceProfile'][name] = value
when 'instanceId', 'launchedAvailabilityZone', 'productDescription', 'spotInstanceRequestId', 'state', 'type'

View file

@ -146,6 +146,9 @@ module Fog
elsif state_reason_key = filter_key.split('state-reason-')[1]
aliased_key = state_reason_aliases[state_reason_key]
instance_set = instance_set.reject{|instance| ![*filter_value].include?(instance['stateReason'][aliased_key])}
elsif filter_key == "availability-zone"
aliased_key = aliases[filter_key]
instance_set = instance_set.reject{|instance| ![*filter_value].include?(instance['placement'][aliased_key])}
elsif filter_key == "group-name"
instance_set = instance_set.reject {|instance| !instance['groupSet'].include?(filter_value)}
elsif filter_key == "group-id"

View file

@ -65,12 +65,13 @@ module Fog
@dynect_password = options[:dynect_password]
@connection_options = options[:connection_options] || {}
@host = 'api-v4.dynect.net'
@port = options[:port] || 443
@path = options[:path] || '/REST'
@persistent = options[:persistent] || false
@scheme = options[:scheme] || 'https'
@version = options[:version] || '3.5.2'
@host = 'api-v4.dynect.net'
@port = options[:port] || 443
@path = options[:path] || '/REST'
@persistent = options[:persistent] || false
@scheme = options[:scheme] || 'https'
@version = options[:version] || '3.5.2'
@job_poll_timeout = options[:job_poll_timeout] || 10
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
@ -102,7 +103,7 @@ module Fog
end
if response.status == 307 && params[:path] !~ %r{^/REST/Job/}
response = poll_job(response, params[:expects])
response = poll_job(response, params[:expects], @job_poll_timeout)
end
response
@ -118,9 +119,9 @@ module Fog
response
end
def poll_job(response, original_expects, time_to_wait = 10)
def poll_job(response, original_expects, time_to_wait)
job_location = response.headers['Location']
begin
Fog.wait_for(time_to_wait) do
response = request(
@ -131,7 +132,7 @@ module Fog
)
response.body['status'] != 'incomplete'
end
rescue Errors::TimeoutError => error
if response.body['status'] == 'incomplete'
raise JobIncomplete.new("Job #{response.body['job_id']} is still incomplete")

View file

@ -6,6 +6,12 @@ module Fog
requires :google_project
recognizes :app_name, :app_version, :google_client_email, :google_key_location, :google_key_string, :google_client
GOOGLE_COMPUTE_API_VERSION = 'v1'
GOOGLE_COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/'
GOOGLE_COMPUTE_API_SCOPE_URLS = %w(https://www.googleapis.com/auth/compute
https://www.googleapis.com/auth/devstorage.read_write)
GOOGLE_COMPUTE_DEFAULT_NETWORK = 'default'
request_path 'fog/google/requests/compute'
request :list_servers
request :list_aggregated_servers
@ -159,52 +165,11 @@ module Fog
model :backend_service
collection :backend_services
module Shared
attr_reader :project, :api_version
def shared_initialize(options = {})
@project = options[:google_project]
@api_version = 'v1'
base_url = 'https://www.googleapis.com/compute/'
@api_url = base_url + api_version + '/projects/'
@default_network = 'default'
end
def build_excon_response(body, status=200)
response = Excon::Response.new
response.body = body
if response.body and response.body["error"]
response.status = response.body["error"]["code"]
if response.body["error"]["errors"]
msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ")
else
msg = "Error [#{response.body["error"]["code"]}]: #{response.body["error"]["message"] || "GCE didn't return an error message"}"
end
case response.status
when 404
raise Fog::Errors::NotFound.new(msg)
else
raise Fog::Errors::Error.new(msg)
end
else
response.status = status
end
response
end
end
class Mock
include Collections
include Shared
include Fog::Google::Shared
def initialize(options={})
shared_initialize(options)
end
def build_response(params={})
body = params[:body] || {}
build_excon_response(body)
def initialize(options)
shared_initialize(options[:google_project], GOOGLE_COMPUTE_API_VERSION, GOOGLE_COMPUTE_BASE_URL)
end
def self.data(api_version)
@ -853,119 +818,18 @@ module Fog
end
class Real
include Collections
include Shared
include Fog::Google::Shared
attr_accessor :client
attr_reader :compute, :api_url
attr_reader :compute
def initialize(options)
# NOTE: loaded here to avoid requiring this as a core Fog dependency
begin
require 'google/api_client'
rescue LoadError => error
Fog::Logger.warning("Please install the google-api-client gem before using this provider.")
raise error
end
shared_initialize(options)
if !options[:google_client].nil?
@client = options[:google_client]
end
if @client.nil?
if !options[:google_key_location].nil?
google_key = File.expand_path(options[:google_key_location])
elsif !options[:google_key_string].nil?
google_key = options[:google_key_string]
end
if !options[:google_client_email].nil? and !google_key.nil?
@client = self.new_pk12_google_client(
options[:google_client_email],
google_key,
options[:app_name],
options[:app_verion])
else
Fog::Logger.debug("Fog::Compute::Google.client has not been initialized nor are the :google_client_email and :google_key_location or :google_key_string options set, so we can not create one for you.")
raise ArgumentError.new("No Google API Client has been initialized.")
end
end
# We want to always mention we're using Fog.
if @client.user_agent.nil? or @client.user_agent.empty?
@client.user_agent = ""
elsif !@client.user_agent.include? "fog"
@client.user_agent += "fog/#{Fog::VERSION}"
end
shared_initialize(options[:google_project], GOOGLE_COMPUTE_API_VERSION, GOOGLE_COMPUTE_BASE_URL)
options.merge!(:google_api_scope_url => GOOGLE_COMPUTE_API_SCOPE_URLS.join(' '))
@client = initialize_google_client(options)
@compute = @client.discovered_api('compute', api_version)
end
# Public: Create a Google::APIClient with a pkcs12 key and a user email.
#
# google_client_email - an @developer.gserviceaccount.com email address to use.
# google_key - an absolute location to a pkcs12 key file or the content of the file itself.
# app_name - an optional string to set as the app name in the user agent.
# app_version - an optional string to set as the app version in the user agent.
#
# Returns a new Google::APIClient
def new_pk12_google_client(google_client_email, google_key, app_name=nil, app_version=nil)
# The devstorage scope is needed to be able to insert images
# devstorage.read_only scope is not sufficient like you'd hope
api_scope_url = 'https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/devstorage.read_write'
user_agent = ""
if app_name
user_agent = "#{app_name}/#{app_version || '0.0.0'} "
end
user_agent += "fog/#{Fog::VERSION}"
api_client_options = {
# https://github.com/google/google-api-ruby-client/blob/master/lib/google/api_client.rb#L98
:application_name => "suppress warning",
# https://github.com/google/google-api-ruby-client/blob/master/lib/google/api_client.rb#L100
:user_agent => user_agent
}
local_client = ::Google::APIClient.new(api_client_options)
key = ::Google::APIClient::KeyUtils.load_from_pkcs12(google_key, 'notasecret')
local_client.authorization = Signet::OAuth2::Client.new({
:audience => 'https://accounts.google.com/o/oauth2/token',
:auth_provider_x509_cert_url => "https://www.googleapis.com/oauth2/v1/certs",
:client_x509_cert_url => "https://www.googleapis.com/robot/v1/metadata/x509/#{google_client_email}",
:issuer => google_client_email,
:scope => api_scope_url,
:signing_key => key,
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
})
local_client.authorization.fetch_access_token!
return local_client
end
def build_result(api_method, parameters, body_object=nil)
if body_object
result = @client.execute(
:api_method => api_method,
:parameters => parameters,
:body_object => body_object
)
else
result = @client.execute(
:api_method => api_method,
:parameters => parameters
)
end
end
# result = Google::APIClient::Result
# returns Excon::Response
def build_response(result)
build_excon_response(result.body.nil? || result.body.empty? ? nil : Fog::JSON.decode(result.body), result.status)
end
end
RUNNING = 'RUNNING'

View file

@ -0,0 +1,7 @@
def test
connection = Fog::Google::SQL.new
puts 'Listing all Flags...'
puts '--------------------'
connection.flags
end

View file

@ -0,0 +1,38 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Get the Instance...'
puts '----------------------'
connection.instances.get(instance.instance)
puts 'List all Instances...'
puts '---------------------'
connection.instances.all
puts 'Update the Instance...'
puts '----------------------'
instance.activation_policy = 'ALWAYS'
instance.update
instance.wait_for { ready? }
puts 'Reset the Instance SSL configuration...'
puts '---------------------------------------'
instance.reset_ssl_config
puts 'Restart the Instance...'
puts '-----------------------'
instance.restart
puts 'Set the Instance root password...'
puts '---------------------------------'
instance.set_root_password(Fog::Mock.random_letters_and_numbers(8))
puts 'Delete the Instance...'
puts '----------------------'
instance.destroy
end

View file

@ -0,0 +1,20 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Delete the Instance...'
puts '----------------------'
operation = instance.destroy
puts 'Get the Operation...'
puts '--------------------'
connection.operations.get(instance.identity, operation.identity)
puts 'Listing all Operations...'
puts '-------------------------'
connection.operations.all(instance.identity)
end

View file

@ -0,0 +1,28 @@
def test
connection = Fog::Google::SQL.new
puts 'Create a Instance...'
puts '--------------------'
instance = connection.instances.create(:instance => Fog::Mock.random_letters(16), :tier => 'D1')
instance.wait_for { ready? }
puts 'Create a SSL certificate...'
puts '---------------------------'
ssl_cert = connection.ssl_certs.create(:instance => instance.instance, :common_name => Fog::Mock.random_letters(16))
puts 'Get the SSL certificate...'
puts '--------------------------'
connection.ssl_certs.get(instance.instance, ssl_cert.sha1_fingerprint)
puts 'List all SSL certificate...'
puts '---------------------------'
connection.ssl_certs.all(instance.instance)
puts 'Delete the SSL certificate...'
puts '-----------------------------'
ssl_cert.destroy
puts 'Delete the Instance...'
puts '----------------------'
instance.destroy
end

View file

@ -0,0 +1,7 @@
def test
connection = Fog::Google::SQL.new
puts 'Listing all Tiers...'
puts '--------------------'
connection.tiers
end

View file

@ -0,0 +1,34 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A database instance backup run resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns
class BackupRun < Fog::Model
identity :backup_configuration, :aliases => 'backupConfiguration'
attribute :due_time, :aliases => 'dueTime'
attribute :end_time, :aliases => 'endTime'
attribute :enqueued_time, :aliases => 'enqueuedTime'
attribute :error
attribute :instance
attribute :kind
attribute :start_time, :aliases => 'startTime'
attribute :status
DONE_STATE = 'DONE'
##
# Checks if the instance backup run is done
#
# @return [Boolean] True if the backup run is done; False otherwise
def ready?
self.state == DONE_STATE
end
end
end
end
end

View file

@ -0,0 +1,38 @@
require 'fog/core/collection'
require 'fog/google/models/sql/backup_run'
module Fog
module Google
class SQL
class BackupRuns < Fog::Collection
model Fog::Google::SQL::BackupRun
##
# Lists all backup runs associated with a given instance and configuration
#
# @param [String] instance_id Instance ID
# @param [String] backup_configuration_id Backup Configuration ID
# @return [Array<Fog::Google::SQL::BackupRun>] List of Backup run resources
def all(instance_id, backup_configuration_id)
data = service.list_backup_runs(instance_id, backup_configuration_id).body['items'] || []
load(data)
end
##
# Retrieves a resource containing information about a backup run
#
# @param [String] instance_id Instance ID
# @param [String] backup_configuration_id Backup Configuration ID
# @param [String] due_time The time when this run is due to start in RFC 3339 format
# @return [Fog::Google::SQL::BackupRun] Backup run resource
def get(instance_id, backup_configuration_id, due_time)
if backup_run = service.get_backup_run(instance_id, backup_configuration_id, due_time).body
new(backup_run)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A Google Cloud SQL service flag resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/flags
class Flag < Fog::Model
identity :name
attribute :allowed_string_values, :aliases => 'allowedStringValues'
attribute :applies_to, :aliases => 'appliesTo'
attribute :kind
attribute :max_value, :aliases => 'maxValue'
attribute :min_value, :aliases => 'minValue'
attribute :type
end
end
end
end

View file

@ -0,0 +1,21 @@
require 'fog/core/collection'
require 'fog/google/models/sql/flag'
module Fog
module Google
class SQL
class Flags < Fog::Collection
model Fog::Google::SQL::Flag
##
# List all available database flags
#
# @return [Array<Fog::Google::SQL::Flag>] List of flags
def all
data = service.list_flags.body['items'] || []
load(data)
end
end
end
end
end

View file

@ -0,0 +1,353 @@
require 'fog/core/model'
module Fog
module Google
class SQL
class Instance < Fog::Model
identity :instance
attribute :current_disk_size, :aliases => 'currentDiskSize'
attribute :database_version, :aliases => 'databaseVersion'
attribute :etag
attribute :ip_addresses, :aliases => 'ipAddresses'
attribute :kind
attribute :max_disk_size, :aliases => 'maxDiskSize'
attribute :project
attribute :region
attribute :server_ca_cert, :aliases => 'serverCaCert'
attribute :settings
attribute :state
# These attributes are not available in the representation of an 'Instance' returned by the Google SQL API.
attribute :activation_policy
attribute :autorized_gae_applications
attribute :backup_configuration
attribute :database_flags
attribute :ip_configuration_authorized_networks
attribute :ip_configuration_enabled
attribute :ip_configuration_require_ssl
attribute :location_preference_zone_follow_gae_application
attribute :location_preference_zone
attribute :pricing_plan
attribute :replication_type
attribute :settings_version
attribute :tier
MAINTENANCE_STATE = 'MAINTENANCE'
PENDING_CREATE_STATE = 'PENDING_CREATE'
RUNNABLE_STATE = 'RUNNABLE'
SUSPENDED_STATE = 'SUSPENDED'
UNKNOWN_STATE = 'UNKNOWN_STATE'
##
# Returns the activation policy for this instance
#
# @return [String] The activation policy for this instance
def activation_policy
self.settings['activationPolicy']
end
##
# Returns the AppEngine app ids that can access this instance
#
# @return [Array<String>] The AppEngine app ids that can access this instance
def autorized_gae_applications
self.settings['authorizedGaeApplications']
end
##
# Returns the daily backup configuration for the instance
#
# @return [Array<Hash>] The daily backup configuration for the instance
def backup_configuration
self.settings['backupConfiguration']
end
##
# Creates a Cloud SQL instance as a clone of the source instance
#
# @param [String] destination_name Name of the Cloud SQL instance to be created as a clone
# @param [Hash] options Method options
# @option options [String] :log_filename Name of the binary log file for a Cloud SQL instance
# @option options [Integer] :log_position Position (offset) within the binary log file
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def clone(destination_name, options = {})
requires :identity
data = service.clone_instance(self.identity, destination_name, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Creates a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def create
requires :identity
data = service.insert_instance(self.identity, self.attributes[:tier], self.attributes)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
operation.wait_for { !pending? }
reload
end
##
# Returns the database flags passed to the instance at startup
#
# @return [Array<Hash>] The database flags passed to the instance at startup
def database_flags
self.settings['databaseFlags']
end
##
# Deletes a Cloud SQL instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def destroy(options = {})
requires :identity
data = service.delete_instance(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
# DISABLED: A delete instance operation never reachs a 'DONE' state (bug?)
# operation.wait_for { ready? }
end
operation
end
##
# Exports data from a Cloud SQL instance to a Google Cloud Storage bucket as a MySQL dump file
#
# @param [String] uri The path to the file in Google Cloud Storage where the export will be stored,
# or where it was already stored
# @param [Hash] options Method options
# @option options [Array<String>] :databases Databases (for example, guestbook) from which the export is made.
# If unspecified, all databases are exported.
# @option options [Array<String>] :tables Tables to export, or that were exported, from the specified database.
# If you specify tables, specify one and only one database.
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def export(uri, options = {})
requires :identity
data = service.export_instance(self.identity, uri, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Imports data into a Cloud SQL instance from a MySQL dump file in Google Cloud Storage
#
# @param [Array<String>] uri A path to the MySQL dump file in Google Cloud Storage from which the import is
# made
# @param [Hash] options Method options
# @option options [String] :database The database (for example, guestbook) to which the import is made.
# If not set, it is assumed that the database is specified in the file to be imported.
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def import(uri, options = {})
requires :identity
data = service.import_instance(self.identity, uri, options)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Returns the list of external networks that are allowed to connect to the instance using the IP
#
# @return [Array<String>] The list of external networks that are allowed to connect to the instance using the IP
def ip_configuration_authorized_networks
self.settings.fetch('ipConfiguration', {})['authorizedNetworks']
end
##
# Returns whether the instance should be assigned an IP address or not
#
# @return [Boolean] Whether the instance should be assigned an IP address or not
def ip_configuration_enabled
self.settings.fetch('ipConfiguration', {})['enabled']
end
##
# Returns whether the mysqld should default to 'REQUIRE X509' for users connecting over IP
#
# @return [Boolean] Whether the mysqld should default to 'REQUIRE X509' for users connecting over IP
def ip_configuration_require_ssl
self.settings.fetch('ipConfiguration', {})['requireSsl']
end
##
# Returns the AppEngine application to follow
#
# @return [String] The AppEngine application to follow
def location_preference_zone_follow_gae_application
self.settings.fetch('locationPreference', {})['followGaeApplication']
end
##
# Returns the preferred Compute Engine zone
#
# @return [String] The preferred Compute Engine zone
def location_preference_zone
self.settings.fetch('locationPreference', {})['zone']
end
##
# Returns the pricing plan for this instance
#
# @return [String] The pricing plan for this instance
def pricing_plan
self.settings['pricingPlan']
end
##
# Checks if the instance is running
#
# @return [Boolean] True if the instance is running; False otherwise
def ready?
self.state == RUNNABLE_STATE
end
##
# Returns the type of replication this instance uses
#
# @return [String] The type of replication this instance uses
def replication_type
self.settings['replicationType']
end
##
# Deletes all client certificates and generates a new server SSL certificate for the instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def reset_ssl_config(options = {})
requires :identity
data = service.reset_instance_ssl_config(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Restarts a Cloud SQL instance
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def restart(options = {})
requires :identity
data = service.restart_instance(self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Restores a backup of a Cloud SQL instance
#
# @param [String] backup_configuration The identifier of the backup configuration
# @param [String] due_time The time when this run is due to start in RFC 3339 format
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def restore_backup(backup_configuration, due_time, options = {})
requires :identity
data = service.restore_instance_backup(self.identity, backup_configuration, due_time)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Saves a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def save
self.etag ? update : create
end
##
# Sets the password for the root user
#
# @param [String] password The password for the root user
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def set_root_password(password, options = {})
requires :identity
data = service.set_instance_root_password(self.identity, password)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Returns the version of instance settings
#
# @return [String] The version of instance settings
def settings_version
self.settings['settingsVersion']
end
##
# Lists all of the current SSL certificates for the instance
#
# @return [Array<Fog::Google::SQL::SslCert>] List of SSL certificate resources
def ssl_certs
requires :identity
service.ssl_certs.all(self.identity)
end
##
# Returns the tier of service for this instance
#
# @return [String] The tier of service for this instance
def tier
self.settings['tier']
end
##
# Updates settings of a Cloud SQL instance
#
# @return [Fog::Google::SQL::Instance] Instance resource
def update
requires :identity
data = service.update_instance(self.identity, self.settings_version, self.tier, self.attributes)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
operation.wait_for { !pending? }
reload
end
end
end
end
end

View file

@ -0,0 +1,39 @@
require 'fog/core/collection'
require 'fog/google/models/sql/instance'
module Fog
module Google
class SQL
class Instances < Fog::Collection
model Fog::Google::SQL::Instance
##
# Lists all instance
#
# @return [Array<Fog::Google::SQL::Instance>] List of instance resources
def all
data = service.list_instances.body['items'] || []
load(data)
end
##
# Retrieves an instance
#
# @param [String] instance_id Instance ID
# @return [Fog::Google::SQL::Instance] Instance resource
def get(instance_id)
if instance = service.get_instance(instance_id).body
new(instance)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -0,0 +1,61 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# An Operation resource contains information about database instance operations
# such as create, delete, and restart
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/operations
class Operation < Fog::Model
identity :operation
attribute :end_time, :aliases => 'endTime'
attribute :enqueued_time, :aliases => 'enqueuedTime'
attribute :error
attribute :export_context, :aliases => 'exportContext'
attribute :import_context, :aliases => 'importContext'
attribute :instance
attribute :kind
attribute :operation_type, :aliases => 'operationType'
attribute :start_time, :aliases => 'startTime'
attribute :state
attribute :user_email_address, :aliases => 'userEmailAddress'
DONE_STATE = 'DONE'
PENDING_STATE = 'PENDING'
RUNNING_STATE = 'RUNNING'
UNKNOWN_STATE = 'UNKNOWN'
##
# Checks if the instance operation is pending
#
# @return [Boolean] True if the operation is pending; False otherwise
def pending?
self.state == PENDING_STATE
end
##
# Checks if the instance operation is done
#
# @return [Boolean] True if the operation is done; False otherwise
def ready?
self.state == DONE_STATE
end
##
# Reloads an instance operation
#
# @return [Fog::Google::SQL::Operation] Instance operation resource
def reload
requires :identity
data = collection.get(self.instance, self.identity)
merge_attributes(data.attributes)
self
end
end
end
end
end

View file

@ -0,0 +1,49 @@
require 'fog/core/collection'
require 'fog/google/models/sql/operation'
module Fog
module Google
class SQL
class Operations < Fog::Collection
model Fog::Google::SQL::Operation
##
# Lists all instance operations that have been performed on the given instance
#
# @param [String] instance_id Instance ID
# @return [Array<Fog::Google::SQL::Operation>] List of instance operation resources
def all(instance_id)
data = []
begin
data = service.list_operations(instance_id).body['items'] || []
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return an empty Array
raise e unless e.message == 'The client is not authorized to make this request.'
end
load(data)
end
##
# Retrieves an instance operation that has been performed on an instance
#
# @param [String] instance_id Instance ID
# @param [String] operation_id Instance operation ID
# @return [Fog::Google::SQL::Operation] Instance operation resource
def get(instance_id, operation_id)
if operation = service.get_operation(instance_id, operation_id).body
new(operation)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -0,0 +1,73 @@
require 'fog/core/model'
module Fog
module Google
class SQL
##
# A SSL certificate resource
#
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/sslCerts
class SslCert < Fog::Model
identity :sha1_fingerprint, :aliases => 'sha1Fingerprint'
attribute :cert
attribute :cert_serial_number, :aliases => 'certSerialNumber'
attribute :common_name, :aliases => 'commonName'
attribute :create_time, :aliases => 'createTime'
attribute :expiration_time, :aliases => 'expirationTime'
attribute :instance
attribute :kind
# These attributes are not available in the representation of a 'SSL Certificate' returned by the SQL API.
# These attributes are only available as a reponse to a create operation
attribute :server_ca_cert, :aliases => 'serverCaCert'
attribute :cert_private_key, :aliases => 'certPrivateKey'
##
# Deletes a SSL certificate. The change will not take effect until the instance is restarted.
#
# @param [Hash] options Method options
# @option options [Boolean] :async If the operation must be performed asynchronously (true by default)
# @return [Fog::Google::SQL::Operation] A Operation resource
def destroy(options = {})
requires :instance, :identity
data = service.delete_ssl_cert(self.instance, self.identity)
operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
unless options.fetch(:async, true)
operation.wait_for { ready? }
end
operation
end
##
# Reloads a SSL certificate
#
# @return [Fog::Google::SQL::SslCert] SSL certificate resource
def reload
requires :instance, :identity
data = collection.get(self.instance, self.identity)
merge_attributes(data.attributes)
self
end
##
# Creates a SSL certificate. The new certificate will not be usable until the instance is restarted.
#
# @raise [Fog::Errors::Error] If SSL certificate already exists
def save
requires :instance, :common_name
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
data = service.insert_ssl_cert(self.instance, self.common_name).body
merge_attributes(data['clientCert']['certInfo'])
self.server_ca_cert = Fog::Google::SQL::SslCert.new(data['serverCaCert'])
self.cert_private_key = data['clientCert']['certPrivateKey']
self
end
end
end
end
end

View file

@ -0,0 +1,49 @@
require 'fog/core/collection'
require 'fog/google/models/sql/ssl_cert'
module Fog
module Google
class SQL
class SslCerts < Fog::Collection
model Fog::Google::SQL::SslCert
##
# Lists all of the current SSL certificates for the instance
#
# @param [String] instance_id Instance ID
# @return [Array<Fog::Google::SQL::SslCert>] List of SSL certificate resources
def all(instance_id)
data = []
begin
data = service.list_ssl_certs(instance_id).body['items'] || []
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return an empty Array
raise e unless e.message == 'The client is not authorized to make this request.'
end
load(data)
end
##
# Retrieves a particular SSL certificate (does not include the private key)
#
# @param [String] instance_id Instance ID
# @param [String] sha1_fingerprint Sha1 FingerPrint
# @return [Fog::Google::SQL::SslCert] SSL certificate resource
def get(instance_id, sha1_fingerprint)
if ssl_cert = service.get_ssl_cert(instance_id, sha1_fingerprint).body
new(ssl_cert)
end
rescue Fog::Errors::NotFound
nil
rescue Fog::Errors::Error => e
# Google SQL returns a 403 if we try to access a non-existing resource
# The default behaviour in Fog is to return a nil
return nil if e.message == 'The client is not authorized to make this request.'
raise e
end
end
end
end
end

View file

@ -60,7 +60,11 @@ module Fog
def get(key, options = {}, &block)
requires :directory
data = service.get_object(directory.key, key, options, &block)
file_data = data.headers.merge({
file_data = {}
data.headers.each do |key, value|
file_data[key] = value
end
file_data.merge({
:body => data.body,
:key => key
})

View file

@ -24,8 +24,7 @@ module Fog
body_object['name'] = options[:name] ? options[:name] : 'External NAT'
body_object['natIP'] = options[:address] if options[:address]
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -19,8 +19,7 @@ module Fog
'healthChecks' => health_checks.map { |i| { 'healthCheck' => i } }
}
result = self.build_result(api_method, parameters, body_object=body)
self.build_response(result)
request(api_method, parameters, body_object=body)
end
end
end

View file

@ -19,8 +19,7 @@ module Fog
'instances' => instances.map { |i| { 'instance' => i } }
}
result = self.build_result(api_method, parameters, body_object=body)
self.build_response(result)
request(api_method, parameters, body_object=body)
end
end
end

View file

@ -26,8 +26,7 @@ module Fog
'autoDelete' => options.delete(:autoDelete),
}
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -16,8 +16,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'project' => @project,
'backendService' => backend_service_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -23,7 +23,7 @@ module Fog
}
self.data[:disks].delete disk_name
build_response(:body => self.data[:operations][operation])
build_excon_response(self.data[:operations][operation])
end
end
@ -40,8 +40,7 @@ module Fog
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'firewall' => firewall_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -22,8 +22,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'httpHealthCheck' => name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'image' => image_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'network' => network_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -21,8 +21,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'route' => identity,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -45,7 +45,7 @@ module Fog
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
}
build_response(:body => self.data[:operations][operation])
build_excon_response(self.data[:operations][operation])
end
end
@ -61,8 +61,7 @@ module Fog
'instance' => server_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -18,8 +18,7 @@ module Fog
'accessConfig' => options[:access_config].nil? ? 'External NAT' : options[:access_config],
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'snapshot' => snapshot_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -22,8 +22,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -21,8 +21,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
'deviceName' => deviceName
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,8 +16,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project,
'backendService' => service_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,7 +16,7 @@ module Fog
}
health_results = backend_service.backends.map do |backend|
body = { 'group' => backend['group'] }
resp = build_response(build_result(api_method, parameters, body_object= body))
resp = request(api_method, parameters, body_object= body)
[backend['group'], resp.data[:body]['healthStatus']]
end
Hash[health_results]

View file

@ -10,7 +10,7 @@ module Fog
get_zone(zone_name)
zone = self.data[:zones][zone_name]
if disk.nil? or disk["zone"] != zone["selfLink"]
return build_response(:body => {
return build_excon_response({
"error" => {
"errors" => [
{
@ -27,7 +27,7 @@ module Fog
# TODO transition the disk through the states
build_response(:body => disk)
build_excon_response(disk)
end
end
@ -44,8 +44,7 @@ module Fog
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -6,7 +6,7 @@ module Fog
disk_types = list_disk_types(zone).body['items']
disk_type = disk_types.select { |dt| dt['name'] == identity } || []
if disk_type.empty?
return build_response(:body => {
return build_excon_response({
'error' => {
'errors' => [
{
@ -21,7 +21,7 @@ module Fog
})
end
build_response(:body => disk_type.first)
build_excon_response(disk_type.first)
end
end
@ -34,8 +34,7 @@ module Fog
'diskType' => identity,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'firewall' => firewall_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -20,8 +20,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'httpHealthCheck' => name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,7 +16,7 @@ module Fog
"message" => "The resource 'projects/#{project}/global/images/#{image_name}' was not found"
}
}
build_response(:body => image)
build_excon_response(image)
end
end
@ -28,8 +28,7 @@ module Fog
'project' => project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -18,7 +18,7 @@ module Fog
"message" => "The resource 'projects/#{@project}/zones/#{zone_name}/machineTypes/#{machine_type_name}' was not found"
}
}
build_response(:body => machine_type)
build_excon_response(machine_type)
end
end
@ -35,8 +35,7 @@ module Fog
'machineType' => machine_type_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'network' => network_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
:project => identity,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -7,7 +7,7 @@ module Fog
region = regions.body['items'].select { |region| region['name'] == identity }
raise Fog::Errors::NotFound if region.nil? || region.empty?
build_response(:body => region.first)
build_excon_response(region.first)
end
end
@ -19,8 +19,7 @@ module Fog
'region' => identity.split('/')[-1],
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -22,8 +22,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'route' => identity,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -7,7 +7,7 @@ module Fog
get_zone(zone_name)
zone = self.data[:zones][zone_name]
if server.nil? or server["zone"] != zone["selfLink"]
return build_response(:body => {
return build_excon_response({
"error" => {
"errors" => [
{
@ -48,7 +48,7 @@ module Fog
end
end
build_response(:body => server)
build_excon_response(server)
end
end
@ -67,8 +67,7 @@ module Fog
'instance' => server_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,8 +16,7 @@ module Fog
'zone' => zone.split('/')[-1],
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -19,8 +19,7 @@ module Fog
'project' => project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -20,8 +20,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -18,7 +18,7 @@ module Fog
health_results = target_pool.instances.map do |instance|
body = { 'instance' => instance }
resp = build_response(build_result(api_method, parameters, body_object=body))
resp = request(api_method, parameters, body_object=body)
[instance, resp.data[:body]['healthStatus']]
end
Hash[health_results]

View file

@ -16,7 +16,7 @@ module Fog
"message" => "The resource 'projects/#{project}/zones/#{zone_name}' was not found"
}
}
build_response(:body => zone)
build_excon_response(zone)
end
end
@ -28,8 +28,7 @@ module Fog
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -28,7 +28,7 @@ module Fog
}
}
end
build_response(:body => operation)
build_excon_response(operation)
end
end
@ -47,8 +47,7 @@ module Fog
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
body_object = { 'name' => address_name }
body_object['description'] = options[:description] if options[:description]
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -15,9 +15,8 @@ module Fog
}
body_object = { 'name' => backend_service_name }
body_object.merge!(opts)
result = self.build_result(api_method, parameters, body_object=body_object)
response = self.build_response(result)
request(api_method, parameters, body_object=body_object)
end
end
end

View file

@ -60,7 +60,7 @@ module Fog
"selfLink" => "#{object["zone"]}/operations/#{operation}"
}
build_response(:body => self.data[:operations][operation])
build_excon_response(self.data[:operations][operation])
end
end
@ -105,9 +105,7 @@ module Fog
# Merge in any remaining options (only 'description' should remain)
body_object.merge!(opts)
result = self.build_result(api_method, parameters,
body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -2,13 +2,13 @@ module Fog
module Compute
class Google
class Mock
def insert_firewall(firewall_name, allowed, network = @default_network, options = {})
def insert_firewall(firewall_name, allowed, network = GOOGLE_COMPUTE_DEFAULT_NETWORK, options = {})
Fog::Mock.not_implemented
end
end
class Real
def insert_firewall(firewall_name, allowed, network = @default_network, options = {})
def insert_firewall(firewall_name, allowed, network = GOOGLE_COMPUTE_DEFAULT_NETWORK, options = {})
unless network.start_with? 'http'
network = "#{@api_url}#{@project}/global/networks/#{network}"
end
@ -35,8 +35,7 @@ module Fog
body_object["targetTags"] = options[:target_tags]
end
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -17,9 +17,7 @@ module Fog
body_object = { 'name' => forwarding_rule_name }
body_object.merge!(opts)
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
request(api_method, parameters, body_object=body_object)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
body_object = { 'name' => name }
body_object.merge!(opts)
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -18,16 +18,12 @@ module Fog
body_object = {
'sourceType' => 'RAW',
'name' => image_name,
'rawDisk' => { 'source' => options.delete('rawDisk') }
}
# Merge in the remaining params (only 'description' should remain)
# Merge in the remaining params
body_object.merge!(options)
result = self.build_result(api_method,
parameters,
body_object=body_object)
response = self.build_response(result)
request(api_method, parameters, body_object=body_object)
end
end
end

View file

@ -21,8 +21,7 @@ module Fog
body_object['description'] = options[:description] if options[:description]
body_object['gatewayIPv4'] = options[:gateway_ipv4] if options[:gateway_ipv4]
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -27,8 +27,7 @@ module Fog
body_object['nextHopGateway'] = options[:next_hop_gateway] if options[:next_hop_gateway]
body_object['nextHopIp'] = options[:next_hop_ip] if options[:next_hop_ip]
result = self.build_result(api_method, parameters, body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -88,7 +88,7 @@ module Fog
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
}
build_response(:body => self.data[:operations][operation])
build_excon_response(self.data[:operations][operation])
end
end
@ -130,8 +130,8 @@ module Fog
network = nil
if options.key? 'network'
network = options.delete 'network'
elsif @default_network
network = @default_network
else
network = GOOGLE_COMPUTE_DEFAULT_NETWORK
end
# ExternalIP is default value for server creation
@ -184,9 +184,7 @@ module Fog
body_object.merge!(options) # Adds in all remaining options that weren't explicitly handled.
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
request(api_method, parameters, body_object=body_object)
end
end
end

View file

@ -32,9 +32,7 @@ module Fog
# Merge in any remaining options (description)
body_object.merge!(opts)
result = self.build_result(api_method, parameters,
body_object)
response = self.build_response(result)
request(api_method, parameters, body_object)
end
end
end

View file

@ -17,9 +17,7 @@ module Fog
body_object = { 'name' => target_pool_name }
body_object.merge!(opts)
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
request(api_method, parameters, body_object=body_object)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
}
parameters['filter'] = options[:filter] if options[:filter]
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,7 +16,7 @@ module Fog
disk_types_items["zones/#{zone}"] = { 'diskTypes' => disk_types }
end
end
build_response(:body => {
build_excon_response({
'kind' => 'compute#diskTypeAggregatedList',
'selfLink' => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/aggregated/diskTypes",
'items' => disk_types_items,
@ -32,8 +32,7 @@ module Fog
}
parameters['filter'] = options[:filter] if options[:filter]
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,7 +14,7 @@ module Fog
# Fill the zones Hash with the disks attached to each zone
self.data[:disks].values.each { |disk| zones["zones/#{disk['zone'].split('/')[-1]}"]['disks'].concat([disk]) }
end
build_response(:body => {
build_excon_response({
"kind" => "compute#diskAggregatedList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/aggregated/disks",
"id" => "projects/#{@project}/aggregated/disks",
@ -32,8 +32,7 @@ module Fog
}
parameters['filter'] = options[:filter] if options[:filter]
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,7 +14,7 @@ module Fog
# Fill the zones Hash with the servers attached to each zone
self.data[:servers].values.each { |server| zones["zones/#{server['zone'].split('/')[-1]}"]['instances'].concat([server]) }
end
build_response(:body => {
build_excon_response({
"kind" => "compute#instanceAggregatedList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/aggregated/instances",
"id" => "projects/#{@project}/aggregated/instances",
@ -32,8 +32,7 @@ module Fog
}
parameters['filter'] = options[:filter] if options[:filter]
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -3,7 +3,7 @@ module Fog
class Google
class Mock
def list_disk_types(zone)
build_response(:body => {
build_excon_response({
'kind' => 'compute#diskTypeList',
'selfLink' => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone}/diskTypes",
'items' => [
@ -38,8 +38,7 @@ module Fog
'zone' => zone.split('/')[-1],
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -4,7 +4,7 @@ module Fog
class Mock
def list_disks(zone_name)
disks = self.data[:disks].values.select{|d| d["zone"].split("/")[-1] == zone_name}
build_response(:body => {
build_excon_response({
"kind" => "compute#diskList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks",
"id" => "projects/#{@project}/zones/#{zone_name}/disks",
@ -21,8 +21,7 @@ module Fog
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -4,7 +4,7 @@ module Fog
class Mock
def list_forwarding_rules(region_name)
forwarding_rules = self.data[:forwarding_rules].values.select{|d| d["region"].split("/")[-1] == region_name}
build_response(:body => {
build_excon_response({
"kind" => "compute#forwardingRuleList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/regions/#{region_name}/forwardingRules",
"id" => "projects/#{@project}/regions/#{region_name}/regions",
@ -21,8 +21,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -16,8 +16,7 @@ module Fog
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -4,7 +4,7 @@ module Fog
class Mock
def list_images(project=@project)
images = data(project)[:images].values
build_response(:body => {
build_excon_response({
"kind" => "compute#imageList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{project}/global/images",
"id" => "projects/#{project}/global/images",
@ -21,8 +21,7 @@ module Fog
'project' => project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -5,7 +5,7 @@ module Fog
def list_machine_types(zone_name)
get_zone(zone_name)
machine_types = data[:machine_types][zone_name].values
build_response(:body => {
build_excon_response({
"kind" => "compute#machineTypeList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/machineTypes",
"id" => "projects/high-cistern-340/zones/us-central1-a/machineTypes",
@ -22,8 +22,7 @@ module Fog
'zone' => zone_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -17,8 +17,7 @@ module Fog
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -3,7 +3,7 @@ module Fog
class Google
class Mock
def list_regions
build_response(:body => {
build_excon_response({
"kind" => "compute#regionList",
"selfLink" => "https://www.googleapis.com/compute/v1/projects/#{@project}/regions",
"id" => "projects/#{@project}/regions",
@ -77,8 +77,7 @@ module Fog
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -14,8 +14,7 @@ module Fog
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -6,7 +6,7 @@ module Fog
get_zone(zone_name)
zone = self.data[:zones][zone_name]
servers = self.data[:servers].values.select{|s| s["zone"] == zone["selfLink"]}
build_response(:body => {
build_excon_response({
"kind" => "compute#instanceList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/instances",
"id" => "projects/#{@project}/zones/#{zone_name}/instances",
@ -23,8 +23,7 @@ module Fog
'zone' => zone_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'project' => project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

View file

@ -15,8 +15,7 @@ module Fog
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
request(api_method, parameters)
end
end
end

Some files were not shown because too many files have changed in this diff Show more