fog 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +3 -3
- data/changelog.txt +213 -0
- data/docs/compute/index.markdown +15 -1
- data/fog.gemspec +3 -3
- data/lib/fog.rb +1 -1
- data/lib/fog/aws.rb +9 -0
- data/lib/fog/aws/auto_scaling.rb +3 -1
- data/lib/fog/aws/cloud_formation.rb +2 -0
- data/lib/fog/aws/cloud_watch.rb +2 -0
- data/lib/fog/aws/compute.rb +9 -3
- data/lib/fog/aws/elasticache.rb +8 -1
- data/lib/fog/aws/elb.rb +2 -0
- data/lib/fog/aws/models/cloud_watch/metric_statistic.rb +1 -2
- data/lib/fog/aws/models/compute/security_group.rb +1 -1
- data/lib/fog/aws/models/compute/server.rb +3 -1
- data/lib/fog/aws/models/dns/records.rb +3 -3
- data/lib/fog/aws/models/elb/load_balancer.rb +6 -0
- data/lib/fog/aws/models/storage/file.rb +2 -2
- data/lib/fog/aws/models/storage/files.rb +4 -4
- data/lib/fog/aws/parsers/compute/describe_instance_status.rb +64 -0
- data/lib/fog/aws/parsers/compute/describe_security_groups.rb +1 -1
- data/lib/fog/aws/parsers/sqs/receive_message.rb +1 -1
- data/lib/fog/aws/parsers/sts/get_session_token.rb +31 -0
- data/lib/fog/aws/rds.rb +36 -1
- data/lib/fog/aws/requests/compute/describe_availability_zones.rb +3 -0
- data/lib/fog/aws/requests/compute/describe_instance_status.rb +36 -0
- data/lib/fog/aws/requests/compute/describe_security_groups.rb +2 -0
- data/lib/fog/aws/requests/elb/set_load_balancer_listener_ssl_certificate.rb +27 -0
- data/lib/fog/aws/requests/rds/create_db_instance.rb +64 -1
- data/lib/fog/aws/requests/rds/delete_db_instance.rb +19 -3
- data/lib/fog/aws/requests/rds/describe_db_instances.rb +40 -1
- data/lib/fog/aws/requests/rds/describe_db_reserved_instances.rb +1 -1
- data/lib/fog/aws/requests/rds/modify_db_instance.rb +24 -1
- data/lib/fog/aws/requests/rds/reboot_db_instance.rb +17 -1
- data/lib/fog/aws/requests/storage/{hash_to_acl.rb → acl_utils.rb} +8 -0
- data/lib/fog/aws/requests/storage/copy_object.rb +8 -0
- data/lib/fog/aws/requests/storage/get_bucket_acl.rb +7 -1
- data/lib/fog/aws/requests/storage/get_object_acl.rb +7 -1
- data/lib/fog/aws/requests/storage/get_object_http_url.rb +4 -3
- data/lib/fog/aws/requests/storage/get_object_https_url.rb +4 -3
- data/lib/fog/aws/requests/storage/put_bucket_acl.rb +2 -2
- data/lib/fog/aws/requests/storage/put_object_acl.rb +1 -1
- data/lib/fog/aws/requests/sts/get_federation_token.rb +20 -0
- data/lib/fog/aws/requests/sts/get_session_token.rb +18 -0
- data/lib/fog/aws/simpledb.rb +5 -1
- data/lib/fog/aws/sns.rb +2 -0
- data/lib/fog/aws/sqs.rb +5 -1
- data/lib/fog/aws/storage.rb +6 -0
- data/lib/fog/aws/sts.rb +137 -0
- data/lib/fog/bin.rb +1 -0
- data/lib/fog/bin/aws.rb +2 -0
- data/lib/fog/bin/clodo.rb +31 -0
- data/lib/fog/brightbox/compute.rb +7 -0
- data/lib/fog/brightbox/models/compute/cloud_ip.rb +10 -2
- data/lib/fog/brightbox/models/compute/firewall_policies.rb +29 -0
- data/lib/fog/brightbox/models/compute/firewall_policy.rb +65 -0
- data/lib/fog/brightbox/models/compute/firewall_rule.rb +54 -0
- data/lib/fog/brightbox/models/compute/firewall_rules.rb +24 -0
- data/lib/fog/brightbox/models/compute/image.rb +2 -0
- data/lib/fog/brightbox/models/compute/server.rb +41 -6
- data/lib/fog/brightbox/models/compute/server_group.rb +56 -17
- data/lib/fog/brightbox/requests/compute/remove_firewall_policy.rb +14 -0
- data/lib/fog/clodo.rb +34 -0
- data/lib/fog/clodo/compute.rb +152 -0
- data/lib/fog/clodo/models/compute/image.rb +31 -0
- data/lib/fog/clodo/models/compute/images.rb +28 -0
- data/lib/fog/clodo/models/compute/server.rb +163 -0
- data/lib/fog/clodo/models/compute/servers.rb +36 -0
- data/lib/fog/clodo/requests/compute/add_ip_address.rb +49 -0
- data/lib/fog/clodo/requests/compute/create_server.rb +112 -0
- data/lib/fog/clodo/requests/compute/delete_ip_address.rb +47 -0
- data/lib/fog/clodo/requests/compute/delete_server.rb +44 -0
- data/lib/fog/clodo/requests/compute/get_image_details.rb +20 -0
- data/lib/fog/clodo/requests/compute/get_server_details.rb +49 -0
- data/lib/fog/clodo/requests/compute/list_images.rb +48 -0
- data/lib/fog/clodo/requests/compute/list_images_detail.rb +61 -0
- data/lib/fog/clodo/requests/compute/list_servers.rb +50 -0
- data/lib/fog/clodo/requests/compute/list_servers_detail.rb +51 -0
- data/lib/fog/clodo/requests/compute/move_ip_address.rb +34 -0
- data/lib/fog/clodo/requests/compute/reboot_server.rb +19 -0
- data/lib/fog/clodo/requests/compute/rebuild_server.rb +21 -0
- data/lib/fog/clodo/requests/compute/server_action.rb +25 -0
- data/lib/fog/clodo/requests/compute/start_server.rb +19 -0
- data/lib/fog/clodo/requests/compute/stop_server.rb +19 -0
- data/lib/fog/compute.rb +3 -0
- data/lib/fog/core/credentials.rb +3 -3
- data/lib/fog/core/errors.rb +2 -0
- data/lib/fog/core/wait_for.rb +1 -1
- data/lib/fog/dnsmadeeasy/dns.rb +1 -1
- data/lib/fog/libvirt/compute.rb +2 -0
- data/lib/fog/libvirt/models/compute/nodes.rb +1 -3
- data/lib/fog/libvirt/models/compute/server.rb +8 -1
- data/lib/fog/providers.rb +1 -0
- data/lib/fog/rackspace/dns.rb +10 -2
- data/lib/fog/rackspace/load_balancers.rb +3 -0
- data/lib/fog/rackspace/models/compute/server.rb +2 -2
- data/lib/fog/rackspace/models/dns/callback.rb +3 -1
- data/lib/fog/rackspace/models/dns/record.rb +4 -0
- data/lib/fog/rackspace/models/load_balancers/load_balancer.rb +18 -8
- data/lib/fog/rackspace/requests/load_balancers/delete_nodes.rb +1 -2
- data/lib/fog/rackspace/requests/load_balancers/get_error_page.rb +15 -0
- data/lib/fog/rackspace/requests/load_balancers/list_load_balancers.rb +8 -2
- data/lib/fog/rackspace/requests/load_balancers/remove_error_page.rb +15 -0
- data/lib/fog/rackspace/requests/load_balancers/set_error_page.rb +21 -0
- data/lib/fog/vcloud/compute.rb +7 -1
- data/lib/fog/vcloud/models/compute/catalogs.rb +4 -5
- data/lib/fog/vcloud/models/compute/helpers/status.rb +37 -0
- data/lib/fog/vcloud/models/compute/network.rb +13 -49
- data/lib/fog/vcloud/models/compute/networks.rb +12 -3
- data/lib/fog/vcloud/models/compute/organization.rb +44 -0
- data/lib/fog/vcloud/models/compute/organizations.rb +29 -0
- data/lib/fog/vcloud/models/compute/server.rb +35 -56
- data/lib/fog/vcloud/models/compute/servers.rb +11 -13
- data/lib/fog/vcloud/models/compute/vapp.rb +41 -0
- data/lib/fog/vcloud/models/compute/vapps.rb +32 -0
- data/lib/fog/vcloud/models/compute/vdc.rb +11 -26
- data/lib/fog/vcloud/models/compute/vdcs.rb +6 -8
- data/lib/fog/vcloud/requests/compute/get_server.rb +10 -0
- data/lib/fog/vsphere/compute.rb +1 -0
- data/lib/fog/vsphere/models/compute/server.rb +18 -0
- data/lib/fog/vsphere/models/compute/servers.rb +8 -2
- data/lib/fog/vsphere/requests/compute/datacenters.rb +34 -0
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +132 -91
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +76 -37
- data/spec/lib/fog/aws/parsers/sqs/receive_message_spec.rb +58 -0
- data/tests/aws/models/elb/model_tests.rb +5 -0
- data/tests/aws/requests/compute/instance_tests.rb +23 -0
- data/tests/aws/requests/compute/security_group_tests.rb +1 -0
- data/tests/aws/requests/elb/listener_tests.rb +4 -0
- data/tests/aws/requests/storage/{hash_to_acl_tests.rb → acl_utils_tests.rb} +38 -2
- data/tests/aws/requests/storage/bucket_tests.rb +0 -3
- data/tests/aws/requests/storage/object_tests.rb +2 -4
- data/tests/aws/requests/sts/get_federation_token_tests.rb +21 -0
- data/tests/aws/requests/sts/session_token_tests.rb +16 -0
- data/tests/brightbox/requests/compute/account_tests.rb +11 -6
- data/tests/brightbox/requests/compute/api_client_tests.rb +23 -12
- data/tests/brightbox/requests/compute/cloud_ip_tests.rb +32 -17
- data/tests/brightbox/requests/compute/helper.rb +29 -3
- data/tests/brightbox/requests/compute/image_tests.rb +17 -14
- data/tests/brightbox/requests/compute/interface_tests.rb +3 -2
- data/tests/brightbox/requests/compute/load_balancer_tests.rb +57 -11
- data/tests/brightbox/requests/compute/server_group_tests.rb +29 -22
- data/tests/brightbox/requests/compute/server_tests.rb +41 -22
- data/tests/brightbox/requests/compute/server_type_tests.rb +7 -6
- data/tests/brightbox/requests/compute/user_tests.rb +11 -16
- data/tests/brightbox/requests/compute/zone_tests.rb +7 -6
- data/tests/clodo/requests/compute/image_tests.rb +36 -0
- data/tests/clodo/requests/compute/server_tests.rb +152 -0
- data/tests/compute/helper.rb +1 -1
- data/tests/core/credential_tests.rb +2 -2
- data/tests/glesys/requests/compute/helper.rb +91 -66
- data/tests/glesys/requests/compute/ip_tests.rb +1 -1
- data/tests/glesys/requests/compute/server_tests.rb +5 -5
- data/tests/helpers/mock_helper.rb +2 -0
- data/tests/rackspace/models/dns/zone_tests.rb +14 -0
- data/tests/rackspace/models/{access_list_tests.rb → load_balancers/access_list_tests.rb} +0 -0
- data/tests/rackspace/models/{access_lists_tests.rb → load_balancers/access_lists_tests.rb} +0 -0
- data/tests/rackspace/models/{load_balancer_tests.rb → load_balancers/load_balancer_tests.rb} +25 -0
- data/tests/rackspace/models/{load_balancers_tests.rb → load_balancers/load_balancers_tests.rb} +0 -0
- data/tests/rackspace/models/{node_tests.rb → load_balancers/node_tests.rb} +0 -0
- data/tests/rackspace/models/{nodes_tests.rb → load_balancers/nodes_tests.rb} +0 -0
- data/tests/rackspace/models/{virtual_ip_tests.rb → load_balancers/virtual_ip_tests.rb} +0 -0
- data/tests/rackspace/models/{virtual_ips_tests.rb → load_balancers/virtual_ips_tests.rb} +0 -0
- data/tests/rackspace/requests/dns/dns_tests.rb +4 -2
- data/tests/rackspace/requests/load_balancers/error_page_tests.rb +31 -0
- data/tests/rackspace/requests/load_balancers/helper.rb +27 -11
- data/tests/rackspace/requests/load_balancers/load_balancer_tests.rb +4 -1
- data/tests/rackspace/requests/load_balancers/node_tests.rb +24 -25
- data/tests/slicehost/requests/compute/slice_tests.rb +2 -2
- data/tests/storm_on_demand/requests/compute/server_tests.rb +3 -3
- data/tests/vcloud/data/api_+_v1.0_+_admin_+_network_+_2 +110 -0
- data/tests/vcloud/data/api_+_v1.0_+_login +5 -0
- data/tests/vcloud/data/api_+_v1.0_+_network_+_1 +44 -0
- data/tests/vcloud/data/api_+_v1.0_+_network_+_2 +31 -0
- data/tests/vcloud/data/api_+_v1.0_+_org_+_1 +17 -0
- data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 +369 -0
- data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 +139 -0
- data/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 +155 -0
- data/tests/vcloud/data/api_+_v1.0_+_vdc_+_1 +61 -0
- data/tests/vcloud/models/compute/conn_helper.rb +20 -0
- data/tests/vcloud/models/compute/network_tests.rb +65 -0
- data/tests/vcloud/models/compute/networks_tests.rb +42 -0
- data/tests/vcloud/models/compute/organization_tests.rb +13 -0
- data/tests/vcloud/models/compute/organizations_tests.rb +14 -0
- data/tests/vcloud/models/compute/server_tests.rb +136 -0
- data/tests/vcloud/models/compute/servers_tests.rb +10 -89
- data/tests/vcloud/models/compute/vapp_tests.rb +27 -0
- data/tests/vcloud/models/compute/vapps_tests.rb +17 -0
- data/tests/vcloud/models/compute/vdc_tests.rb +42 -0
- data/tests/vcloud/models/compute/vdcs_tests.rb +17 -0
- data/tests/vsphere/requests/compute/vm_clone_tests.rb +2 -6
- 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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
#
|
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
|
-
#
|
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
|
-
|
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.
|
50
|
-
merge_attributes
|
77
|
+
data = connection.move_servers_server_group identity, options
|
78
|
+
merge_attributes data
|
51
79
|
end
|
52
80
|
|
53
|
-
|
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
|