fog 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -2
- data/README.md +9 -10
- data/Rakefile +15 -299
- data/changelog.txt +153 -0
- data/docs/about/contributing.markdown +1 -0
- data/docs/dns/index.markdown +1 -1
- data/docs/index.markdown +8 -3
- data/fog.gemspec +3 -3
- data/lib/fog.rb +0 -5
- data/lib/fog/aws/auto_scaling.rb +1 -1
- data/lib/fog/aws/cloud_watch.rb +1 -1
- data/lib/fog/aws/compute.rb +2 -1
- data/lib/fog/aws/dynamodb.rb +30 -64
- data/lib/fog/aws/elb.rb +1 -1
- data/lib/fog/aws/glacier.rb +1 -1
- data/lib/fog/aws/iam.rb +1 -0
- data/lib/fog/aws/models/auto_scaling/group.rb +1 -1
- data/lib/fog/aws/models/compute/server.rb +2 -0
- data/lib/fog/aws/models/compute/volume.rb +0 -1
- data/lib/fog/aws/models/iam/user.rb +1 -1
- data/lib/fog/aws/parsers/compute/describe_instances.rb +3 -1
- data/lib/fog/aws/parsers/compute/describe_reserved_instances_offerings.rb +1 -1
- data/lib/fog/aws/parsers/storage/delete_multiple_objects.rb +50 -0
- data/lib/fog/aws/rds.rb +2 -2
- data/lib/fog/aws/requests/compute/describe_availability_zones.rb +3 -0
- data/lib/fog/aws/requests/compute/describe_reserved_instances_offerings.rb +11 -8
- data/lib/fog/aws/requests/compute/modify_volume_attribute.rb +51 -0
- data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +1 -0
- data/lib/fog/aws/requests/storage/delete_multiple_objects.rb +172 -0
- data/lib/fog/aws/signaturev4.rb +1 -1
- data/lib/fog/aws/sqs.rb +1 -1
- data/lib/fog/aws/storage.rb +2 -0
- data/lib/fog/bluebox/requests/compute/create_block.rb +1 -3
- data/lib/fog/brightbox/compute.rb +239 -84
- data/lib/fog/brightbox/models/compute/account.rb +9 -3
- data/lib/fog/brightbox/models/compute/server.rb +2 -1
- data/lib/fog/brightbox/models/compute/servers.rb +33 -1
- data/lib/fog/brightbox/oauth2.rb +164 -0
- data/lib/fog/brightbox/requests/compute/activate_console_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/add_listeners_load_balancer.rb +11 -2
- data/lib/fog/brightbox/requests/compute/add_nodes_load_balancer.rb +11 -2
- data/lib/fog/brightbox/requests/compute/add_servers_server_group.rb +9 -11
- data/lib/fog/brightbox/requests/compute/apply_to_firewall_policy.rb +11 -2
- data/lib/fog/brightbox/requests/compute/create_api_client.rb +11 -2
- data/lib/fog/brightbox/requests/compute/create_application.rb +11 -2
- data/lib/fog/brightbox/requests/compute/create_cloud_ip.rb +11 -1
- data/lib/fog/brightbox/requests/compute/create_firewall_policy.rb +13 -2
- data/lib/fog/brightbox/requests/compute/create_firewall_rule.rb +17 -2
- data/lib/fog/brightbox/requests/compute/create_image.rb +18 -2
- data/lib/fog/brightbox/requests/compute/create_load_balancer.rb +14 -2
- data/lib/fog/brightbox/requests/compute/create_server.rb +17 -2
- data/lib/fog/brightbox/requests/compute/create_server_group.rb +11 -2
- data/lib/fog/brightbox/requests/compute/destroy_api_client.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_application.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_cloud_ip.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_firewall_policy.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_firewall_rule.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_image.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_load_balancer.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/destroy_server_group.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_account.rb +7 -15
- data/lib/fog/brightbox/requests/compute/get_api_client.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_application.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_authenticated_user.rb +1 -3
- data/lib/fog/brightbox/requests/compute/get_cloud_ip.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_firewall_policy.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_firewall_rule.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_image.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_interface.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_load_balancer.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_scoped_account.rb +1 -5
- data/lib/fog/brightbox/requests/compute/get_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_server_group.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_server_type.rb +9 -2
- data/lib/fog/brightbox/requests/compute/get_user.rb +7 -15
- data/lib/fog/brightbox/requests/compute/get_zone.rb +9 -2
- data/lib/fog/brightbox/requests/compute/list_accounts.rb +6 -2
- data/lib/fog/brightbox/requests/compute/list_api_clients.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_applications.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_cloud_ips.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_firewall_policies.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_images.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_load_balancers.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_server_groups.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_server_types.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_servers.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_users.rb +8 -2
- data/lib/fog/brightbox/requests/compute/list_zones.rb +8 -2
- data/lib/fog/brightbox/requests/compute/map_cloud_ip.rb +11 -2
- data/lib/fog/brightbox/requests/compute/move_servers_server_group.rb +10 -12
- data/lib/fog/brightbox/requests/compute/remove_firewall_policy.rb +11 -2
- data/lib/fog/brightbox/requests/compute/remove_listeners_load_balancer.rb +11 -2
- data/lib/fog/brightbox/requests/compute/remove_nodes_load_balancer.rb +11 -2
- data/lib/fog/brightbox/requests/compute/remove_servers_server_group.rb +9 -10
- data/lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb +22 -3
- data/lib/fog/brightbox/requests/compute/reset_ftp_password_scoped_account.rb +18 -0
- data/lib/fog/brightbox/requests/compute/reset_secret_api_client.rb +13 -1
- data/lib/fog/brightbox/requests/compute/reset_secret_application.rb +9 -2
- data/lib/fog/brightbox/requests/compute/shutdown_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/snapshot_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/start_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/stop_server.rb +9 -2
- data/lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb +9 -2
- data/lib/fog/brightbox/requests/compute/update_account.rb +32 -34
- data/lib/fog/brightbox/requests/compute/update_api_client.rb +12 -2
- data/lib/fog/brightbox/requests/compute/update_application.rb +12 -2
- data/lib/fog/brightbox/requests/compute/update_cloud_ip.rb +13 -2
- data/lib/fog/brightbox/requests/compute/update_firewall_rule.rb +16 -1
- data/lib/fog/brightbox/requests/compute/update_image.rb +17 -2
- data/lib/fog/brightbox/requests/compute/update_load_balancer.rb +15 -2
- data/lib/fog/brightbox/requests/compute/update_scoped_account.rb +12 -19
- data/lib/fog/brightbox/requests/compute/update_server.rb +12 -2
- data/lib/fog/brightbox/requests/compute/update_server_group.rb +12 -2
- data/lib/fog/brightbox/requests/compute/update_user.rb +15 -2
- data/lib/fog/cloudstack/models/compute/server.rb +3 -1
- data/lib/fog/core.rb +1 -0
- data/lib/fog/core/connection.rb +1 -0
- data/lib/fog/google/storage.rb +13 -2
- data/lib/fog/libvirt/models/compute/server.rb +1 -0
- data/lib/fog/libvirt/requests/compute/list_domains.rb +2 -2
- data/lib/fog/openstack.rb +57 -58
- data/lib/fog/openstack/compute.rb +15 -14
- data/lib/fog/openstack/identity.rb +10 -2
- data/lib/fog/openstack/image.rb +1 -1
- data/lib/fog/openstack/models/compute/flavor.rb +5 -1
- data/lib/fog/openstack/models/compute/security_group.rb +1 -1
- data/lib/fog/openstack/models/compute/server.rb +5 -0
- data/lib/fog/openstack/models/identity/users.rb +1 -2
- data/lib/fog/openstack/requests/compute/create_flavor.rb +4 -1
- data/lib/fog/openstack/requests/compute/create_security_group.rb +1 -1
- data/lib/fog/openstack/requests/compute/get_limits.rb +93 -0
- data/lib/fog/openstack/requests/compute/list_tenants.rb +1 -0
- data/lib/fog/openstack/requests/compute/release_address.rb +13 -1
- data/lib/fog/openstack/requests/compute/reset_server_state.rb +24 -0
- data/lib/fog/openstack/requests/identity/create_role.rb +1 -1
- data/lib/fog/openstack/requests/identity/set_tenant.rb +21 -0
- data/lib/fog/openstack/volume.rb +2 -1
- data/lib/fog/rackspace/models/compute_v2/server.rb +27 -0
- data/lib/fog/rackspace/models/compute_v2/servers.rb +8 -0
- data/lib/fog/rackspace/models/dns/record.rb +14 -1
- data/lib/fog/rackspace/models/storage/file.rb +68 -2
- data/lib/fog/rackspace/requests/compute_v2/create_server.rb +3 -0
- data/lib/fog/version.rb +5 -0
- data/lib/fog/vsphere/compute.rb +74 -8
- data/lib/fog/vsphere/models/compute/cluster.rb +31 -0
- data/lib/fog/vsphere/models/compute/clusters.rb +26 -0
- data/lib/fog/vsphere/models/compute/datacenter.rb +35 -0
- data/lib/fog/vsphere/models/compute/datacenters.rb +23 -0
- data/lib/fog/vsphere/models/compute/datastore.rb +24 -0
- data/lib/fog/vsphere/models/compute/datastores.rb +25 -0
- data/lib/fog/vsphere/models/compute/folder.rb +28 -0
- data/lib/fog/vsphere/models/compute/folders.rb +27 -0
- data/lib/fog/vsphere/models/compute/interface.rb +39 -0
- data/lib/fog/vsphere/models/compute/interfaces.rb +33 -0
- data/lib/fog/vsphere/models/compute/network.rb +21 -0
- data/lib/fog/vsphere/models/compute/networks.rb +25 -0
- data/lib/fog/vsphere/models/compute/resource_pool.rb +23 -0
- data/lib/fog/vsphere/models/compute/resource_pools.rb +26 -0
- data/lib/fog/vsphere/models/compute/server.rb +78 -12
- data/lib/fog/vsphere/models/compute/servers.rb +16 -20
- data/lib/fog/vsphere/models/compute/template.rb +13 -0
- data/lib/fog/vsphere/models/compute/templates.rb +23 -0
- data/lib/fog/vsphere/models/compute/volume.rb +45 -0
- data/lib/fog/vsphere/models/compute/volumes.rb +33 -0
- data/lib/fog/vsphere/requests/compute/create_vm.rb +114 -0
- data/lib/fog/vsphere/requests/compute/get_cluster.rb +25 -0
- data/lib/fog/vsphere/requests/compute/get_datacenter.rb +29 -0
- data/lib/fog/vsphere/requests/compute/get_datastore.rb +25 -0
- data/lib/fog/vsphere/requests/compute/get_folder.rb +73 -0
- data/lib/fog/vsphere/requests/compute/get_network.rb +25 -0
- data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +26 -0
- data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +62 -0
- data/lib/fog/vsphere/requests/compute/list_clusters.rb +37 -0
- data/lib/fog/vsphere/requests/compute/list_datacenters.rb +34 -0
- data/lib/fog/vsphere/requests/compute/list_datastores.rb +40 -0
- data/lib/fog/vsphere/requests/compute/list_folders.rb +45 -0
- data/lib/fog/vsphere/requests/compute/list_networks.rb +38 -0
- data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +39 -0
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +132 -166
- data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +52 -0
- data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +51 -0
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +6 -8
- data/lib/fog/vsphere/requests/compute/vm_destroy.rb +1 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +1 -2
- data/lib/tasks/changelog_task.rb +98 -0
- data/lib/tasks/documentation_task.rb +155 -0
- data/lib/tasks/test_task.rb +46 -0
- data/tests/aws/models/iam/users_tests.rb +16 -2
- data/tests/aws/requests/auto_scaling/notification_configuration_tests.rb +1 -0
- data/tests/aws/requests/auto_scaling/tag_tests.rb +1 -0
- data/tests/aws/requests/compute/instance_tests.rb +2 -0
- data/tests/aws/requests/compute/volume_tests.rb +8 -0
- data/tests/aws/requests/storage/object_tests.rb +18 -1
- data/tests/aws/requests/storage/versioning_tests.rb +70 -0
- data/tests/brightbox/compute_tests.rb +96 -4
- data/tests/brightbox/models/compute/account_tests.rb +15 -0
- data/tests/brightbox/oauth2_tests.rb +103 -0
- data/tests/brightbox/requests/compute/account_tests.rb +9 -2
- data/tests/brightbox/requests/compute/interface_tests.rb +18 -4
- data/tests/dns/models/record_tests.rb +17 -3
- data/tests/openstack/requests/compute/address_tests.rb +22 -19
- data/tests/openstack/requests/compute/flavor_tests.rb +4 -2
- data/tests/openstack/requests/compute/limit_tests.rb +60 -0
- data/tests/openstack/requests/compute/quota_tests.rb +16 -3
- data/tests/openstack/requests/compute/security_group_tests.rb +1 -1
- data/tests/rackspace/models/compute_v2/servers_tests.rb +6 -0
- data/tests/rackspace/models/storage/file_tests.rb +172 -0
- data/tests/rackspace/requests/dns/helper.rb +12 -26
- data/tests/vsphere/compute_tests.rb +3 -3
- data/tests/vsphere/models/compute/server_tests.rb +1 -2
- data/tests/vsphere/requests/compute/list_virtual_machines_tests.rb +5 -13
- data/tests/vsphere/requests/compute/vm_clone_tests.rb +2 -2
- metadata +59 -11
- data/lib/fog/vsphere/requests/compute/datacenters.rb +0 -34
- data/lib/fog/vsphere/requests/compute/find_vm_by_ref.rb +0 -41
- data/lib/fog/vsphere/requests/compute/vm_create.rb +0 -97
- data/tests/vsphere/requests/compute/find_vm_by_ref_tests.rb +0 -26
- data/tests/vsphere/requests/compute/vm_create_tests.rb +0 -20
@@ -33,6 +33,7 @@ module Fog
|
|
33
33
|
attribute :tenant_id
|
34
34
|
attribute :links
|
35
35
|
attribute :metadata
|
36
|
+
attribute :personality
|
36
37
|
attribute :ipv4_address, :aliases => 'accessIPv4'
|
37
38
|
attribute :ipv6_address, :aliases => 'accessIPv6'
|
38
39
|
attribute :disk_config, :aliases => 'OS-DCF:diskConfig'
|
@@ -54,8 +55,12 @@ module Fog
|
|
54
55
|
|
55
56
|
def create
|
56
57
|
requires :name, :image_id, :flavor_id
|
58
|
+
|
57
59
|
options = {}
|
58
60
|
options[:disk_config] = disk_config unless disk_config.nil?
|
61
|
+
options[:metadata] = metadata unless metadata.nil?
|
62
|
+
options[:personality] = personality unless personality.nil?
|
63
|
+
|
59
64
|
data = connection.create_server(name, image_id, flavor_id, 1, 1, options)
|
60
65
|
merge_attributes(data.body['server'])
|
61
66
|
true
|
@@ -92,6 +97,14 @@ module Fog
|
|
92
97
|
})
|
93
98
|
end
|
94
99
|
end
|
100
|
+
|
101
|
+
def private_ip_address
|
102
|
+
addresses['private'].select{|a| a["version"] == 4}[0]["addr"]
|
103
|
+
end
|
104
|
+
|
105
|
+
def public_ip_address
|
106
|
+
ipv4_address
|
107
|
+
end
|
95
108
|
|
96
109
|
def ready?
|
97
110
|
state == ACTIVE
|
@@ -137,6 +150,20 @@ module Fog
|
|
137
150
|
@password = password
|
138
151
|
true
|
139
152
|
end
|
153
|
+
|
154
|
+
def setup(credentials = {})
|
155
|
+
requires :public_ip_address, :identity, :public_key, :username
|
156
|
+
Fog::SSH.new(public_ip_address, username, credentials).run([
|
157
|
+
%{mkdir .ssh},
|
158
|
+
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
159
|
+
%{passwd -l #{username}},
|
160
|
+
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
|
161
|
+
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
|
162
|
+
])
|
163
|
+
rescue Errno::ECONNREFUSED
|
164
|
+
sleep(1)
|
165
|
+
retry
|
166
|
+
end
|
140
167
|
|
141
168
|
private
|
142
169
|
|
@@ -4,6 +4,7 @@ require 'fog/rackspace/models/compute_v2/server'
|
|
4
4
|
module Fog
|
5
5
|
module Compute
|
6
6
|
class RackspaceV2
|
7
|
+
|
7
8
|
class Servers < Fog::Collection
|
8
9
|
|
9
10
|
model Fog::Compute::RackspaceV2::Server
|
@@ -13,6 +14,13 @@ module Fog
|
|
13
14
|
load(data)
|
14
15
|
end
|
15
16
|
|
17
|
+
def bootstrap(new_attributes = {})
|
18
|
+
server = create(new_attributes)
|
19
|
+
server.wait_for { ready? }
|
20
|
+
server.setup(:password => server.password)
|
21
|
+
server
|
22
|
+
end
|
23
|
+
|
16
24
|
def get(server_id)
|
17
25
|
data = connection.get_server(server_id).body['server']
|
18
26
|
new(data)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'fog/core/model'
|
2
2
|
require 'fog/rackspace/models/dns/callback'
|
3
|
+
require 'ipaddr'
|
3
4
|
|
4
5
|
module Fog
|
5
6
|
module DNS
|
@@ -55,7 +56,19 @@ module Fog
|
|
55
56
|
end
|
56
57
|
|
57
58
|
response = wait_for_job connection.add_records(@zone.identity, [options]).body['jobId']
|
58
|
-
|
59
|
+
|
60
|
+
matching_record = response.body['response']['records'].find do |record|
|
61
|
+
if ['A', 'AAAA'].include?(self.type.upcase)
|
62
|
+
# If this is an A or AAAA record, match by normalized IP address value.
|
63
|
+
(record['name'] == self.name) && (record['type'] == self.type) && (IPAddr.new(record['data']) == IPAddr.new(self.value))
|
64
|
+
else
|
65
|
+
# Other record types are matched by the raw value.
|
66
|
+
(record['name'] == self.name) && (record['type'] == self.type) && (record['data'] == self.value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
merge_attributes(matching_record)
|
71
|
+
|
59
72
|
true
|
60
73
|
end
|
61
74
|
|
@@ -12,6 +12,8 @@ module Fog
|
|
12
12
|
attribute :content_type, :aliases => ['content_type', 'Content-Type']
|
13
13
|
attribute :etag, :aliases => ['hash', 'Etag']
|
14
14
|
attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time
|
15
|
+
attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin']
|
16
|
+
attribute :origin, :aliases => ['Origin']
|
15
17
|
|
16
18
|
def body
|
17
19
|
attributes[:body] ||= if last_modified
|
@@ -32,6 +34,8 @@ module Fog
|
|
32
34
|
def copy(target_directory_key, target_file_key, options={})
|
33
35
|
requires :directory, :key
|
34
36
|
options['Content-Type'] ||= content_type if content_type
|
37
|
+
options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
|
38
|
+
options['Origin'] ||= origin if origin
|
35
39
|
connection.copy_object(directory.key, key, target_directory_key, target_file_key, options)
|
36
40
|
target_directory = connection.directories.new(:key => target_directory_key)
|
37
41
|
target_directory.files.get(target_file_key)
|
@@ -43,6 +47,10 @@ module Fog
|
|
43
47
|
true
|
44
48
|
end
|
45
49
|
|
50
|
+
def metadata
|
51
|
+
@metadata ||= headers_to_metadata
|
52
|
+
end
|
53
|
+
|
46
54
|
def owner=(new_owner)
|
47
55
|
if new_owner
|
48
56
|
attributes[:owner] = {
|
@@ -64,8 +72,14 @@ module Fog
|
|
64
72
|
def save(options = {})
|
65
73
|
requires :body, :directory, :key
|
66
74
|
options['Content-Type'] = content_type if content_type
|
67
|
-
|
68
|
-
|
75
|
+
options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
|
76
|
+
options['Origin'] = origin if origin
|
77
|
+
options.merge!(metadata_to_headers)
|
78
|
+
|
79
|
+
data = connection.put_object(directory.key, key, body, options)
|
80
|
+
update_attributes_from(data)
|
81
|
+
refresh_metadata
|
82
|
+
|
69
83
|
self.content_length = Fog::Storage.get_body_size(body)
|
70
84
|
self.content_type ||= Fog::Storage.get_content_type(body)
|
71
85
|
true
|
@@ -77,6 +91,58 @@ module Fog
|
|
77
91
|
@directory = new_directory
|
78
92
|
end
|
79
93
|
|
94
|
+
def refresh_metadata
|
95
|
+
metadata.reject! {|k, v| v.nil? }
|
96
|
+
end
|
97
|
+
|
98
|
+
def headers_to_metadata
|
99
|
+
key_map = key_mapping
|
100
|
+
Hash[metadata_attributes.map {|k, v| [key_map[k], v] }]
|
101
|
+
end
|
102
|
+
|
103
|
+
def key_mapping
|
104
|
+
key_map = metadata_attributes
|
105
|
+
key_map.each_pair {|k, v| key_map[k] = header_to_key(k)}
|
106
|
+
end
|
107
|
+
|
108
|
+
def header_to_key(opt)
|
109
|
+
opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym
|
110
|
+
end
|
111
|
+
|
112
|
+
def metadata_to_headers
|
113
|
+
header_map = header_mapping
|
114
|
+
Hash[metadata.map {|k, v| [header_map[k], v] }]
|
115
|
+
end
|
116
|
+
|
117
|
+
def header_mapping
|
118
|
+
header_map = metadata.dup
|
119
|
+
header_map.each_pair {|k, v| header_map[k] = key_to_header(k)}
|
120
|
+
end
|
121
|
+
|
122
|
+
def key_to_header(key)
|
123
|
+
metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
|
124
|
+
end
|
125
|
+
|
126
|
+
def metadata_attributes
|
127
|
+
if etag
|
128
|
+
headers = connection.head_object(directory.key, self.key).headers
|
129
|
+
headers.reject! {|k, v| !metadata_attribute?(k)}
|
130
|
+
else
|
131
|
+
{}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def metadata_attribute?(key)
|
136
|
+
key.to_s =~ /^#{metadata_prefix}/
|
137
|
+
end
|
138
|
+
|
139
|
+
def metadata_prefix
|
140
|
+
"X-Object-Meta-"
|
141
|
+
end
|
142
|
+
|
143
|
+
def update_attributes_from(data)
|
144
|
+
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
145
|
+
end
|
80
146
|
end
|
81
147
|
|
82
148
|
end
|
@@ -13,7 +13,10 @@ module Fog
|
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|
16
|
+
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
|
16
17
|
data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
|
18
|
+
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
|
19
|
+
data['server']['personality'] = options[:personality] unless options[:personality].nil?
|
17
20
|
|
18
21
|
request(
|
19
22
|
:body => Fog::JSON.encode(data),
|
data/lib/fog/version.rb
ADDED
data/lib/fog/vsphere/compute.rb
CHANGED
@@ -11,19 +11,50 @@ module Fog
|
|
11
11
|
model_path 'fog/vsphere/models/compute'
|
12
12
|
model :server
|
13
13
|
collection :servers
|
14
|
+
model :datacenter
|
15
|
+
collection :datacenters
|
16
|
+
model :interface
|
17
|
+
collection :interfaces
|
18
|
+
model :volume
|
19
|
+
collection :volumes
|
20
|
+
model :template
|
21
|
+
collection :templates
|
22
|
+
model :cluster
|
23
|
+
collection :clusters
|
24
|
+
model :resource_pool
|
25
|
+
collection :resource_pools
|
26
|
+
model :network
|
27
|
+
collection :networks
|
28
|
+
model :datastore
|
29
|
+
collection :datastores
|
30
|
+
model :folder
|
31
|
+
collection :folders
|
14
32
|
|
15
33
|
request_path 'fog/vsphere/requests/compute'
|
16
34
|
request :current_time
|
17
|
-
request :find_vm_by_ref
|
18
35
|
request :list_virtual_machines
|
19
36
|
request :vm_power_off
|
20
37
|
request :vm_power_on
|
21
38
|
request :vm_reboot
|
22
39
|
request :vm_clone
|
23
|
-
request :vm_create
|
24
40
|
request :vm_destroy
|
25
41
|
request :vm_migrate
|
26
|
-
request :
|
42
|
+
request :list_datacenters
|
43
|
+
request :get_datacenter
|
44
|
+
request :list_clusters
|
45
|
+
request :get_cluster
|
46
|
+
request :list_resource_pools
|
47
|
+
request :get_resource_pool
|
48
|
+
request :list_networks
|
49
|
+
request :get_network
|
50
|
+
request :list_datastores
|
51
|
+
request :get_datastore
|
52
|
+
request :get_folder
|
53
|
+
request :list_folders
|
54
|
+
request :create_vm
|
55
|
+
request :list_vm_interfaces
|
56
|
+
request :list_vm_volumes
|
57
|
+
request :get_virtual_machine
|
27
58
|
request :vm_reconfig_hardware
|
28
59
|
request :vm_reconfig_memory
|
29
60
|
request :vm_reconfig_cpus
|
@@ -36,11 +67,12 @@ module Fog
|
|
36
67
|
attr_reader :vsphere_server
|
37
68
|
attr_reader :vsphere_username
|
38
69
|
|
70
|
+
protected
|
71
|
+
|
39
72
|
ATTR_TO_PROP = {
|
40
73
|
:id => 'config.instanceUuid',
|
41
74
|
:name => 'name',
|
42
75
|
:uuid => 'config.uuid',
|
43
|
-
:instance_uuid => 'config.instanceUuid',
|
44
76
|
:hostname => 'summary.guest.hostName',
|
45
77
|
:operatingsystem => 'summary.guest.guestFullName',
|
46
78
|
:ipaddress => 'guest.ipAddress',
|
@@ -49,9 +81,10 @@ module Fog
|
|
49
81
|
:hypervisor => 'runtime.host',
|
50
82
|
:tools_state => 'guest.toolsStatus',
|
51
83
|
:tools_version => 'guest.toolsVersionStatus',
|
52
|
-
:is_a_template => 'config.template',
|
53
84
|
:memory_mb => 'config.hardware.memoryMB',
|
54
85
|
:cpus => 'config.hardware.numCPU',
|
86
|
+
:overall_status => 'overallStatus',
|
87
|
+
:guest_id => 'summary.guest.guestId',
|
55
88
|
}
|
56
89
|
|
57
90
|
# Utility method to convert a VMware managed object into an attribute hash.
|
@@ -75,9 +108,17 @@ module Fog
|
|
75
108
|
attrs['mo_ref'] = vm_mob_ref._ref
|
76
109
|
# The name method "magically" appears after a VM is ready and
|
77
110
|
# finished cloning.
|
78
|
-
if attrs['hypervisor'].kind_of?(RbVmomi::VIM::HostSystem)
|
79
|
-
|
80
|
-
|
111
|
+
if attrs['hypervisor'].kind_of?(RbVmomi::VIM::HostSystem)
|
112
|
+
begin
|
113
|
+
host = attrs['hypervisor']
|
114
|
+
attrs['datacenter'] = parent_attribute(host.path, :datacenter)[1]
|
115
|
+
attrs['cluster'] = parent_attribute(host.path, :cluster)[1]
|
116
|
+
attrs['hypervisor'] = host.name
|
117
|
+
attrs['resource_pool'] = (vm_mob_ref.resourcePool || host.resourcePool).name rescue nil
|
118
|
+
rescue
|
119
|
+
# If it's not ready, set the hypervisor to nil
|
120
|
+
attrs['hypervisor'] = nil
|
121
|
+
end
|
81
122
|
end
|
82
123
|
# This inline rescue catches any standard error. While a VM is
|
83
124
|
# cloning, a call to the macs method will throw and NoMethodError
|
@@ -86,6 +127,31 @@ module Fog
|
|
86
127
|
end
|
87
128
|
end
|
88
129
|
|
130
|
+
# returns the parent object based on a type
|
131
|
+
# provides both real RbVmomi object and its name.
|
132
|
+
# e.g.
|
133
|
+
#[Datacenter("datacenter-2"), "dc-name"]
|
134
|
+
def parent_attribute path, type
|
135
|
+
element = case type
|
136
|
+
when :datacenter
|
137
|
+
RbVmomi::VIM::Datacenter
|
138
|
+
when :cluster
|
139
|
+
RbVmomi::VIM::ClusterComputeResource
|
140
|
+
when :host
|
141
|
+
RbVmomi::VIM::HostSystem
|
142
|
+
else
|
143
|
+
raise "Unknown type"
|
144
|
+
end
|
145
|
+
path.select {|x| x[0].is_a? element}.flatten
|
146
|
+
rescue
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
|
150
|
+
# returns vmware managed obj id string
|
151
|
+
def managed_obj_id obj
|
152
|
+
obj.to_s.match(/\("(\S+)"\)/)[1]
|
153
|
+
end
|
154
|
+
|
89
155
|
end
|
90
156
|
|
91
157
|
class Mock
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Vsphere
|
4
|
+
|
5
|
+
class Cluster < Fog::Model
|
6
|
+
|
7
|
+
identity :id
|
8
|
+
|
9
|
+
attribute :name
|
10
|
+
attribute :datacenter
|
11
|
+
attribute :num_host
|
12
|
+
attribute :num_cpu_cores
|
13
|
+
attribute :overall_status
|
14
|
+
|
15
|
+
def resource_pools(filters = { })
|
16
|
+
self.attributes[:resource_pools] ||= id.nil? ? [] : connection.resource_pools({
|
17
|
+
:connection => connection,
|
18
|
+
:cluster => name,
|
19
|
+
:datacenter => datacenter
|
20
|
+
}.merge(filters))
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
name
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/vsphere/models/compute/cluster'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Vsphere
|
7
|
+
|
8
|
+
class Clusters < Fog::Collection
|
9
|
+
|
10
|
+
model Fog::Compute::Vsphere::Cluster
|
11
|
+
attr_accessor :datacenter
|
12
|
+
|
13
|
+
def all(filters = {})
|
14
|
+
requires :datacenter
|
15
|
+
load connection.list_clusters(filters.merge(:datacenter => datacenter))
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id)
|
19
|
+
requires :datacenter
|
20
|
+
new connection.get_cluster(id, datacenter)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Vsphere
|
4
|
+
|
5
|
+
class Datacenter < Fog::Model
|
6
|
+
|
7
|
+
identity :id
|
8
|
+
attribute :name
|
9
|
+
attribute :status
|
10
|
+
|
11
|
+
def clusters filters = { }
|
12
|
+
connection.clusters({ :datacenter => name }.merge(filters))
|
13
|
+
end
|
14
|
+
|
15
|
+
def networks filters = { }
|
16
|
+
connection.networks({ :datacenter => name }.merge(filters))
|
17
|
+
end
|
18
|
+
|
19
|
+
def datastores filters = { }
|
20
|
+
connection.datastores({ :datacenter => name }.merge(filters))
|
21
|
+
end
|
22
|
+
|
23
|
+
def vm_folders filters = { }
|
24
|
+
connection.folders({ :datacenter => name, :type => :vm }.merge(filters))
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
name
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|