fog 0.0.67 → 0.0.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION.yml +1 -1
  3. data/fog.gemspec +24 -6
  4. data/lib/fog/aws/ec2.rb +48 -47
  5. data/lib/fog/aws/requests/ec2/describe_instances.rb +1 -1
  6. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +3 -3
  7. data/lib/fog/aws/requests/ec2/run_instances.rb +2 -3
  8. data/lib/fog/aws/s3.rb +18 -17
  9. data/lib/fog/aws/simpledb.rb +11 -10
  10. data/lib/fog/bin.rb +12 -4
  11. data/lib/fog/rackspace/files.rb +16 -15
  12. data/lib/fog/rackspace/requests/servers/get_image_details.rb +35 -0
  13. data/lib/fog/rackspace/servers.rb +26 -24
  14. data/lib/fog/slicehost.rb +18 -17
  15. data/lib/fog/slicehost/models/flavors.rb +11 -3
  16. data/lib/fog/slicehost/models/images.rb +14 -4
  17. data/lib/fog/slicehost/models/servers.rb +10 -2
  18. data/lib/fog/terremark.rb +83 -17
  19. data/lib/fog/terremark/parsers/get_public_Ips.rb +28 -0
  20. data/lib/fog/terremark/parsers/internet_service.rb +63 -0
  21. data/lib/fog/terremark/parsers/node_service.rb +30 -0
  22. data/lib/fog/terremark/requests/add_internet_service.rb +63 -0
  23. data/lib/fog/terremark/requests/add_node_service.rb +63 -0
  24. data/lib/fog/terremark/requests/create_internet_service.rb +63 -0
  25. data/lib/fog/terremark/requests/delete_internet_service.rb +40 -0
  26. data/lib/fog/terremark/requests/delete_node_service.rb +40 -0
  27. data/lib/fog/terremark/requests/deploy_vapp.rb +2 -2
  28. data/lib/fog/terremark/requests/get_public_ips.rb +37 -0
  29. data/lib/fog/terremark/requests/get_task.rb +1 -1
  30. data/lib/fog/terremark/requests/get_tasks_list.rb +1 -1
  31. data/lib/fog/terremark/requests/get_vapp.rb +1 -1
  32. data/lib/fog/terremark/requests/instantiate_vapp_template.rb +4 -8
  33. data/lib/fog/terremark/requests/power_off.rb +1 -1
  34. data/lib/fog/terremark/requests/power_on.rb +1 -1
  35. data/lib/fog/terremark/requests/reset.rb +1 -1
  36. data/lib/fog/terremark/requests/shutdown.rb +1 -1
  37. data/tests/{test_helper.rb → helper.rb} +8 -7
  38. data/tests/{test_helper_tests.rb → helper_tests.rb} +7 -9
  39. data/tests/rackspace/helper.rb +64 -0
  40. data/tests/rackspace/requests/servers/create_image_tests.rb +22 -0
  41. data/tests/rackspace/requests/servers/create_server_tests.rb +19 -0
  42. data/tests/rackspace/requests/servers/delete_image_tests.rb +32 -0
  43. data/tests/rackspace/requests/servers/delete_server_tests.rb +26 -0
  44. data/tests/rackspace/requests/servers/get_flavor_details_tests.rb +25 -0
  45. data/tests/rackspace/requests/servers/get_image_details_tests.rb +25 -0
  46. data/tests/rackspace/requests/servers/get_server_details_tests.rb +31 -0
  47. data/tests/slicehost/{slicehost_helper.rb → helper.rb} +0 -0
  48. data/tests/slicehost/requests/create_slice_tests.rb +1 -1
  49. data/tests/slicehost/requests/get_backups_tests.rb +1 -1
  50. data/tests/slicehost/requests/get_flavor_tests.rb +5 -2
  51. data/tests/slicehost/requests/get_flavors_tests.rb +5 -2
  52. data/tests/slicehost/requests/get_image_tests.rb +5 -2
  53. data/tests/slicehost/requests/get_images_tests.rb +5 -2
  54. data/tests/slicehost/requests/get_slice_tests.rb +2 -2
  55. data/tests/slicehost/requests/get_slices_tests.rb +5 -2
  56. data/tests/slicehost/requests/reboot_slice_tests.rb +1 -1
  57. metadata +24 -6
