fog 1.12.1 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/Gemfile +5 -0
- data/Rakefile +14 -4
- data/bin/fog +22 -0
- data/changelog.txt +262 -0
- data/fog.gemspec +8 -4
- data/lib/fog/aws.rb +11 -0
- data/lib/fog/aws/auto_scaling.rb +15 -18
- data/lib/fog/aws/beanstalk.rb +8 -10
- data/lib/fog/aws/cloud_formation.rb +9 -12
- data/lib/fog/aws/compute.rb +8 -10
- data/lib/fog/aws/credential_fetcher.rb +6 -6
- data/lib/fog/aws/elasticache.rb +13 -17
- data/lib/fog/aws/elb.rb +29 -31
- data/lib/fog/aws/iam.rb +10 -13
- data/lib/fog/aws/models/auto_scaling/group.rb +6 -3
- data/lib/fog/aws/models/compute/spot_request.rb +1 -11
- data/lib/fog/aws/models/rds/log_file.rb +26 -0
- data/lib/fog/aws/models/rds/log_files.rb +50 -0
- data/lib/fog/aws/models/rds/server.rb +3 -1
- data/lib/fog/aws/models/rds/snapshot.rb +1 -0
- data/lib/fog/aws/models/rds/snapshots.rb +20 -13
- data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
- data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
- data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
- data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
- data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
- data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
- data/lib/fog/aws/rds.rb +27 -14
- data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
- data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
- data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
- data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
- data/lib/fog/aws/requests/rds/describe_db_log_files.rb +67 -0
- data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
- data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
- data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
- data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
- data/lib/fog/aws/requests/storage/get_object.rb +1 -1
- data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
- data/lib/fog/aws/ses.rb +26 -9
- data/lib/fog/aws/storage.rb +2 -1
- data/lib/fog/aws/sts.rb +31 -21
- data/lib/fog/bin.rb +0 -1
- data/lib/fog/bin/openstack.rb +5 -0
- data/lib/fog/brightbox/compute.rb +20 -212
- data/lib/fog/brightbox/compute/shared.rb +232 -0
- data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
- data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
- data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
- data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
- data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
- data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
- data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
- data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
- data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
- data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
- data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
- data/lib/fog/core.rb +7 -2
- data/lib/fog/core/connection.rb +62 -29
- data/lib/fog/core/deprecated/connection.rb +24 -0
- data/lib/fog/core/parser.rb +1 -1
- data/lib/fog/digitalocean/examples/getting_started.md +1 -1
- data/lib/fog/digitalocean/models/compute/server.rb +2 -2
- data/lib/fog/google/compute.rb +31 -7
- data/lib/fog/google/models/compute/disk.rb +80 -0
- data/lib/fog/google/models/compute/disks.rb +28 -0
- data/lib/fog/google/models/compute/image.rb +36 -0
- data/lib/fog/google/models/compute/server.rb +46 -33
- data/lib/fog/google/models/compute/servers.rb +15 -8
- data/lib/fog/google/requests/compute/delete_server.rb +5 -2
- data/lib/fog/google/requests/compute/get_disk.rb +3 -0
- data/lib/fog/google/requests/compute/get_server.rb +7 -1
- data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
- data/lib/fog/google/requests/compute/insert_server.rb +51 -22
- data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
- data/lib/fog/google/requests/storage/get_object.rb +1 -1
- data/lib/fog/hp/requests/storage/get_object.rb +1 -1
- data/lib/fog/hp/storage.rb +26 -9
- data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
- data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
- data/lib/fog/{core/json.rb → json.rb} +13 -2
- data/lib/fog/metering.rb +25 -0
- data/lib/fog/openstack.rb +1 -0
- data/lib/fog/openstack/metering.rb +215 -0
- data/lib/fog/openstack/models/compute/flavors.rb +2 -2
- data/lib/fog/openstack/models/compute/metadata.rb +1 -1
- data/lib/fog/openstack/models/compute/server.rb +5 -2
- data/lib/fog/openstack/models/image/images.rb +1 -1
- data/lib/fog/openstack/models/metering/meter.rb +0 -0
- data/lib/fog/openstack/models/metering/meters.rb +0 -0
- data/lib/fog/openstack/models/metering/resource.rb +24 -0
- data/lib/fog/openstack/models/metering/resources.rb +25 -0
- data/lib/fog/openstack/models/volume/volume.rb +3 -1
- data/lib/fog/openstack/models/volume/volumes.rb +2 -1
- data/lib/fog/openstack/network.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
- data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
- data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
- data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
- data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
- data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
- data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
- data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
- data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
- data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
- data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
- data/lib/fog/rackspace.rb +16 -1
- data/lib/fog/rackspace/block_storage.rb +13 -28
- data/lib/fog/rackspace/cdn.rb +10 -24
- data/lib/fog/rackspace/compute.rb +17 -45
- data/lib/fog/rackspace/compute_v2.rb +13 -33
- data/lib/fog/rackspace/databases.rb +13 -29
- data/lib/fog/rackspace/dns.rb +27 -23
- data/lib/fog/rackspace/identity.rb +10 -26
- data/lib/fog/rackspace/load_balancers.rb +13 -29
- data/lib/fog/rackspace/mock_data.rb +3 -3
- data/lib/fog/rackspace/models/compute/server.rb +1 -1
- data/lib/fog/rackspace/models/dns/zones.rb +34 -21
- data/lib/fog/rackspace/models/identity/users.rb +2 -2
- data/lib/fog/rackspace/models/storage/file.rb +1 -0
- data/lib/fog/rackspace/requests/dns/list_domains.rb +2 -2
- data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
- data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
- data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
- data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
- data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
- data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
- data/lib/fog/rackspace/service.rb +43 -1
- data/lib/fog/rackspace/storage.rb +25 -43
- data/lib/fog/riakcs/provisioning.rb +2 -1
- data/lib/fog/riakcs/usage.rb +2 -1
- data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
- data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
- data/lib/fog/version.rb +1 -1
- data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
- data/lib/fog/xenserver/compute.rb +2 -0
- data/lib/fog/xenserver/models/compute/server.rb +9 -7
- data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
- data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
- data/lib/fog/xml.rb +21 -0
- data/lib/fog/xml/sax_parser_connection.rb +43 -0
- data/lib/tasks/changelog_task.rb +1 -0
- data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
- data/tests/aws/requests/compute/volume_tests.rb +3 -3
- data/tests/aws/requests/rds/helper.rb +14 -0
- data/tests/aws/requests/rds/log_file_tests.rb +19 -0
- data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
- data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
- data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
- data/tests/brightbox/requests/compute/helper.rb +46 -2
- data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
- data/tests/core/connection_tests.rb +26 -0
- data/tests/helper.rb +13 -0
- data/tests/openstack/requests/metering/meter_tests.rb +52 -0
- data/tests/openstack/requests/metering/resource_tests.rb +19 -0
- data/tests/openvz/helper.rb +14 -8
- data/tests/rackspace/block_storage_tests.rb +9 -0
- data/tests/rackspace/compute_tests.rb +9 -0
- data/tests/rackspace/compute_v2_tests.rb +9 -0
- data/tests/rackspace/databases_tests.rb +9 -0
- data/tests/rackspace/dns_tests.rb +20 -0
- data/tests/rackspace/helper.rb +12 -1
- data/tests/rackspace/identity_tests.rb +25 -0
- data/tests/rackspace/load_balancer_tests.rb +10 -0
- data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
- data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
- data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
- data/tests/rackspace/models/dns/zones_tests.rb +19 -5
- data/tests/rackspace/models/storage/file_tests.rb +22 -6
- data/tests/rackspace/rackspace_tests.rb +35 -0
- data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
- data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
- data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
- data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
- data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
- data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
- data/tests/rackspace/requests/databases/database_tests.rb +23 -20
- data/tests/rackspace/requests/databases/user_tests.rb +6 -6
- data/tests/rackspace/requests/identity/user_tests.rb +4 -1
- data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
- data/tests/rackspace/requests/storage/large_object_tests.rb +303 -59
- data/tests/rackspace/requests/storage/object_tests.rb +73 -18
- data/tests/rackspace/service_tests.rb +83 -0
- data/tests/rackspace/storage_tests.rb +9 -0
- data/tests/xenserver/models/compute/server_tests.rb +11 -1
- metadata +89 -19
- data/tests/core/user_agent_tests.rb +0 -6
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class Google
|
6
|
+
|
7
|
+
class Disk < Fog::Model
|
8
|
+
|
9
|
+
identity :name
|
10
|
+
|
11
|
+
attribute :kind, :aliases => 'kind'
|
12
|
+
attribute :id, :aliases => 'id'
|
13
|
+
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
14
|
+
attribute :zone_name, :aliases => 'zone'
|
15
|
+
attribute :status, :aliases => 'status'
|
16
|
+
attribute :description, :aliases => 'description'
|
17
|
+
attribute :size_gb, :aliases => 'sizeGb'
|
18
|
+
attribute :self_link, :aliases => 'selfLink'
|
19
|
+
attribute :image_name, :aliases => 'image'
|
20
|
+
|
21
|
+
def save
|
22
|
+
data = service.insert_disk(name, size_gb, zone_name, image_name).body
|
23
|
+
data = service.backoff_if_unfound {service.get_disk(name, zone_name).body}
|
24
|
+
service.disks.merge_attributes(data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
requires :name, :zone
|
29
|
+
service.delete_disk(name, zone)
|
30
|
+
end
|
31
|
+
|
32
|
+
def zone
|
33
|
+
if self.zone_name.is_a? String
|
34
|
+
service.get_zone(self.zone_name.split('/')[-1]).body["name"]
|
35
|
+
elsif zone_name.is_a? Excon::Response
|
36
|
+
service.get_zone(zone_name.body["name"]).body["name"]
|
37
|
+
else
|
38
|
+
self.zone_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_as_boot_disk(writable=true)
|
43
|
+
mode = writable ? 'READ_WRITE' : 'READ_ONLY'
|
44
|
+
return {
|
45
|
+
'name' => name,
|
46
|
+
'type' => 'PERSISTENT',
|
47
|
+
'boot' => true,
|
48
|
+
'source' => self_link,
|
49
|
+
'mode' => mode
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def ready?
|
54
|
+
data = service.get_disk(self.name, self.zone_name).body
|
55
|
+
data['zone_name'] = self.zone_name
|
56
|
+
self.merge_attributes(data)
|
57
|
+
self.status == RUNNING_STATE
|
58
|
+
end
|
59
|
+
|
60
|
+
def reload
|
61
|
+
requires :identity
|
62
|
+
requires :zone_name
|
63
|
+
|
64
|
+
return unless data = begin
|
65
|
+
collection.get(identity, zone_name)
|
66
|
+
rescue Excon::Errors::SocketError
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
new_attributes = data.attributes
|
71
|
+
merge_attributes(new_attributes)
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
RUNNING_STATE = "READY"
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/google/models/compute/disk'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Google
|
7
|
+
|
8
|
+
class Disks < Fog::Collection
|
9
|
+
|
10
|
+
model Fog::Compute::Google::Disk
|
11
|
+
|
12
|
+
def all(zone)
|
13
|
+
data = service.list_disks(zone).body["items"]
|
14
|
+
load(data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(identity, zone)
|
18
|
+
data = service.get_disk(identity, zone).body
|
19
|
+
new(data)
|
20
|
+
rescue Excon::Errors::NotFound
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -12,6 +12,42 @@ module Fog
|
|
12
12
|
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
13
13
|
attribute :description
|
14
14
|
attribute :preferred_kernel, :aliases => 'preferredKernel'
|
15
|
+
attribute :project
|
16
|
+
|
17
|
+
def reload
|
18
|
+
requires :name
|
19
|
+
|
20
|
+
data = {}
|
21
|
+
|
22
|
+
# Try looking for the image in known projects
|
23
|
+
[
|
24
|
+
self.service.project,
|
25
|
+
'google',
|
26
|
+
'debian-cloud',
|
27
|
+
'centos-cloud',
|
28
|
+
].each do |owner|
|
29
|
+
begin
|
30
|
+
data = service.get_image(name, owner).body
|
31
|
+
data[:project] = owner
|
32
|
+
rescue
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
raise ArgumentError, 'Specified image was not found' if data.empty?
|
37
|
+
|
38
|
+
self.merge_attributes(data)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def save
|
43
|
+
requires :name
|
44
|
+
|
45
|
+
reload
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_url
|
49
|
+
"#{self.project}/global/images/#{name}"
|
50
|
+
end
|
15
51
|
|
16
52
|
end
|
17
53
|
end
|
@@ -13,11 +13,13 @@ module Fog
|
|
13
13
|
attribute :state, :aliases => 'status'
|
14
14
|
attribute :zone_name, :aliases => 'zone'
|
15
15
|
attribute :machine_type, :aliases => 'machineType'
|
16
|
+
attribute :disks, :aliases => 'disks'
|
17
|
+
attribute :kernel, :aliases => 'kernel'
|
16
18
|
attribute :metadata
|
17
19
|
|
18
20
|
def destroy
|
19
|
-
requires :name
|
20
|
-
service.delete_server(name)
|
21
|
+
requires :name, :zone
|
22
|
+
service.delete_server(name, zone)
|
21
23
|
end
|
22
24
|
|
23
25
|
def image
|
@@ -25,53 +27,64 @@ module Fog
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def public_ip_address
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
ip = nil
|
31
|
+
if self.network_interfaces
|
32
|
+
self.network_interfaces.each do |netif|
|
33
|
+
netif["accessConfigs"].each do |access_config|
|
34
|
+
if access_config["name"] == "External NAT"
|
35
|
+
ip = access_config['natIP']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
32
39
|
end
|
40
|
+
|
41
|
+
ip
|
33
42
|
end
|
34
43
|
|
35
44
|
def ready?
|
36
|
-
|
37
|
-
data['zone_name'] = self.zone_name
|
38
|
-
self.merge_attributes(data)
|
39
|
-
self.state == RUNNING_STATE
|
45
|
+
self.state == RUNNING
|
40
46
|
end
|
41
47
|
|
42
48
|
def zone
|
43
|
-
|
49
|
+
if self.zone_name.is_a? String
|
50
|
+
service.get_zone(self.zone_name.split('/')[-1]).body["name"]
|
51
|
+
elsif zone_name.is_a? Excon::Response
|
52
|
+
service.get_zone(zone_name.body["name"]).body["name"]
|
53
|
+
else
|
54
|
+
self.zone_name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def reload
|
59
|
+
data = service.get_server(self.name, self.zone).body
|
60
|
+
self.merge_attributes(data)
|
44
61
|
end
|
45
62
|
|
46
63
|
def save
|
47
64
|
requires :name
|
48
|
-
requires :image_name
|
49
65
|
requires :machine_type
|
50
66
|
requires :zone_name
|
51
67
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
zone_name,
|
56
|
-
machine_type)
|
57
|
-
|
58
|
-
data = service.get_server(self.name, self.zone_name).body
|
59
|
-
service.servers.merge_attributes(data)
|
60
|
-
end
|
68
|
+
if self.metadata.nil?
|
69
|
+
self.metadata = {}
|
70
|
+
end
|
61
71
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
rescue Errno::ECONNREFUSED
|
66
|
-
sleep(1)
|
67
|
-
retry
|
68
|
-
end
|
72
|
+
self.metadata.merge!({
|
73
|
+
"sshKeys" => "#{username}:#{File.read(public_key_path).strip}"
|
74
|
+
}) if public_key_path
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
76
|
+
options = {
|
77
|
+
'image' => image_name,
|
78
|
+
'machineType' => machine_type,
|
79
|
+
'networkInterfaces' => network_interfaces,
|
80
|
+
'disks' => disks,
|
81
|
+
'kernel' => kernel,
|
82
|
+
'metadata' => metadata
|
83
|
+
}
|
84
|
+
options.delete_if {|key, value| value.nil?}
|
85
|
+
service.insert_server(name, zone_name, options)
|
86
|
+
data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
|
87
|
+
service.servers.merge_attributes(data)
|
75
88
|
end
|
76
89
|
|
77
90
|
end
|
@@ -22,20 +22,20 @@ module Fog
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def get(identity, zone=nil)
|
25
|
-
|
25
|
+
response = nil
|
26
26
|
if zone.nil?
|
27
27
|
service.list_zones.body['items'].each do |zone|
|
28
|
-
|
29
|
-
break if
|
28
|
+
response = service.get_server(identity, zone['name'])
|
29
|
+
break if response.status == 200
|
30
30
|
end
|
31
31
|
else
|
32
|
-
|
32
|
+
response = service.get_server(identity, zone)
|
33
33
|
end
|
34
34
|
|
35
|
-
if
|
35
|
+
if response.nil? or response.status != 200
|
36
36
|
nil
|
37
37
|
else
|
38
|
-
new(
|
38
|
+
new(response.body)
|
39
39
|
end
|
40
40
|
rescue Excon::Errors::NotFound
|
41
41
|
nil
|
@@ -44,15 +44,22 @@ module Fog
|
|
44
44
|
def bootstrap(new_attributes = {})
|
45
45
|
defaults = {
|
46
46
|
:name => "fog-#{Time.now.to_i}",
|
47
|
-
:image_name => "
|
47
|
+
:image_name => "debian-7-wheezy-v20130617",
|
48
48
|
:machine_type => "n1-standard-1",
|
49
49
|
:zone_name => "us-central1-a",
|
50
50
|
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
|
51
51
|
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
|
52
|
+
:username => ENV['USER'],
|
52
53
|
}
|
54
|
+
if new_attributes[:disks]
|
55
|
+
new_attributes[:disks].each do |disk|
|
56
|
+
defaults.delete :image_name if disk['boot']
|
57
|
+
end
|
58
|
+
end
|
53
59
|
|
54
60
|
server = create(defaults.merge(new_attributes))
|
55
|
-
server.wait_for
|
61
|
+
server.wait_for { sshable? }
|
62
|
+
|
56
63
|
server
|
57
64
|
end
|
58
65
|
end
|
@@ -15,11 +15,14 @@ module Fog
|
|
15
15
|
def delete_server(server_name, zone_name=nil)
|
16
16
|
if zone_name.nil?
|
17
17
|
list_zones.body['items'].each do |zone|
|
18
|
-
|
19
|
-
if data["error"].nil?
|
18
|
+
if get_server(server_name, zone['name']).status == 200
|
20
19
|
zone_name = zone['name']
|
21
20
|
end
|
22
21
|
end
|
22
|
+
else
|
23
|
+
if zone_name.is_a? Excon::Response
|
24
|
+
zone_name = zone_name.body["name"]
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
25
28
|
api_method = @compute.instances.delete
|
@@ -13,10 +13,16 @@ module Fog
|
|
13
13
|
class Real
|
14
14
|
|
15
15
|
def get_server(server_name, zone_name)
|
16
|
+
if zone_name.is_a? Excon::Response
|
17
|
+
zone = zone_name.body["name"]
|
18
|
+
else
|
19
|
+
zone = zone_name
|
20
|
+
end
|
21
|
+
|
16
22
|
api_method = @compute.instances.get
|
17
23
|
parameters = {
|
18
24
|
'project' => @project,
|
19
|
-
'zone' =>
|
25
|
+
'zone' => zone,
|
20
26
|
'instance' => server_name
|
21
27
|
}
|
22
28
|
|
@@ -12,19 +12,25 @@ module Fog
|
|
12
12
|
|
13
13
|
class Real
|
14
14
|
|
15
|
-
def insert_disk(disk_name, disk_size, zone_name=@default_zone)
|
15
|
+
def insert_disk(disk_name, disk_size, zone_name=@default_zone, image_name=nil)
|
16
16
|
api_method = @compute.disks.insert
|
17
17
|
parameters = {
|
18
18
|
'project' => @project,
|
19
19
|
'zone' => zone_name
|
20
20
|
}
|
21
|
+
if image_name
|
22
|
+
# We don't know the owner of the image.
|
23
|
+
image = images.create({:name => image_name})
|
24
|
+
@image_url = @api_url + image.resource_url
|
25
|
+
parameters['sourceImage'] = @image_url
|
26
|
+
end
|
21
27
|
body_object = {
|
22
28
|
'name' => disk_name,
|
23
29
|
'sizeGb' => disk_size,
|
24
30
|
}
|
25
31
|
|
26
32
|
result = self.build_result(api_method, parameters,
|
27
|
-
body_object
|
33
|
+
body_object)
|
28
34
|
response = self.build_response(result)
|
29
35
|
end
|
30
36
|
|
@@ -12,38 +12,67 @@ module Fog
|
|
12
12
|
|
13
13
|
class Real
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# We need to check if the image is owned by the user or a global image.
|
20
|
-
if get_image(image_name, @project).data['code'] == 200
|
21
|
-
image_url = @api_url + @project + "/global/images/#{image_name}"
|
22
|
-
else
|
23
|
-
image_url = @api_url + "google/global/images/#{image_name}"
|
24
|
-
end
|
15
|
+
def format_metadata(metadata)
|
16
|
+
{ "items" => metadata.map {|k,v| {"key" => k, "value" => v}} }
|
17
|
+
end
|
25
18
|
|
19
|
+
def insert_server(server_name, zone_name, options={}, *deprecated_args)
|
20
|
+
if deprecated_args.length > 0 or not options.is_a? Hash
|
21
|
+
raise ArgumentError.new 'Too many parameters specified. This may be the cause of code written for an outdated'\
|
22
|
+
' version of fog. Usage: server_name, zone_name, [options]'
|
23
|
+
end
|
26
24
|
api_method = @compute.instances.insert
|
27
25
|
parameters = {
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
body_object = {
|
32
|
-
'name' => server_name,
|
33
|
-
'image' => image_url,
|
34
|
-
'machineType' => @api_url + @project + "/global/machineTypes/#{machine_name}",
|
35
|
-
'networkInterfaces' => [{
|
36
|
-
'network' => @api_url + @project + "/global/networks/#{network_name}"
|
37
|
-
}]
|
26
|
+
'project' => @project,
|
27
|
+
'zone' => zone_name,
|
38
28
|
}
|
29
|
+
body_object = {:name => server_name}
|
30
|
+
|
31
|
+
if options.has_key? 'image'
|
32
|
+
image_name = options.delete 'image'
|
33
|
+
# We don't know the owner of the image.
|
34
|
+
image = images.create({:name => image_name})
|
35
|
+
@image_url = @api_url + image.resource_url
|
36
|
+
body_object['image'] = @image_url
|
37
|
+
end
|
38
|
+
body_object['machineType'] = @api_url + @project + "/zones/#{zone_name}/machineTypes/#{options.delete 'machineType'}"
|
39
|
+
networkInterfaces = []
|
40
|
+
if @default_network
|
41
|
+
networkInterfaces << {
|
42
|
+
'network' => @api_url + @project + "/global/networks/#{@default_network}",
|
43
|
+
'accessConfigs' => [
|
44
|
+
{'type' => 'ONE_TO_ONE_NAT',
|
45
|
+
'name' => 'External NAT'}
|
46
|
+
]
|
47
|
+
}
|
48
|
+
end
|
49
|
+
# TODO: add other networks
|
50
|
+
body_object['networkInterfaces'] = networkInterfaces
|
51
|
+
|
52
|
+
if options['disks']
|
53
|
+
disks = []
|
54
|
+
options.delete('disks').each do |disk|
|
55
|
+
if disk.is_a? Disk
|
56
|
+
disks << disk.get_object
|
57
|
+
else
|
58
|
+
disks << disk
|
59
|
+
end
|
60
|
+
end
|
61
|
+
body_object['disks'] = disks
|
62
|
+
end
|
63
|
+
|
64
|
+
options['metadata'] = format_metadata options['metadata'] if options['metadata']
|
65
|
+
|
66
|
+
if options['kernel']
|
67
|
+
body_object['kernel'] = @api_url + "google/global/kernels/#{options.delete 'kernel'}"
|
68
|
+
end
|
69
|
+
body_object.merge! options # Adds in all remaining options that weren't explicitly handled.
|
39
70
|
|
40
71
|
result = self.build_result(api_method, parameters,
|
41
72
|
body_object=body_object)
|
42
73
|
response = self.build_response(result)
|
43
74
|
end
|
44
|
-
|
45
75
|
end
|
46
|
-
|
47
76
|
end
|
48
77
|
end
|
49
78
|
end
|