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 rds_subnets

This commit is contained in:
Rusty Geldmacher 2012-10-25 10:43:55 -04:00
commit 84dd43e468
19 changed files with 106 additions and 35 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@
.bundle .bundle
.DS_Store .DS_Store
.idea .idea
/tests/.fog
bin/* bin/*
!bin/fog !bin/fog
!bin/rdoc !bin/rdoc

View file

@ -59,7 +59,7 @@ namespace :test do
end end
task :test do task :test do
Rake::Task[:mock_tests].invoke && Rake::Task[:real_tests].invoke Rake::Task[:mock_tests].invoke
end end
def tests(mocked) def tests(mocked)

View file

@ -57,20 +57,22 @@ module Fog
# By default, expire in 5 years # By default, expire in 5 years
def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60))
requires :objectid file = directory.files.head(key)
# TODO - more efficient method to get this? self.objectid = if file.present? then file.attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] else nil end
storage = Fog::Storage.new(:provider => 'Atmos') if self.objectid.present?
uri = URI::HTTP.build(:scheme => @prefix, :host => @storage_host, :port => @storage_port.to_i, :path => "/rest/objects/#{objectid}" ) uri = URI::HTTP.build(:scheme => connection.ssl? ? "http" : "https" , :host => connection.host, :port => connection.port.to_i, :path => "/rest/objects/#{self.objectid}" )
Fog::Storage.new(:provider => 'Atmos').uid
sb = "GET\n" sb = "GET\n"
sb += uri.path.downcase + "\n" sb += uri.path.downcase + "\n"
sb += storage.uid + "\n" sb += connection.uid + "\n"
sb += String(expires.to_i()) sb += String(expires.to_i())
signature = storage.sign( sb ) signature = connection.sign( sb )
uri.query = "uid=#{CGI::escape(storage.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}" uri.query = "uid=#{CGI::escape(connection.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}"
uri.to_s uri.to_s
else
nil
end
end end
def save(options = {}) def save(options = {})

View file

@ -6,7 +6,7 @@ module Fog
extend Fog::AWS::CredentialFetcher::ServiceMethods extend Fog::AWS::CredentialFetcher::ServiceMethods
requires :aws_access_key_id, :aws_secret_access_key requires :aws_access_key_id, :aws_secret_access_key
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
request_path 'fog/aws/requests/cloud_watch' request_path 'fog/aws/requests/cloud_watch'
@ -94,6 +94,10 @@ module Fog
setup_credentials(options) setup_credentials(options)
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
@instrumentor = options[:instrumentor]
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.cloud_watch'
options[:region] ||= 'us-east-1' options[:region] ||= 'us-east-1'
@host = options[:host] || "monitoring.#{options[:region]}.amazonaws.com" @host = options[:host] || "monitoring.#{options[:region]}.amazonaws.com"
@path = options[:path] || '/' @path = options[:path] || '/'
@ -136,6 +140,16 @@ module Fog
} }
) )
if @instrumentor
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
_request(body, idempotent, parser)
end
else
_request(body, idempotent, parser)
end
end
def _request(body, idempotent, parser)
@connection.request({ @connection.request({
:body => body, :body => body,
:expects => 200, :expects => 200,

View file

@ -121,9 +121,13 @@ module Fog
# self # self
#end #end
def destroy def destroy(options = { :force => false })
requires :id requires :id
connection.delete_auto_scaling_group(id)
opts = {}
opts.merge({'ForceDelete' => true}) if options[:force]
connection.delete_auto_scaling_group(id, opts)
end end
def update def update

View file

@ -38,7 +38,7 @@ module Fog
@metric[name] = value @metric[name] = value
when 'Dimensions' when 'Dimensions'
@in_dimensions = false @in_dimensions = false
when 'NextMarker' when 'NextToken'
@response['ListMetricsResult'][name] = value @response['ListMetricsResult'][name] = value
when 'RequestId' when 'RequestId'
@response['ResponseMetadata'][name] = value @response['ResponseMetadata'][name] = value

View file

@ -4,6 +4,13 @@ module Fog
module AWS module AWS
class DescribeAvailabilityZones < Fog::Parsers::Base class DescribeAvailabilityZones < Fog::Parsers::Base
def start_element(name, attrs = [])
case name
when 'messageSet'
@in_message_set = true
end
super
end
def reset def reset
@availability_zone = { 'messageSet' => [] } @availability_zone = { 'messageSet' => [] }
@ -13,14 +20,18 @@ module Fog
def end_element(name) def end_element(name)
case name case name
when 'item' when 'item'
@response['availabilityZoneInfo'] << @availability_zone unless @in_message_set
@availability_zone = { 'messageSet' => [] } @response['availabilityZoneInfo'] << @availability_zone
@availability_zone = { 'messageSet' => [] }
end
when 'message' when 'message'
@availability_zone['messageSet'] << value @availability_zone['messageSet'] << value
when 'regionName', 'zoneName', 'zoneState' when 'regionName', 'zoneName', 'zoneState'
@availability_zone[name] = value @availability_zone[name] = value
when 'requestId' when 'requestId'
@response[name] = value @response[name] = value
when 'messageSet'
@in_message_set = false
end end
end end

View file

@ -16,7 +16,7 @@ module Fog
@reserved_instance[name] = value @reserved_instance[name] = value
when 'duration', 'instanceCount' when 'duration', 'instanceCount'
@reserved_instance[name] = value.to_i @reserved_instance[name] = value.to_i
when 'fixedPrice', 'amount' when 'fixedPrice', 'amount', 'usagePrice'
@reserved_instance[name] = value.to_f @reserved_instance[name] = value.to_f
when 'item' when 'item'
@response['reservedInstancesSet'] << @reserved_instance @response['reservedInstancesSet'] << @reserved_instance

View file

@ -26,7 +26,7 @@ module Fog
'x-amz-content-sha256' => Digest::SHA256.hexdigest(body), 'x-amz-content-sha256' => Digest::SHA256.hexdigest(body),
'x-amz-sha256-tree-hash' => Fog::AWS::Glacier::TreeHash.digest(body) 'x-amz-sha256-tree-hash' => Fog::AWS::Glacier::TreeHash.digest(body)
} }
headers['x-amz-archive-description'] = options['description'] if options['description'] headers['x-amz-archive-description'] = Fog::AWS.escape(options['description']) if options['description']
request( request(
:expects => 201, :expects => 201,

View file

@ -23,7 +23,7 @@ module Fog
path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}/multipart-uploads" path = "/#{account_id}/vaults/#{Fog::AWS.escape(name)}/multipart-uploads"
headers = {'x-amz-part-size' => part_size.to_s} headers = {'x-amz-part-size' => part_size.to_s}
headers['x-amz-archive-description'] = options['description'] if options['description'] headers['x-amz-archive-description'] = Fog::AWS.escape(options['description']) if options['description']
request( request(
:expects => 201, :expects => 201,
:headers => headers, :headers => headers,

View file

@ -209,7 +209,7 @@ module Fog
def select_default_image def select_default_image
return @default_image_id unless @default_image_id.nil? return @default_image_id unless @default_image_id.nil?
all_images = Fog::Compute[:brightbox].list_images all_images = list_images
official_images = all_images.select {|img| img["official"] == true} official_images = all_images.select {|img| img["official"] == true}
ubuntu_lts_images = official_images.select {|img| img["name"] =~ /Ubuntu.*LTS/} ubuntu_lts_images = official_images.select {|img| img["name"] =~ /Ubuntu.*LTS/}
ubuntu_lts_i686_images = ubuntu_lts_images.select {|img| img["arch"] == "i686"} ubuntu_lts_i686_images = ubuntu_lts_images.select {|img| img["arch"] == "i686"}

View file

@ -38,8 +38,10 @@ module Fog
attribute :server_type attribute :server_type
def initialize(attributes={}) def initialize(attributes={})
self.image_id ||= Fog::Compute[:brightbox].default_image # Call super first to initialize the 'connection' object for our default image
super super
# FIXME connection is actually <Fog::Compute::Brightbox::Real> not <Fog::Connection>
self.image_id ||= connection.default_image
end end
def zone_id def zone_id

View file

@ -243,7 +243,7 @@ DATA
canonical_resource << "#{params[:path]}" canonical_resource << "#{params[:path]}"
canonical_resource << '?' canonical_resource << '?'
for key in (params[:query] || {}).keys for key in (params[:query] || {}).keys
if ['acl', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(key) if ['acl', 'cors', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(key)
canonical_resource << "#{key}&" canonical_resource << "#{key}&"
end end
end end

View file

@ -95,7 +95,7 @@ module Fog
req_body = { req_body = {
'auth' => { 'auth' => {
'passwordCredentials' => { 'passwordCredentials' => {
'username' => @openstack_username, 'username' => @openstack_username.to_s,
'password' => @openstack_api_key.to_s 'password' => @openstack_api_key.to_s
} }
} }

View file

@ -24,6 +24,8 @@ module Fog
attribute :availability_zone attribute :availability_zone
attribute :user_data_encoded attribute :user_data_encoded
attribute :state, :aliases => 'status' attribute :state, :aliases => 'status'
attribute :created, :type => :time
attribute :updated, :type => :time
attribute :tenant_id attribute :tenant_id
attribute :user_id attribute :user_id

View file

@ -67,7 +67,9 @@ module Fog
'accessIPv4' => options['accessIPv4'] || "", 'accessIPv4' => options['accessIPv4'] || "",
'accessIPv6' => options['accessIPv6'] || "", 'accessIPv6' => options['accessIPv6'] || "",
'progress' => 0, 'progress' => 0,
'status' => 'BUILD' 'status' => 'BUILD',
'created' => '2012-09-27T00:04:18Z',
'updated' => '2012-09-27T00:04:27Z',
} }
self.data[:last_modified][:servers][data['id']] = Time.now self.data[:last_modified][:servers][data['id']] = Time.now

View file

@ -30,17 +30,43 @@ module Fog
class Real class Real
include Shared include Shared
# Clones a VM from a template or existing machine on your vSphere
# Server.
#
# ==== Parameters
# * options<~Hash>:
# * 'template_path'<~String> - *REQUIRED* The path to the machine you
# want to clone FROM. (Example:
# "/Datacenter/DataCenterNameHere/FolderNameHere/VMNameHere")
# * 'name'<~String> - *REQUIRED* The VMName of the Destination
# * 'resource_pool'<~String> - The resource pool on your datacenter
# cluster you want to use.
# * 'dest_folder'<~String> - Destination Folder of where 'name' will
# be placed on your cluster. *NOT TESTED OR VALIDATED*
# * 'power_on'<~Boolean> - Whether to power on machine after clone.
# Defaults to true.
# * 'wait'<~Boolean> - Whether the method should wait for the virtual
# machine to close finish cloning before returning information from
# vSphere. Returns the value of the machine if it finishes cloning
# in 150 seconds (1m30s) else it returns nil. 'wait' Defaults to nil.
# Saves a little time.
# * 'transform'<~String> - Not documented - see http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.RelocateSpec.html
#
def vm_clone(options = {}) def vm_clone(options = {})
# Option handling # Option handling
options = vm_clone_check_options(options) options = vm_clone_check_options(options)
# Added for people still using options['path']
template_path = options['path'] || options['template_path']
notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Could not find VM template" } notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Could not find VM template" }
# Find the template in the folder. This is more efficient than # Find the template in the folder. This is more efficient than
# searching ALL VM's looking for the template. # searching ALL VM's looking for the template.
# Tap gets rid of the leading empty string and "Datacenters" element # Tap gets rid of the leading empty string and "Datacenters" element
# and returns the array. # and returns the array.
path_elements = options['path'].split('/').tap { |ary| ary.shift 2 } path_elements = template_path.split('/').tap { |ary| ary.shift 2 }
# The DC name itself. # The DC name itself.
template_dc = path_elements.shift template_dc = path_elements.shift
# If the first path element contains "vm" this denotes the vmFolder # If the first path element contains "vm" this denotes the vmFolder
@ -69,10 +95,10 @@ module Fog
# Now find the template itself using the efficient find method # Now find the template itself using the efficient find method
vm_mob_ref = folder.find(template_name, RbVmomi::VIM::VirtualMachine) vm_mob_ref = folder.find(template_name, RbVmomi::VIM::VirtualMachine)
# Now find _a_ resource pool to use for the clone # Now find _a_ resource pool to use for the clone if one is not specified
# (REVISIT: We need to support cloning into a specific RP) if ( options.has_key?('resource_pool') )
resource_pool = options['resource_pool']
if ( vm_mob_ref.resourcePool == nil ) elsif ( vm_mob_ref.resourcePool == nil )
# If the template is really a template then there is no associated resource pool, # If the template is really a template then there is no associated resource pool,
# so we need to find one using the template's parent host or cluster # so we need to find one using the template's parent host or cluster
esx_host = vm_mob_ref.collect!('runtime.host')['runtime.host'] esx_host = vm_mob_ref.collect!('runtime.host')['runtime.host']
@ -125,7 +151,9 @@ module Fog
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec, clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec,
:powerOn => options.has_key?('power_on') ? options['power_on'] : true, :powerOn => options.has_key?('power_on') ? options['power_on'] : true,
:template => false) :template => false)
task = vm_mob_ref.CloneVM_Task(:folder => vm_mob_ref.parent, :name => options['name'], :spec => clone_spec) task = vm_mob_ref.CloneVM_Task(:folder => options.has_key?('dest_folder') ? options['dest_folder'] : vm_mob_ref.parent,
:name => options['name'],
:spec => clone_spec)
# Waiting for the VM to complete allows us to get the VirtulMachine # Waiting for the VM to complete allows us to get the VirtulMachine
# object of the new machine when it's done. It is HIGHLY recommended # object of the new machine when it's done. It is HIGHLY recommended
# to set 'wait' => true if your app wants to wait. Otherwise, you're # to set 'wait' => true if your app wants to wait. Otherwise, you're

View file

@ -1,3 +1,6 @@
ENV['FOG_RC'] = File.expand_path '../.fog', __FILE__
ENV['FOG_CREDENTIAL'] = 'default'
require 'fog' require 'fog'
require 'fog/bin' # for available_providers and registered_providers require 'fog/bin' # for available_providers and registered_providers
@ -22,7 +25,7 @@ available_providers = Fog.available_providers.map {|provider| provider.downcase}
unavailable_providers = all_providers - available_providers unavailable_providers = all_providers - available_providers
for provider in unavailable_providers for provider in unavailable_providers
Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '~/.fog' to run them)[/]") Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '#{Fog.credentials_path}' to run them)[/]")
Thread.current[:tags] << ('-' << provider) Thread.current[:tags] << ('-' << provider)
end end

View file

@ -12,7 +12,9 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
'status' => String, 'status' => String,
'accessIPv4' => Fog::Nullable::String, 'accessIPv4' => Fog::Nullable::String,
'accessIPv6' => Fog::Nullable::String, 'accessIPv6' => Fog::Nullable::String,
'links' => Array 'links' => Array,
'created' => String,
'updated' => String
} }
@image_format = { @image_format = {