@@ -1,24 +1,25 @@
1
- require 'fog/slicehost/models/flavor'
2
- require 'fog/slicehost/models/flavors'
3
- require 'fog/slicehost/models/image'
4
- require 'fog/slicehost/models/images'
5
- require 'fog/slicehost/models/server'
6
- require 'fog/slicehost/models/servers'
7
- require 'fog/slicehost/requests/create_slice'
8
- require 'fog/slicehost/requests/delete_slice'
9
- require 'fog/slicehost/requests/get_backups'
10
- require 'fog/slicehost/requests/get_flavor'
11
- require 'fog/slicehost/requests/get_flavors'
12
- require 'fog/slicehost/requests/get_image'
13
- require 'fog/slicehost/requests/get_images'
14
- require 'fog/slicehost/requests/get_slice'
15
- require 'fog/slicehost/requests/get_slices'
16
- require 'fog/slicehost/requests/reboot_slice'
17
-
18
1
  module Fog
19
2
  module Slicehost
20
3
 
21
4
  def self.new(options={})
5
+
6
+ require 'fog/slicehost/models/flavor'
7
+ require 'fog/slicehost/models/flavors'
8
+ require 'fog/slicehost/models/image'
9
+ require 'fog/slicehost/models/images'
10
+ require 'fog/slicehost/models/server'
11
+ require 'fog/slicehost/models/servers'
12
+ require 'fog/slicehost/requests/create_slice'
13
+ require 'fog/slicehost/requests/delete_slice'
14
+ require 'fog/slicehost/requests/get_backups'
15
+ require 'fog/slicehost/requests/get_flavor'
16
+ require 'fog/slicehost/requests/get_flavors'
17
+ require 'fog/slicehost/requests/get_image'
18
+ require 'fog/slicehost/requests/get_images'
19
+ require 'fog/slicehost/requests/get_slice'
20
+ require 'fog/slicehost/requests/get_slices'
21
+ require 'fog/slicehost/requests/reboot_slice'
22
+
22
23
  unless options[:slicehost_password]
23
24
  raise ArgumentError.new('slicehost_password is required to access slicehost')
24
25
  end
@@ -4,8 +4,16 @@ require 'fog/slicehost/models/flavor'
4
4
  module Fog
5
5
  module Slicehost
6
6
 
7
- def flavors
8
- Fog::Slicehost::Flavors.new(:connection => self)
7
+ class Mock
8
+ def flavors
9
+ Fog::Slicehost::Flavors.new(:connection => self)
10
+ end
11
+ end
12
+
13
+ class Real
14
+ def flavors
15
+ Fog::Slicehost::Flavors.new(:connection => self)
16
+ end
9
17
  end
10
18
 
11
19
  class Flavors < Fog::Collection
@@ -14,7 +22,7 @@ module Fog
14
22
 
15
23
  def all
16
24
  data = connection.get_flavors.body['flavors']
17
- load(self)
25
+ load(data)
18
26
  end
19
27
 
20
28
  def get(flavor_id)
@@ -4,10 +4,20 @@ require 'fog/slicehost/models/image'
4
4
  module Fog
5
5
  module Slicehost
6
6
 
7
- def images(attributes = {})
8
- Fog::Slicehost::Images.new({
9
- :connection => self
10
- }.merge!(attributes))
7
+ class Mock
8
+ def images(attributes = {})
9
+ Fog::Slicehost::Images.new({
10
+ :connection => self
11
+ }.merge!(attributes))
12
+ end
13
+ end
14
+
15
+ class Real
16
+ def images(attributes = {})
17
+ Fog::Slicehost::Images.new({
18
+ :connection => self
19
+ }.merge!(attributes))
20
+ end
11
21
  end
12
22
 
13
23
  class Images < Fog::Collection
@@ -4,8 +4,16 @@ require 'fog/slicehost/models/server'
4
4
  module Fog
