fog 0.0.84 → 0.0.85

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +47 -37
  3. data/bin/fog +9 -10
  4. data/fog.gemspec +23 -4
  5. data/lib/fog.rb +19 -1
  6. data/lib/fog/aws.rb +23 -0
  7. data/lib/fog/aws/bin.rb +4 -0
  8. data/lib/fog/aws/ec2.rb +20 -27
  9. data/lib/fog/aws/elb.rb +115 -0
  10. data/lib/fog/aws/models/ec2/server.rb +7 -1
  11. data/lib/fog/aws/models/s3/directories.rb +4 -4
  12. data/lib/fog/aws/models/s3/directory.rb +13 -11
  13. data/lib/fog/aws/parsers/elb/deregister_instances_from_load_balancer.rb +26 -0
  14. data/lib/fog/aws/parsers/elb/describe_instance_health.rb +30 -0
  15. data/lib/fog/aws/parsers/elb/describe_load_balancers.rb +101 -0
  16. data/lib/fog/aws/parsers/elb/disable_availability_zones_for_load_balancer.rb +26 -0
  17. data/lib/fog/aws/parsers/elb/enable_availability_zones_for_load_balancer.rb +26 -0
  18. data/lib/fog/aws/parsers/elb/register_instances_with_load_balancer.rb +26 -0
  19. data/lib/fog/aws/requests/ec2/detach_volume.rb +2 -2
  20. data/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb +45 -0
  21. data/lib/fog/aws/requests/elb/describe_instance_health.rb +44 -0
  22. data/lib/fog/aws/requests/elb/describe_load_balancers.rb +57 -0
  23. data/lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb +44 -0
  24. data/lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb +44 -0
  25. data/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb +45 -0
  26. data/lib/fog/aws/s3.rb +8 -1
  27. data/lib/fog/aws/simpledb.rb +9 -18
  28. data/lib/fog/bin.rb +11 -1
  29. data/lib/fog/credentials.rb +1 -0
  30. data/lib/fog/local.rb +72 -0
  31. data/lib/fog/local/bin.rb +34 -0
  32. data/lib/fog/local/models/directories.rb +43 -0
  33. data/lib/fog/local/models/directory.rb +47 -0
  34. data/lib/fog/local/models/file.rb +58 -0
  35. data/lib/fog/local/models/files.rb +74 -0
  36. data/lib/fog/model.rb +2 -8
  37. data/lib/fog/rackspace/models/files/directories.rb +3 -3
  38. data/lib/fog/rackspace/models/files/directory.rb +8 -5
  39. data/lib/fog/rackspace/models/servers/server.rb +7 -3
  40. data/lib/fog/rackspace/requests/servers/create_server.rb +1 -1
  41. data/lib/fog/ssh.rb +91 -25
  42. data/lib/fog/terremark/bin.rb +1 -8
  43. data/lib/fog/terremark/ecloud.rb +14 -5
  44. data/lib/fog/terremark/models/shared/server.rb +54 -3
  45. data/lib/fog/terremark/parsers/shared/vapp.rb +1 -1
  46. data/lib/fog/terremark/requests/shared/get_network.rb +39 -1
  47. data/lib/fog/terremark/requests/shared/get_organization.rb +45 -1
  48. data/lib/fog/terremark/requests/shared/get_organizations.rb +2 -1
  49. data/lib/fog/terremark/requests/shared/get_public_ips.rb +32 -1
  50. data/lib/fog/terremark/requests/shared/get_vdc.rb +83 -1
  51. data/lib/fog/terremark/requests/shared/{reset.rb → power_reset.rb} +1 -1
  52. data/lib/fog/terremark/requests/shared/power_shutdown.rb +32 -0
  53. data/lib/fog/terremark/shared.rb +139 -18
  54. data/lib/fog/terremark/vcloud.rb +14 -5
  55. data/spec/aws/models/ec2/address_spec.rb +1 -3
  56. data/spec/aws/models/ec2/snapshot_spec.rb +25 -49
  57. data/spec/aws/models/ec2/snapshots_spec.rb +25 -31
  58. data/spec/aws/models/ec2/volume_spec.rb +9 -3
  59. data/spec/aws/models/s3/directory_spec.rb +14 -14
  60. data/spec/aws/requests/ec2/associate_address_spec.rb +4 -5
  61. data/spec/aws/requests/ec2/attach_volume_spec.rb +14 -16
  62. data/spec/aws/requests/ec2/create_snapshot_spec.rb +2 -3
  63. data/spec/aws/requests/ec2/delete_snapshot_spec.rb +5 -6
  64. data/spec/aws/requests/ec2/describe_instances_spec.rb +3 -2
  65. data/spec/aws/requests/ec2/describe_snapshots_spec.rb +21 -25
  66. data/spec/aws/requests/ec2/detach_volume_spec.rb +14 -16
  67. data/spec/aws/requests/ec2/disassociate_address_spec.rb +3 -4
  68. data/spec/aws/requests/ec2/get_console_output_spec.rb +1 -0
  69. data/spec/aws/requests/s3/get_service_spec.rb +5 -6
  70. data/spec/spec_helper.rb +0 -20
  71. data/tests/helper.rb +0 -10
  72. data/tests/rackspace/requests/servers/create_image_tests.rb +2 -2
  73. data/tests/rackspace/requests/servers/create_server_tests.rb +3 -2
  74. data/tests/rackspace/requests/servers/delete_image_tests.rb +2 -2
  75. data/tests/rackspace/requests/servers/delete_server_tests.rb +1 -1
  76. data/tests/rackspace/requests/servers/get_server_details_tests.rb +1 -1
  77. data/tests/rackspace/requests/servers/list_addresses_tests.rb +1 -1
  78. data/tests/rackspace/requests/servers/list_private_addresses_tests.rb +1 -1
  79. data/tests/rackspace/requests/servers/list_public_addresses_tests.rb +1 -1
  80. data/tests/rackspace/requests/servers/list_servers_detail_tests.rb +1 -1
  81. data/tests/rackspace/requests/servers/list_servers_tests.rb +1 -1
  82. data/tests/rackspace/requests/servers/reboot_server_tests.rb +3 -3
  83. data/tests/rackspace/requests/servers/update_server_tests.rb +1 -1
  84. data/tests/slicehost/requests/create_slice_tests.rb +1 -1
  85. data/tests/slicehost/requests/delete_slice_tests.rb +1 -1
  86. data/tests/slicehost/requests/get_slice_tests.rb +1 -1
  87. data/tests/slicehost/requests/reboot_slice_tests.rb +2 -2
  88. metadata +24 -5
  89. data/lib/fog/terremark/requests/shared/shutdown.rb +0 -43
