fog 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +3 -3
  3. data/changelog.txt +213 -0
  4. data/docs/compute/index.markdown +15 -1
  5. data/fog.gemspec +3 -3
  6. data/lib/fog.rb +1 -1
  7. data/lib/fog/aws.rb +9 -0
  8. data/lib/fog/aws/auto_scaling.rb +3 -1
  9. data/lib/fog/aws/cloud_formation.rb +2 -0
  10. data/lib/fog/aws/cloud_watch.rb +2 -0
  11. data/lib/fog/aws/compute.rb +9 -3
  12. data/lib/fog/aws/elasticache.rb +8 -1
  13. data/lib/fog/aws/elb.rb +2 -0
  14. data/lib/fog/aws/models/cloud_watch/metric_statistic.rb +1 -2
  15. data/lib/fog/aws/models/compute/security_group.rb +1 -1
  16. data/lib/fog/aws/models/compute/server.rb +3 -1
  17. data/lib/fog/aws/models/dns/records.rb +3 -3
  18. data/lib/fog/aws/models/elb/load_balancer.rb +6 -0
  19. data/lib/fog/aws/models/storage/file.rb +2 -2
  20. data/lib/fog/aws/models/storage/files.rb +4 -4
  21. data/lib/fog/aws/parsers/compute/describe_instance_status.rb +64 -0
  22. data/lib/fog/aws/parsers/compute/describe_security_groups.rb +1 -1
  23. data/lib/fog/aws/parsers/sqs/receive_message.rb +1 -1
  24. data/lib/fog/aws/parsers/sts/get_session_token.rb +31 -0
  25. data/lib/fog/aws/rds.rb +36 -1
  26. data/lib/fog/aws/requests/compute/describe_availability_zones.rb +3 -0
  27. data/lib/fog/aws/requests/compute/describe_instance_status.rb +36 -0
  28. data/lib/fog/aws/requests/compute/describe_security_groups.rb +2 -0
  29. data/lib/fog/aws/requests/elb/set_load_balancer_listener_ssl_certificate.rb +27 -0
  30. data/lib/fog/aws/requests/rds/create_db_instance.rb +64 -1
  31. data/lib/fog/aws/requests/rds/delete_db_instance.rb +19 -3
  32. data/lib/fog/aws/requests/rds/describe_db_instances.rb +40 -1
  33. data/lib/fog/aws/requests/rds/describe_db_reserved_instances.rb +1 -1
  34. data/lib/fog/aws/requests/rds/modify_db_instance.rb +24 -1
  35. data/lib/fog/aws/requests/rds/reboot_db_instance.rb +17 -1
  36. data/lib/fog/aws/requests/storage/{hash_to_acl.rb → acl_utils.rb} +8 -0
  37. data/lib/fog/aws/requests/storage/copy_object.rb +8 -0
  38. data/lib/fog/aws/requests/storage/get_bucket_acl.rb +7 -1
  39. data/lib/fog/aws/requests/storage/get_object_acl.rb +7 -1
  40. data/lib/fog/aws/requests/storage/get_object_http_url.rb +4 -3
  41. data/lib/fog/aws/requests/storage/get_object_https_url.rb +4 -3
  42. data/lib/fog/aws/requests/storage/put_bucket_acl.rb +2 -2
  43. data/lib/fog/aws/requests/storage/put_object_acl.rb +1 -1
  44. data/lib/fog/aws/requests/sts/get_federation_token.rb +20 -0
  45. data/lib/fog/aws/requests/sts/get_session_token.rb +18 -0
  46. data/lib/fog/aws/simpledb.rb +5 -1
  47. data/lib/fog/aws/sns.rb +2 -0
  48. data/lib/fog/aws/sqs.rb +5 -1
  49. data/lib/fog/aws/storage.rb +6 -0
  50. data/lib/fog/aws/sts.rb +137 -0
  51. data/lib/fog/bin.rb +1 -0
  52. data/lib/fog/bin/aws.rb +2 -0
  53. data/lib/fog/bin/clodo.rb +31 -0
  54. data/lib/fog/brightbox/compute.rb +7 -0
  55. data/lib/fog/brightbox/models/compute/cloud_ip.rb +10 -2
  56. data/lib/fog/brightbox/models/compute/firewall_policies.rb +29 -0
  57. data/lib/fog/brightbox/models/compute/firewall_policy.rb +65 -0
  58. data/lib/fog/brightbox/models/compute/firewall_rule.rb +54 -0
  59. data/lib/fog/brightbox/models/compute/firewall_rules.rb +24 -0
  60. data/lib/fog/brightbox/models/compute/image.rb +2 -0
  61. data/lib/fog/brightbox/models/compute/server.rb +41 -6
  62. data/lib/fog/brightbox/models/compute/server_group.rb +56 -17
  63. data/lib/fog/brightbox/requests/compute/remove_firewall_policy.rb +14 -0
  64. data/lib/fog/clodo.rb +34 -0
  65. data/lib/fog/clodo/compute.rb +152 -0
  66. data/lib/fog/clodo/models/compute/image.rb +31 -0
  67. data/lib/fog/clodo/models/compute/images.rb +28 -0
  68. data/lib/fog/clodo/models/compute/server.rb +163 -0
  69. data/lib/fog/clodo/models/compute/servers.rb +36 -0
  70. data/lib/fog/clodo/requests/compute/add_ip_address.rb +49 -0
  71. data/lib/fog/clodo/requests/compute/create_server.rb +112 -0
  72. data/lib/fog/clodo/requests/compute/delete_ip_address.rb +47 -0
  73. data/lib/fog/clodo/requests/compute/delete_server.rb +44 -0
  74. data/lib/fog/clodo/requests/compute/get_image_details.rb +20 -0
  75. data/lib/fog/clodo/requests/compute/get_server_details.rb +49 -0
  76. data/lib/fog/clodo/requests/compute/list_images.rb +48 -0
  77. data/lib/fog/clodo/requests/compute/list_images_detail.rb +61 -0
  78. data/lib/fog/clodo/requests/compute/list_servers.rb +50 -0
  79. data/lib/fog/clodo/requests/compute/list_servers_detail.rb +51 -0
  80. data/lib/fog/clodo/requests/compute/move_ip_address.rb +34 -0
  81. data/lib/fog/clodo/requests/compute/reboot_server.rb +19 -0
  82. data/lib/fog/clodo/requests/compute/rebuild_server.rb +21 -0
  83. data/lib/fog/clodo/requests/compute/server_action.rb +25 -0
  84. data/lib/fog/clodo/requests/compute/start_server.rb +19 -0
  85. data/lib/fog/clodo/requests/compute/stop_server.rb +19 -0
  86. data/lib/fog/compute.rb +3 -0
  87. data/lib/fog/core/credentials.rb +3 -3
  88. data/lib/fog/core/errors.rb +2 -0
  89. data/lib/fog/core/wait_for.rb +1 -1
  90. data/lib/fog/dnsmadeeasy/dns.rb +1 -1
  91. data/lib/fog/libvirt/compute.rb +2 -0
  92. data/lib/fog/libvirt/models/compute/nodes.rb +1 -3
  93. data/lib/fog/libvirt/models/compute/server.rb +8 -1
  94. data/lib/fog/providers.rb +1 -0
  95. data/lib/fog/rackspace/dns.rb +10 -2
  96. data/lib/fog/rackspace/load_balancers.rb +3 -0
  97. data/lib/fog/rackspace/models/compute/server.rb +2 -2
  98. data/lib/fog/rackspace/models/dns/callback.rb +3 -1
  99. data/lib/fog/rackspace/models/dns/record.rb +4 -0
  100. data/lib/fog/rackspace/models/load_balancers/load_balancer.rb +18 -8
  101. data/lib/fog/rackspace/requests/load_balancers/delete_nodes.rb +1 -2
  102. data/lib/fog/rackspace/requests/load_balancers/get_error_page.rb +15 -0
  103. data/lib/fog/rackspace/requests/load_balancers/list_load_balancers.rb +8 -2
  104. data/lib/fog/rackspace/requests/load_balancers/remove_error_page.rb +15 -0
  105. data/lib/fog/rackspace/requests/load_balancers/set_error_page.rb +21 -0
  106. data/lib/fog/vcloud/compute.rb +7 -1
  107. data/lib/fog/vcloud/models/compute/catalogs.rb +4 -5
  108. data/lib/fog/vcloud/models/compute/helpers/status.rb +37 -0
  109. data/lib/fog/vcloud/models/compute/network.rb +13 -49
  110. data/lib/fog/vcloud/models/compute/networks.rb +12 -3
  111. data/lib/fog/vcloud/models/compute/organization.rb +44 -0
  112. data/lib/fog/vcloud/models/compute/organizations.rb +29 -0
  113. data/lib/fog/vcloud/models/compute/server.rb +35 -56
  114. data/lib/fog/vcloud/models/compute/servers.rb +11 -13
  115. data/lib/fog/vcloud/models/compute/vapp.rb +41 -0
  116. data/lib/fog/vcloud/models/compute/vapps.rb +32 -0
  117. data/lib/fog/vcloud/models/compute/vdc.rb +11 -26
  118. data/lib/fog/vcloud/models/compute/vdcs.rb +6 -8
  119. data/lib/fog/vcloud/requests/compute/get_server.rb +10 -0
  120. data/lib/fog/vsphere/compute.rb +1 -0
  121. data/lib/fog/vsphere/models/compute/server.rb +18 -0
  122. data/lib/fog/vsphere/models/compute/servers.rb +8 -2
  123. data/lib/fog/vsphere/requests/compute/datacenters.rb +34 -0
  124. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +132 -91
  125. data/lib/fog/vsphere/requests/compute/vm_clone.rb +76 -37
  126. data/spec/lib/fog/aws/parsers/sqs/receive_message_spec.rb +58 -0
  127. data/tests/aws/models/elb/model_tests.rb +5 -0
  128. data/tests/aws/requests/compute/instance_tests.rb +23 -0
  129. data/tests/aws/requests/compute/security_group_tests.rb +1 -0
  130. data/tests/aws/requests/elb/listener_tests.rb +4 -0
  131. data/tests/aws/requests/storage/{hash_to_acl_tests.rb → acl_utils_tests.rb} +38 -2
  132. data/tests/aws/requests/storage/bucket_tests.rb +0 -3
  133. data/tests/aws/requests/storage/object_tests.rb +2 -4
  134. data/tests/aws/requests/sts/get_federation_token_tests.rb +21 -0
  135. data/tests/aws/requests/sts/session_token_tests.rb +16 -0
  136. data/tests/brightbox/requests/compute/account_tests.rb +11 -6
  137. data/tests/brightbox/requests/compute/api_client_tests.rb +23 -12
  138. data/tests/brightbox/requests/compute/cloud_ip_tests.rb +32 -17
  139. data/tests/brightbox/requests/compute/helper.rb +29 -3
  140. data/tests/brightbox/requests/compute/image_tests.rb +17 -14
  141. data/tests/brightbox/requests/compute/interface_tests.rb +3 -2
  142. data/tests/brightbox/requests/compute/load_balancer_tests.rb +57 -11
  143. data/tests/brightbox/requests/compute/server_group_tests.rb +29 -22
  144. data/tests/brightbox/requests/compute/server_tests.rb +41 -22
  145. data/tests/brightbox/requests/compute/server_type_tests.rb +7 -6
  146. data/tests/brightbox/requests/compute/user_tests.rb +11 -16
  147. data/tests/brightbox/requests/compute/zone_tests.rb +7 -6
  148. data/tests/clodo/requests/compute/image_tests.rb +36 -0
  149. data/tests/clodo/requests/compute/server_tests.rb +152 -0
  150. data/tests/compute/helper.rb +1 -1
  151. data/tests/core/credential_tests.rb +2 -2
  152. data/tests/glesys/requests/compute/helper.rb +91 -66
  153. data/tests/glesys/requests/compute/ip_tests.rb +1 -1
  154. data/tests/glesys/requests/compute/server_tests.rb +5 -5
  155. data/tests/helpers/mock_helper.rb +2 -0
  156. data/tests/rackspace/models/dns/zone_tests.rb +14 -0
  157. data/tests/rackspace/models/{access_list_tests.rb → load_balancers/access_list_tests.rb} +0 -0
  158. data/tests/rackspace/models/{access_lists_tests.rb → load_balancers/access_lists_tests.rb} +0 -0
  159. data/tests/rackspace/models/{load_balancer_tests.rb → load_balancers/load_balancer_tests.rb} +25 -0
  160. data/tests/rackspace/models/{load_balancers_tests.rb → load_balancers/load_balancers_tests.rb} +0 -0
  161. data/tests/rackspace/models/{node_tests.rb → load_balancers/node_tests.rb} +0 -0
  162. data/tests/rackspace/models/{nodes_tests.rb → load_balancers/nodes_tests.rb} +0 -0
  163. data/tests/rackspace/models/{virtual_ip_tests.rb → load_balancers/virtual_ip_tests.rb} +0 -0
  164. data/tests/rackspace/models/{virtual_ips_tests.rb → load_balancers/virtual_ips_tests.rb} +0 -0
  165. data/tests/rackspace/requests/dns/dns_tests.rb +4 -2
  166. data/tests/rackspace/requests/load_balancers/error_page_tests.rb +31 -0
  167. data/tests/rackspace/requests/load_balancers/helper.rb +27 -11
  168. data/tests/rackspace/requests/load_balancers/load_balancer_tests.rb +4 -1
  169. data/tests/rackspace/requests/load_balancers/node_tests.rb +24 -25
  170. data/tests/slicehost/requests/compute/slice_tests.rb +2 -2
  171. data/tests/storm_on_demand/requests/compute/server_tests.rb +3 -3
  172. data/tests/vcloud/data/api_+_v1.0_+_admin_+_network_+_2 +110 -0
  173. data/tests/vcloud/data/api_+_v1.0_+_login +5 -0
  174. data/tests/vcloud/data/api_+_v1.0_+_network_+_1 +44 -0
  175. data/tests/vcloud/data/api_+_v1.0_+_network_+_2 +31 -0
  176. data/tests/vcloud/data/api_+_v1.0_+_org_+_1 +17 -0
  177. data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 +369 -0
  178. data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 +139 -0
  179. data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 +155 -0
  180. data/tests/vcloud/data/api_+_v1.0_+_vdc_+_1 +61 -0
  181. data/tests/vcloud/models/compute/conn_helper.rb +20 -0
  182. data/tests/vcloud/models/compute/network_tests.rb +65 -0
  183. data/tests/vcloud/models/compute/networks_tests.rb +42 -0
  184. data/tests/vcloud/models/compute/organization_tests.rb +13 -0
  185. data/tests/vcloud/models/compute/organizations_tests.rb +14 -0
  186. data/tests/vcloud/models/compute/server_tests.rb +136 -0
  187. data/tests/vcloud/models/compute/servers_tests.rb +10 -89
  188. data/tests/vcloud/models/compute/vapp_tests.rb +27 -0
  189. data/tests/vcloud/models/compute/vapps_tests.rb +17 -0
  190. data/tests/vcloud/models/compute/vdc_tests.rb +42 -0
  191. data/tests/vcloud/models/compute/vdcs_tests.rb +17 -0
  192. data/tests/vsphere/requests/compute/vm_clone_tests.rb +2 -6
  193. metadata +151 -55