5
5
  module Slicehost
6
6
 
7
- def servers
8
- Fog::Slicehost::Servers.new(:connection => self)
7
+ class Mock
8
+ def servers
9
+ Fog::Slicehost::Servers.new(:connection => self)
10
+ end
11
+ end
12
+
13
+ class Real
14
+ def servers
15
+ Fog::Slicehost::Servers.new(:connection => self)
16
+ end
9
17
  end
10
18
 
11
19
  class Servers < Fog::Collection
@@ -1,24 +1,31 @@
1
- require 'fog/terremark/requests/delete_vapp'
2
- require 'fog/terremark/requests/deploy_vapp'
3
- require 'fog/terremark/requests/get_catalog'
4
- require 'fog/terremark/requests/get_catalog_item'
5
- require 'fog/terremark/requests/get_organization'
6
- require 'fog/terremark/requests/get_organizations'
7
- require 'fog/terremark/requests/get_task'
8
- require 'fog/terremark/requests/get_tasks_list'
9
- require 'fog/terremark/requests/get_vapp'
10
- require 'fog/terremark/requests/get_vapp_template'
11
- require 'fog/terremark/requests/get_vdc'
12
- require 'fog/terremark/requests/instantiate_vapp_template'
13
- require 'fog/terremark/requests/reset'
14
- require 'fog/terremark/requests/power_off'
15
- require 'fog/terremark/requests/power_on'
16
- require 'fog/terremark/requests/shutdown'
17
-
18
1
  module Fog
19
2
  module Terremark
20
3
 
21
4
  def self.new(options={})
5
+
6
+ require 'fog/terremark/requests/add_internet_service'
7
+ require 'fog/terremark/requests/add_node_service'
8
+ require 'fog/terremark/requests/create_internet_service'
9
+ require 'fog/terremark/requests/delete_internet_service'
10
+ require 'fog/terremark/requests/delete_node_service'
11
+ require 'fog/terremark/requests/delete_vapp'
12
+ require 'fog/terremark/requests/deploy_vapp'
13
+ require 'fog/terremark/requests/get_catalog'
14
+ require 'fog/terremark/requests/get_catalog_item'
15
+ require 'fog/terremark/requests/get_organization'
16
+ require 'fog/terremark/requests/get_organizations'
17
+ require 'fog/terremark/requests/get_public_ips'
18
+ require 'fog/terremark/requests/get_task'
19
+ require 'fog/terremark/requests/get_tasks_list'
20
+ require 'fog/terremark/requests/get_vapp'
21
+ require 'fog/terremark/requests/get_vapp_template'
22
+ require 'fog/terremark/requests/get_vdc'
23
+ require 'fog/terremark/requests/instantiate_vapp_template'
24
+ require 'fog/terremark/requests/reset'
25
+ require 'fog/terremark/requests/power_off'
26
+ require 'fog/terremark/requests/power_on'
27
+ require 'fog/terremark/requests/shutdown'
28
+
22
29
  unless options[:terremark_password]
23
30
  raise ArgumentError.new('terremark_password is required to access terremark')
24
31
  end
@@ -65,6 +72,65 @@ module Fog
65
72
  @cookie = get_organizations.headers['Set-Cookie']
66
73
  end
67
74
 