@@ -0,0 +1,57 @@
1
+ module Fog
2
+ module AWS
3
+ module ELB
4
+ class Real
5
+
6
+ # Describe all or specified load balancers
7
+ #
8
+ # ==== Parameters
9
+ # * lb_name<~Array> - List of load balancer names to describe, defaults to all
10
+ #
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ # * body<~Hash>:
14
+ # * 'ResponseMetadata'<~Hash>:
15
+ # * 'RequestId'<~String> - Id of request
16
+ # * 'DescribeLoadBalancersResult'<~Hash>:
17
+ # * 'LoadBalancerDescriptions'<~Array>
18
+ # * 'LoadBalancerName'<~String> - name of load balancer
19
+ # * 'DNSName'<~String> - external DNS name of load balancer
20
+ # * 'CreatedTime'<~Time> - time load balancer was created
21
+ # * 'ListenerDescriptions'<~Array>
22
+ # * 'PolicyNames'<~Array> - list of policies enabled
23
+ # * 'Listener'<~Hash>:
24
+ # * 'InstancePort'<~Integer> - port on instance that requests are sent to
25
+ # * 'Protocol'<~String> - transport protocol used for routing in [TCP, HTTP]
26
+ # * 'LoadBalancerPort'<~Integer> - port that load balancer listens on for requests
27
+ # * 'HealthCheck'<~Hash>:
28
+ # * 'HealthyThreshold'<~Integer> - number of consecutive health probe successes required before moving the instance to the Healthy state
29
+ # * 'Timeout'<~Integer> - number of seconds after which no response means a failed health probe
30
+ # * 'Interval'<~Integer> - interval (in seconds) between health checks of an individual instance
31
+ # * 'UnhealthyThreshold'<~Integer> - number of consecutive health probe failures that move the instance to the unhealthy state
32
+ # * 'Target'<~String> - string describing protocol type, port and URL to check
33
+ # * 'Policies'<~Hash>:
34
+ # * 'LBCookieStickinessPolicies'<~Array> - list of Load Balancer Generated Cookie Stickiness policies for the LoadBalancer
35
+ # * 'AppCookieStickinessPolicies'<~Array> - list of Application Generated Cookie Stickiness policies for the LoadBalancer
36
+ # * 'AvailabilityZones'<~Array> - list of availability zones covered by this load balancer
37
+ # * 'Instances'<~Array> - list of instances that the load balancer balances between
38
+ def describe_load_balancers(lb_name = [])
39
+ params = ELB.indexed_param('LoadBalancerNames.member', [*lb_name], 1)
40
+ request({
41
+ 'Action' => 'DescribeLoadBalancers',
42
+ :parser => Fog::Parsers::AWS::ELB::DescribeLoadBalancers.new
43
+ }.merge!(params))
44
+ end
45
+
46
+ end
47
+
48
+ class Mock
49
+
50
+ def describe_load_balancers(lb_name = [])
51
+ raise MockNotImplemented.new("Contributions welcome!")
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module AWS
3
+ module ELB
4
+ class Real
5
+
6
+ # Disable an availability zone for an existing ELB
7
+ #
8
+ # ==== Parameters
9
+ # * availability_zones<~Array> - List of availability zones to disable on ELB
10
+ # * lb_name<~String> - Load balancer to disable availability zones on
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'ResponseMetadata'<~Hash>:
16
+ # * 'RequestId'<~String> - Id of request
17
+ # * 'DisableAvailabilityZonesForLoadBalancerResult'<~Hash>:
18
+ # * 'AvailabilityZones'<~Array> - array of strings describing instances currently enabled
19
+ def disable_availability_zones_for_load_balancer(availability_zones, lb_name)
20
+ params = ELB.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
21
+ request({
22
+ 'Action' => 'DisableAvailabilityZonesForLoadBalancer',
23
+ 'LoadBalancerName' => lb_name,
24
+ :parser => Fog::Parsers::AWS::ELB::DisableAvailabilityZonesForLoadBalancer.new
25
+ }.merge!(params))
26
+ end
27
+
28
+ alias :disable_zones :disable_availability_zones_for_load_balancer
29
+
30
+ end
31
+
32
+ class Mock
33
+
34
+ def disable_availability_zones_for_load_balancer(availability_zones, lb_name)
35
+ raise MockNotImplemented.new("Contributions welcome!")
36
+ end
37
+
38
+ alias :disable_zones :disable_availability_zones_for_load_balancer
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module AWS
3
+ module ELB
4
+ class Real
5
+
6
+ # Enable an availability zone for an existing ELB
7
+ #
8
+ # ==== Parameters
9
+ # * availability_zones<~Array> - List of availability zones to enable on ELB
10
+ # * lb_name<~String> - Load balancer to enable availability zones on
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'ResponseMetadata'<~Hash>:
16
+ # * 'RequestId'<~String> - Id of request
17
+ # * 'EnableAvailabilityZonesForLoadBalancerResult'<~Hash>:
18
+ # * 'AvailabilityZones'<~Array> - array of strings describing instances currently enabled
19
+ def enable_availability_zones_for_load_balancer(availability_zones, lb_name)
20
+ params = ELB.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
21
+ request({
22
+ 'Action' => 'EnableAvailabilityZonesForLoadBalancer',
23
+ 'LoadBalancerName' => lb_name,
24
+ :parser => Fog::Parsers::AWS::ELB::EnableAvailabilityZonesForLoadBalancer.new
25
+ }.merge!(params))
26
+ end
27
+
28
+ alias :enable_zones :enable_availability_zones_for_load_balancer
29
+
30
+ end
31
+
32
+ class Mock
33
+
34
+ def enable_availability_zones_for_load_balancer(availability_zones, lb_name)
35
+ raise MockNotImplemented.new("Contributions welcome!")
36
+ end
37
+
38
+ alias :enable_zones :enable_availability_zones_for_load_balancer
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module AWS
3
+ module ELB
4
+ class Real
5
+
6
+ # Register an instance with an existing ELB
7
+ #
8
+ # ==== Parameters
9
+ # * instance_ids<~Array> - List of instance IDs to associate with ELB
10
+ # * lb_name<~String> - Load balancer to assign instances to
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'ResponseMetadata'<~Hash>:
16
+ # * 'RequestId'<~String> - Id of request
17
+ # * 'RegisterInstancesWithLoadBalancerResult'<~Hash>:
18
+ # * 'Instances'<~Array> - array of hashes describing instances currently enabled
19
+ # * 'InstanceId'<~String>
20
+ def register_instances_with_load_balancer(instance_ids, lb_name)
21
+ params = ELB.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1)
22
+ request({
23
+ 'Action' => 'RegisterInstancesWithLoadBalancer',
24
+ 'LoadBalancerName' => lb_name,
25
+ :parser => Fog::Parsers::AWS::ELB::RegisterInstancesWithLoadBalancer.new
26
+ }.merge!(params))
27
+ end
28
+
29
+ alias :register_instances :register_instances_with_load_balancer
30
+
31
+ end
32
+
33
+ class Mock
34
+
35
+ def register_instances_with_load_balancer(instance_ids, lb_name)
36
+ raise MockNotImplemented.new("Contributions welcome!")
37
+ end
38
+
39
+ alias :register_instances :register_instances_with_load_balancer
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -127,7 +127,14 @@ module Fog
127
127
  raise ArgumentError.new('aws_secret_access_key is required to access ec2')