@@ -16,9 +16,11 @@ module Fog
16
16
  attribute :name
17
17
  attribute :description
18
18
  attribute :default
19
+ attribute :created_at, :type => :time
20
+
21
+ attribute :server_ids, :aliases => "servers"
19
22
 
20
23
  def save
21
- requires :name
22
24
  options = {
23
25
  :name => name,
24
26
  :description => description
@@ -28,30 +30,67 @@ module Fog
28
30
  true
29
31
  end
30
32
 
31
- # Add a server to the server group
32
- #
33
- # == Parameters:
34
- # identifiers::
35
- # An array of identifiers for the servers to add to the group
36
- #
37
- # == Returns:
33
+ def servers
34
+ srv_ids = server_ids.collect {|srv| srv["id"]}
35
+ srv_ids.collect do |srv_id|
36
+ connection.servers.get(srv_id)
37
+ end
38
+ end
39
+
40
+ # Adds specified servers to this server group
38
41
  #
39
- # An excon response object representing the result
42
+ # @param [Array] identifiers array of server identifier strings to add
43
+ # @return [Fog::Compute::ServerGroup]
44
+ def add_servers identifiers
45
+ requires :identity
46
+ options = {
47
+ :servers => server_references(identifiers)
48
+ }
49
+ data = connection.add_servers_server_group identity, options
50
+ merge_attributes data
51
+ end
52
+
53
+ # Removes specified servers from this server group
40
54
  #
41
- # <Excon::Response: ...
55
+ # @param [Array] identifiers array of server identifier strings to remove
56
+ # @return [Fog::Compute::ServerGroup]
57
+ def remove_servers identifiers
58
+ requires :identity
59
+ options = {
60
+ :servers => server_references(identifiers)
61
+ }
62
+ data = connection.remove_servers_server_group identity, options
63
+ merge_attributes data
64
+ end
65
+
66
+ # Moves specified servers from this server group to the specified destination server group
42
67
  #
43
- def add_servers(server_identifiers)
68
+ # @param [Array] identifiers array of server identifier strings to move
69
+ # @param [String] destination_group_id destination server group identifier
70
+ # @return [Fog::Compute::ServerGroup]
71
+ def move_servers identifiers, destination_group_id
44
72
  requires :identity
45
- server_references = server_identifiers.map {|ident| {"server" => ident} }
46
73
  options = {
47
- :servers => server_references
74
+ :servers => server_references(identifiers),
75
+ :destination => destination_group_id
48
76
  }
49
- data = connection.add_servers_server_group(identity, options)
50
- merge_attributes(data)
77
+ data = connection.move_servers_server_group identity, options
78
+ merge_attributes data
51
79
  end
52
80
 
53
- end
81
+ def destroy
82
+ requires :identity
83
+ connection.destroy_server_group(identity)
84
+ true
85
+ end
86
+
87
+ protected
54
88
 
89
+ def server_references identifiers
90
+ identifiers.map {|id| {"server" => id} }
91
+ end
92
+
93
+ end
55
94
  end
56
95
  end
57
- end
96
+ end
@@ -0,0 +1,14 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+
6
+ def remove_firewall_policy(identifier, options)
7
+ return nil if identifier.nil? || identifier == ""
8
+ request("post", "/1.0/firewall_policies/#{identifier}/remove", [202], options)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/fog/clodo.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'fog/core'
2
+
3
+ module Fog
4
+ module Clodo
5
+
6
+ extend Fog::Provider
7
+
8
+ service(:compute, 'clodo/compute', 'Compute')
9
+
10
+ def self.authenticate(options)
11
+ clodo_auth_url = options[:clodo_auth_url] || "api.clodo.ru"
12
+ url = clodo_auth_url.match(/^https?:/) ? \
13
+ clodo_auth_url : 'https://' + clodo_auth_url
14
+ uri = URI.parse(url)
15
+ connection = Fog::Connection.new(url)
16
+ @clodo_api_key = options[:clodo_api_key]
17
+ @clodo_username = options[:clodo_username]
18
+ response = connection.request({
19
+ :expects => [200, 204],
20
+ :headers => {
21
+ 'X-Auth-Key' => @clodo_api_key,
22
+ 'X-Auth-User' => @clodo_username
23
+ },
24
+ :host => uri.host,
25
+ :method => 'GET',
26
+ :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
27
+ })
28
+ response.headers.reject do |key, value|
29
+ !['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
30
+ end
31
+
32
+ end # authenticate
33
+ end # module Clodo
34
+ end # module Fog
@@ -0,0 +1,152 @@
1
+ module Fog
2
+ module Compute
3
+ class Clodo < Fog::Service
4
+
5
+ requires :clodo_api_key, :clodo_username
6
+ recognizes :clodo_auth_url, :persistent
7
+ recognizes :clodo_auth_token, :clodo_management_url
8
+
9
+ model_path 'fog/clodo/models/compute'
10
+ model :image
11
+ collection :images
12
+ model :server
13
+ collection :servers
14
+
15
+ request_path 'fog/clodo/requests/compute'
16
+ request :create_server
17
+ request :delete_server
18
+ request :get_image_details # Not supported by API
19
+ request :list_images
20
+ request :list_images_detail
21
+ request :list_servers
22
+ request :list_servers_detail
23
+ request :get_server_details
24
+ request :server_action
25
+ request :start_server
26
+ request :stop_server
27
+ request :reboot_server
28
+ request :rebuild_server
29
+ request :add_ip_address
30
+ request :delete_ip_address
31
+ request :move_ip_address
32
+ # request :list_addresses
33
+ # request :list_private_addresses
34
+ # request :list_public_addresses
35
+ # request :confirm_resized_server
36
+ # request :revert_resized_server
37
+ # request :resize_server
38
+ # request :update_server
39
+
40
+ class Mock
41
+
42
+ def self.data
43
+ @data ||= Hash.new do |hash, key|
44
+ hash[key] = {
45
+ :last_modified => {
46
+ :images => {},
47
+ :servers => {}
48
+ },
49
+ :images => {},
50
+ :servers => {}
51
+ }
52
+ end
53
+ end
54
+
55
+ def self.reset
56
+ @data = nil
57
+ end
58
+
59
+ def initialize(options={})
60
+ require 'multi_json'
61
+ @clodo_username = options[:clodo_username]
62
+ end
63
+
64
+ def data
65
+ self.class.data[@clodo_username]
66
+ end
67
+
68
+ def reset_data
69
+ self.class.data.delete(@clodo_username)
70
+ end
71
+
72
+ end
73
+
74
+ class Real
75
+
76
+ def initialize(options={})
77
+ require 'multi_json'
78
+ @clodo_api_key = options[:clodo_api_key]
79
+ @clodo_username = options[:clodo_username]
80
+ @clodo_auth_url = options[:clodo_auth_url]
81
+ @clodo_servicenet = options[:clodo_servicenet]
82
+ @clodo_auth_token = options[:clodo_auth_token]
83
+ @clodo_management_url = options[:clodo_management_url]
84
+ @clodo_must_reauthenticate = false
85
+ authenticate
86
+ Excon.ssl_verify_peer = false if options[:clodo_servicenet] == true
87
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
88
+ end
89
+
90
+ def reload
91
+ @connection.reset
92
+ end
93
+
94
+ def request(params)
95
+ begin
96
+ response = @connection.request(params.merge({
97
+ :headers => {
98
+ 'Content-Type' => 'application/json',
99
+ 'Accept' => 'application/json',
100
+ 'X-Auth-Token' => @auth_token
101
+ }.merge!(params[:headers] || {}),
102
+ :host => @host,
103
+ :path => "#{@path}/#{params[:path]}"
104
+ }))
105
+ rescue Excon::Errors::Unauthorized => error
106
+ if error.response.body != 'Bad username or password' # token expiration
107
+ @clodo_must_reauthenticate = true
108
+ authenticate
109
+ retry
110
+ else # bad credentials
111
+ raise error
112
+ end
113
+ rescue Excon::Errors::HTTPStatusError => error
114
+ raise case error
115
+ when Excon::Errors::NotFound
116
+ Fog::Compute::Clodo::NotFound.slurp(error)
117
+ else
118
+ error
119
+ end
120
+ end
121
+ unless response.body.empty?
122
+ response.body = MultiJson.decode(response.body)
123
+ end
124
+ response
125
+ end
126
+
127
+ private
128
+
129
+ def authenticate
130
+ if @clodo_must_reauthenticate || @clodo_auth_token.nil?
131
+ options = {
132
+ :clodo_api_key => @clodo_api_key,
133
+ :clodo_username => @clodo_username,
134
+ :clodo_auth_url => @clodo_auth_url
135
+ }
136
+ credentials = Fog::Clodo.authenticate(options)
137
+ @auth_token = credentials['X-Auth-Token']
138
+ uri = URI.parse(credentials['X-Server-Management-Url'])
139
+ else
140
+ @auth_token = @clodo_auth_token
141
+ uri = URI.parse(@clodo_management_url)
142
+ end
143
+ @host = @clodo_servicenet == true ? "snet-#{uri.host}" : uri.host
144
+ @path = uri.path
145
+ @port = uri.port
146
+ @scheme = uri.scheme
147
+ end
148
+
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,31 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Clodo
6
+
7
+ class Image < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :name
12
+ attribute :vps_type
13
+ attribute :status
14
+ attribute :os_type
15
+ attribute :os_bits
16
+ attribute :os_hvm
17
+
18
+ def initialize(new_attributes)
19
+ super(new_attributes)
20
+ merge_attributes(new_attributes['_attr']) if new_attributes['_attr']
21
+ end
22
+
23
+ def ready?
24
+ status == 'ACTIVE'
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/clodo/models/compute/image'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Clodo
7
+
8
+ class Images < Fog::Collection
9
+
10
+ model Fog::Compute::Clodo::Image
11
+
12
+ def all
13
+ data = connection.list_images_detail.body['images']
14
+ load(data)
15
+ end
16
+
17
+ def get(image_id)
18
+ image = connection.get_image_details(image_id).body['image']
19
+ new(image) if image
20
+ rescue Fog::Compute::Clodo::NotFound
21
+ nil
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,163 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Clodo
6
+
7
+ class Server < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :addresses
12
+ attribute :name
13
+ attribute :image_id, :aliases => 'imageId'
14
+ attribute :type
15
+ attribute :state, :aliases => 'status'
16
+ attribute :type
17
+ attribute :vps_memory
18
+ attribute :vps_memory_max
19
+ attribute :vps_os_title
20
+ attribute :vps_os_bits
21
+ attribute :vps_os_type
22
+ attribute :vps_vnc
23
+ attribute :vps_cpu_load
24
+ attribute :vps_cpu_max
25
+ attribute :vps_cpu_1h_min
26
+ attribute :vps_cpu_1h_max
27
+ attribute :vps_mem_load
28
+ attribute :vps_mem_max
29
+ attribute :vps_mem_1h_min
30
+ attribute :vps_mem_1h_max
31
+ attribute :vps_hdd_load
32
+ attribute :vps_hdd_max
33
+ attribute :vps_traf_rx
34
+ attribute :vps_traf_tx
35
+ attribute :vps_createdate
36
+ attribute :vps_billingdate
37
+ attribute :vps_update
38
+ attribute :vps_update_days
39
+ attribute :vps_root_pass, :aliases => ['adminPass','password']
40
+ attribute :vps_user_pass
41
+ attribute :vps_vnc_pass
42
+
43
+ attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
44
+
45
+ def initialize(attributes={})
46
+ self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666
47
+ super attributes
48
+ end
49
+
50
+ def destroy
51
+ requires :id
52
+ connection.delete_server(id)
53
+ true
54
+ end
55
+
56
+ def image
57
+ requires :image_id
58
+ image_id # API does not support image details request. :-(
59
+ end
60
+
61
+ def private_ip_address
62
+ nil
63
+ end
64
+
65
+ def private_key_path
66
+ @private_key_path ||= Fog.credentials[:private_key_path]
67
+ @private_key_path &&= File.expand_path(@private_key_path)
68
+ end
69
+
70
+ def private_key
71
+ @private_key ||= private_key_path && File.read(private_key_path)
72
+ end
73
+
74
+ def public_ip_address
75
+ pubaddrs = addresses && addresses['public'] ? addresses['public'].select {|ip| ip['primary_ip']} : nil
76
+ pubaddrs && !pubaddrs.empty? ? pubaddrs.first['ip'] : nil
77
+ end
78
+
79
+ def add_ip_address
80
+ connection.add_ip_address(id)
81
+ end
82
+
83
+ def move_ip_address(ip_address)
84
+ connection.move_ip_address(id, ip_address)
85
+ end
86
+
87
+ def delete_ip_address(ip_address)
88
+ connection.delete_ip_address(id, ip_address)
89
+ end
90
+
91
+ def public_key_path
92
+ @public_key_path ||= Fog.credentials[:public_key_path]
93
+ @public_key_path &&= File.expand_path(@public_key_path)
94
+ end
95
+
96
+ def public_key
97
+ @public_key ||= public_key_path && File.read(public_key_path)
98
+ end
99
+
100
+ def ready?
101
+ self.state == 'is_running'
102
+ end
103
+
104
+ def reboot(type = 'SOFT')
105
+ requires :id
106
+ connection.reboot_server(id, type)
107
+ true
108
+ end
109
+
110
+ def save
111
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
112
+ requires :image_id
113
+ data = connection.create_server(image_id, attributes)
114
+ merge_attributes(data.body['server'])
115
+ true
116
+ end
117
+
118
+ def setup(credentials = {})
119
+ requires :public_ip_address, :identity, :public_key, :username
120
+ Fog::SSH.new(public_ip_address, username, credentials).run([
121
+ %{mkdir .ssh},
122
+ %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
123
+ %{passwd -l #{username}},
124
+ %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json},
125
+ ])
126
+ rescue Errno::ECONNREFUSED
127
+ sleep(1)
128
+ retry
129
+ end
130
+
131
+ def ssh(commands)
132
+ requires :public_ip_address, :identity, :username
133
+
134
+ options = {}
135
+ options[:key_data] = [private_key] if private_key
136
+ options[:password] = password if password
137
+ Fog::SSH.new(public_ip_address, username, options).run(commands)
138
+ end
139
+
140
+ def scp(local_path, remote_path, upload_options = {})
141
+ requires :public_ip_address, :username
142
+
143
+ scp_options = {}
144
+ scp_options[:key_data] = [private_key] if private_key
145
+ Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options)
146
+ end
147
+
148
+ def username
149
+ @username ||= 'root'
150
+ end
151
+
152
+ def password
153
+ vps_root_pass
154
+ end
155
+
156
+ private
157
+
158
+ end
159
+
160
+ end
161
+ end
162
+
163
+ end