75
+ # TODO: bust cache on organization creation?
76
+ def default_organization_id
77
+ @default_organization_id ||= begin
78
+ org_list = get_organizations.body['OrgList']
79
+ if org_list.length == 1
80
+ org_list.first['href'].split('/').last.to_i
81
+ else
82
+ nil
83
+ end
84
+ end
85
+ end
86
+
87
+ def default_vdc_id
88
+ if default_organization_id
89
+ @default_vdc_id ||= begin
90
+ vdcs = get_organization(default_organization_id).body['Links'].select {|link|
91
+ link['type'] == 'application/vnd.vmware.vcloud.vdc+xml'
92
+ }
93
+ if vdcs.length == 1
94
+ vdcs.first['href'].split('/').last.to_i
95
+ else
96
+ nil
97
+ end
98
+ end
99
+ else
100
+ nil
101
+ end
102
+ end
103
+
104
+ def default_network_id
105
+ if default_vdc_id
106
+ @default_network_id ||= begin
107
+ networks = get_vdc(default_vdc_id).body['AvailableNetworks']
108
+ if networks.length == 1
109
+ networks.first['href'].split('/').last.to_i
110
+ else
111
+ nil
112
+ end
113
+ end
114
+ else
115
+ nil
116
+ end
117
+ end
118
+
119
+ def default_public_ip_id
120
+ if default_vdc_id
121
+ @default_public_ip_id ||= begin
122
+ ips = get_public_ips(default_vdc_id).body['PublicIpAddresses']
123
+ if ips.length == 1
124
+ ips.first['Href'].split('/').last.to_i
125
+ else
126
+ nil
127
+ end
128
+ end
129
+ else
130
+ nil
131
+ end
132
+ end
133
+
68
134
  private
69
135
 