128
128
  end
129
129
  @hmac = HMAC::SHA1.new(@aws_secret_access_key)
130
- @host = options[:host] || 's3.amazonaws.com'
130
+ @host = options[:host] || case options[:region]
131
+ when 'ap-southeast-1'
132
+ 's3-ap-southeast-1.amazonaws.com'
133
+ when 'us-west-1'
134
+ 's3-us-west-1.amazonaws.com'
135
+ else
136
+ 's3.amazonaws.com'
137
+ end
131
138
  @port = options[:port] || 443
132
139
  @scheme = options[:scheme] || 'https'
133
140
  end
@@ -136,24 +136,15 @@ module Fog
136
136
  idempotent = params.delete(:idempotent)
137
137
  parser = params.delete(:parser)
138
138
 
139
- params.merge!({
140
- 'AWSAccessKeyId' => @aws_access_key_id,
141
- 'SignatureMethod' => 'HmacSHA256',
142
- 'SignatureVersion' => '2',
143
- 'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
144
- 'Version' => '2007-11-07'
145
- })
146
-
147
- body = ''
148
- for key in params.keys.sort
149
- unless (value = params[key]).nil?
150
- body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
151
- end
152
- end
153
-
154
- string_to_sign = "POST\n#{@host}\n/\n" << body.chop
155
- hmac = @hmac.update(string_to_sign)
156
- body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
139
+ body = AWS.signed_params(
140
+ params,
141
+ {
142
+ :aws_access_key_id => @aws_access_key_id,
143
+ :hmac => @hmac,
144
+ :host => @host,
145
+ :version => '2007-11-07'
146
+ }
147
+ )
157
148
 