70
136
  def request(params)
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Parsers
3
+ module Terremark
4
+
5
+ class GetPublicIps< Fog::Parsers::Base
6
+
7
+ def reset
8
+ @ip_address = {}
9
+ @response = { 'PublicIpAddresses' => [] }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'Href', 'Name'
15
+ @ip_address[name] = @value
16
+ when 'Id'
17
+ @ip_address[name] = @value.to_i
18
+ when 'PublicIPAddress'
19
+ @response['PublicIpAddresses'] << @ip_address
20
+ @ip_address = {}
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,63 @@
1
+ module Fog
2
+ module Parsers
3
+ module Terremark
4
+
5
+ class InternetService < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @in_public_ip_address = false
9
+ @response = { 'PublicIpAddress' => {} }
10
+ end
11
+
12
+ def start_element(name, attributes)
13
+ @value = ''
14
+ case name
15
+ when 'Href'
16
+ data = {}
17
+ until attributes.empty?
18
+ data[attributes.shift] = attributes.shift
19
+ end
20
+ if @in_public_ip_address
21
+ @response['PublicIpAddress'][name] = data
22
+ else
23
+ @response[name] = data
24
+ end
25
+ when 'PublicIpAddress'
26
+ @in_public_ip_address = true
27
+ end
28
+ end
29
+
30
+ def end_element(name)
31
+ case name
32
+ when 'Description', 'Protocol'
33
+ @response[name] = @value
34
+ when 'Enabled'
35
+ if @value == 'false'
36
+ @response[name] = false
37
+ else
38
+ @response[name] = true
39
+ end
40
+ when 'Id'
41
+ if @in_public_ip_address
42
+ @response['PublicIpAddress'][name] = @value.to_i
43
+ else
44
+ @response[name] = @value.to_i
45
+ end
46
+ when 'Name'
47
+ if @in_public_ip_address
48
+ @response['PublicIpAddress'][name] = @value
49
+ else
50
+ @response[name] = @value
51
+ end
52
+ when 'Port', 'Timeout'
53
+ @response[name] = @value.to_i
54
+ when 'PublicIpAddress'
55
+ @in_public_ip_address = false
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Parsers
3
+ module Terremark
4
+
5
+ class NodeService < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @response = {}
9
+ end
10
+
11
+ def end_element(name)
12
+ case name
13
+ when 'Description', 'Href', 'IpAddress', 'Name', 'Protocol'
14
+ @response[name] = @value
15
+ when 'Enabled'
16
+ if @value == 'false'
17
+ @response[name] = false
18
+ else
19
+ @response[name] = true
20
+ end
21
+ when 'Id', 'Port'
22
+ @response[name] = @value.to_i
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ module Fog
2
+ module Terremark
3
+ class Real
4
+
5
+ require 'fog/terremark/parsers/internet_service'
6
+
7
+ # Reserve requested resources and deploy vApp
8
+ #
9
+ # ==== Parameters
10
+ # * ip_id<~Integer> - Id of ip to add service to
11
+ # * name<~String> - Name of service
12
+ # * protocol<~String> - Protocol of service
13
+ # * port<~Integer> - Port of service
14
+ # * options<~Hash>:
15
+ # * Enabled<~Boolean>: defaults to true
16
+ # * Description<~String>: optional description
17
+ #
18
+ # ==== Returns
19
+ # * response<~Excon::Response>:
20
+ # * body<~Hash>:
21
+ # * 'endTime'<~String> - endTime of task
22
+ # * 'href'<~String> - link to task
23
+ # * 'startTime'<~String> - startTime of task
24
+ # * 'status'<~String> - status of task
25
+ # * 'type'<~String> - type of task
26
+ # * 'Owner'<~String> -
27
+ # * 'href'<~String> - href of owner
28
+ # * 'name'<~String> - name of owner
29
+ # * 'type'<~String> - type of owner
30
+ def add_internet_service(ip_id, name, protocol, port, options = {})
31
+ unless options.has_key?('Enabled')
32
+ options['Enabled'] = true
33
+ end
34
+ data = <<-DATA
35
+ <InternetService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createInternetService">
36
+ <Name>#{name}</Name>
37
+ <Protocol>#{protocol.upcase}</Protocol>
38
+ <Port>#{port}</Port>
39
+ <Enabled>#{options['Enabled']}</Enabled>
40
+ <Description>#{options['Description']}</Description>
41
+ </InternetService>
42
+ DATA
43
+ request(
44
+ :body => data,
45
+ :expects => 200,
46
+ :headers => {'Content-Type' => 'application/xml'},
47
+ :method => 'POST',
48
+ :parser => Fog::Parsers::Terremark::InternetService.new,
49
+ :path => "publicIps/#{ip_id}/internetServices"
50
+ )
51
+ end
52
+
53
+ end
54
+
55
+ class Mock
56
+
57
+ def add_internet_service(ip_id)
58
+ raise MockNotImplemented.new("Contributions welcome!")
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,63 @@
1
+ module Fog
2
+ module Terremark
3
+ class Real
4
+
5
+ require 'fog/terremark/parsers/node_service'
6
+
7
+ # Reserve requested resources and deploy vApp
8
+ #
9
+ # ==== Parameters
10
+ # * service_id<~String> - Id of service to add node to
11
+ # * ip<~String> - Private ip of server to add to node
12
+ # * name<~String> - Name of service
13
+ # * port<~Integer> - Port of service
14
+ # * options<~Hash>:
15
+ # * Enabled<~Boolean>: defaults to true
16
+ # * Description<~String>: optional description
17
+ #
18
+ # ==== Returns
19
+ # * response<~Excon::Response>:
20
+ # * body<~Hash>:
21
+ # * 'endTime'<~String> - endTime of task
22
+ # * 'href'<~String> - link to task
23
+ # * 'startTime'<~String> - startTime of task
24
+ # * 'status'<~String> - status of task
25
+ # * 'type'<~String> - type of task
26
+ # * 'Owner'<~String> -
27
+ # * 'href'<~String> - href of owner
28
+ # * 'name'<~String> - name of owner
29
+ # * 'type'<~String> - type of owner
30
+ def add_node_service(service_id, ip, name, port, options = {})
31
+ unless options.has_key?('Enabled')
32
+ options['Enabled'] = true
33
+ end
34
+ data = <<-DATA
35
+ <NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
36
+ <IpAddress>#{ip}</IpAddress>
37
+ <Name>#{name}</Name>
38
+ <Port>#{port}</Port>
39
+ <Enabled>#{options['Enabled']}</Enabled>
40
+ <Description>#{options['Description']}</Description>
41
+ </NodeService>
42
+ DATA
43
+ request(
44
+ :body => data,
45
+ :expects => 200,
46
+ :headers => {'Content-Type' => 'application/xml'},
47
+ :method => 'POST',
48
+ :parser => Fog::Parsers::Terremark::InternetService.new,
49
+ :path => "internetServices/#{service_id}/nodes"
50
+ )
51
+ end
52
+
53
+ end
54
+
55
+ class Mock
56
+
57
+ def add_node_service(ip)
58
+ raise MockNotImplemented.new("Contributions welcome!")
59
+ end
60
+
61
+ end
62
+ end
63
+ end