158
149
  response = @connection.request({
159
150
  :body => body,
@@ -5,7 +5,7 @@ module Fog
5
5
 
6
6
  def services
7
7
  services = []
8
- [::AWS, ::Rackspace, ::Slicehost, ::Terremark].each do |service|
8
+ [::AWS, ::Local, ::Rackspace, ::Slicehost, ::Terremark].each do |service|
9
9
  if service.initialized?
10
10
  services << service
11
11
  end
@@ -13,6 +13,16 @@ module Fog
13
13
  services
14
14
  end
15
15
 
16
+ def directories
17
+ directories = {}
18
+ services.each do |service|
19
+ if service.respond_to?(:directories)
20
+ directories[service] = service.directories
21
+ end
22
+ end
23
+ directories
24
+ end
25
+
16
26
  def flavors
17
27
  flavors = {}
18
28
  services.each do |service|
@@ -27,6 +27,7 @@ module Fog
27
27
  :#{credential}:
28
28
  :aws_access_key_id: INTENTIONALLY_LEFT_BLANK
29
29
  :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
30
+ :local_root: INTENTIONALLY_LEFT_BLANK
30
31
  :rackspace_api_key: INTENTIONALLY_LEFT_BLANK
31
32
  :rackspace_username: INTENTIONALLY_LEFT_BLANK
32
33
  :slicehost_password: INTENTIONALLY_LEFT_BLANK
@@ -0,0 +1,72 @@
1
+ module Fog
2
+ module Local
3
+
4
+ def self.new(options={})
5
+
6
+ unless @required
7
+ require 'fog/local/models/directories'
8
+ require 'fog/local/models/directory'
9
+ require 'fog/local/models/file'
10
+ require 'fog/local/models/files'
11
+ @required = true
12
+ end
13
+
14
+ unless options[:local_root]
15
+ raise ArgumentError.new('local_root is required to access local')
16
+ end
17
+ if Fog.mocking?
18
+ Fog::Local::Mock.new(options)
19
+ else
20
+ Fog::Local::Real.new(options)
21
+ end
22
+ end
23
+
24
+ def self.reset_data(keys=Mock.data.keys)
25
+ Mock.reset_data(keys)
26
+ end
27
+
28
+ class Mock
29
+
30
+ def self.data
31
+ @data ||= Hash.new do |hash, key|
32
+ hash[key] = {}
33
+ end
34
+ end
35
+
36
+ def self.reset_data(keys=data.keys)
37
+ for key in [*keys]
38
+ data.delete(key)
39
+ end
40
+ end
41
+
42
+ def initialize(options={})
43
+ @local_root = ::File.expand_path(options[:local_root])
44
+ @data = self.class.data[@local_root]
45
+ end
46
+
47
+ def local_root
48
+ @local_root
49
+ end
50
+
51
+ def path(partial)
52
+ partial
53
+ end
54
+ end
55
+
56
+ class Real
57
+
58
+ def initialize(options={})
59
+ @local_root = ::File.expand_path(options[:local_root])
60
+ end
61
+
62
+ def local_root
63
+ @local_root
64
+ end
65
+
66
+ def path_to(partial)
67
+ ::File.join(@local_root, partial)
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ module Local
2
+ class << self
3
+ if Fog.credentials[:local_root]
4
+
5
+ def initialized?
6
+ true
7
+ end
8
+
9
+ def [](service)
10
+ @@connections ||= Hash.new do |hash, key|
11
+ credentials = Fog.credentials.reject do |k,v|
12
+ ![:local_root].include?(k)
13
+ end
14
+ hash[key] = case key
15
+ when :files
16
+ Fog::Local.new(credentials)
17
+ end
18
+ end
19
+ @@connections[service]
20
+ end
21
+
22
+ def directories
23
+ self[:files].directories
24
+ end
25
+
26
+ else
27
+
28
+ def initialized?
29
+ false
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/collection'
2
+ require 'fog/local/models/directory'
3
+
4
+ module Fog
5
+ module Local
6
+
7
+ class Real
8
+ def directories
9
+ Fog::Local::Directories.new(:connection => self)
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def directories
15
+ Fog::Local::Directories.new(:connection => self)
16
+ end
17
+ end
18
+
19
+ class Directories < Fog::Collection
20
+
21
+ model Fog::Local::Directory
22
+
23
+ def all
24
+ data = Dir.entries(connection.local_root).select do |entry|
25
+ entry[0...1] != '.' && ::File.directory?(connection.path_to(entry))
26
+ end.map do |entry|
27
+ {:name => entry}
28
+ end
29
+ load(data)
30
+ end
31
+
32
+ def get(name)
33
+ if ::File.directory?(connection.path_to(name))
34
+ new(:name => name)
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ require 'fog/model'
2
+ # require 'fog/local/models/files'
3
+
4
+ module Fog
5
+ module Local
6
+
7
+ class Directory < Fog::Model
8
+
9
+ identity :name
10
+
11
+ def destroy
12
+ requires :name
13
+
14
+ if ::File.directory?(path)
15
+ Dir.rmdir(path)
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ def files
23
+ @files ||= begin
24
+ Fog::Local::Files.new(
25
+ :directory => self,
26
+ :connection => connection
27
+ )
28
+ end
29
+ end
30
+
31
+ def save
32
+ requires :name
33
+
34
+ Dir.mkdir(path)
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def path
41
+ connection.path_to(name)
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end