deltacloud-client 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +73 -0
- data/Rakefile +88 -5
- data/lib/deltacloud/client.rb +79 -0
- data/lib/deltacloud/client/base_error.rb +80 -0
- data/lib/deltacloud/client/connection.rb +139 -0
- data/lib/deltacloud/client/helpers/model_helper.rb +69 -0
- data/lib/deltacloud/client/helpers/property_helper.rb +103 -0
- data/lib/deltacloud/client/helpers/xml_helper.rb +33 -0
- data/lib/deltacloud/client/methods.rb +33 -0
- data/lib/deltacloud/client/methods/address.rb +67 -0
- data/lib/deltacloud/client/methods/api.rb +96 -0
- data/lib/deltacloud/client/methods/backward_compatiblity.rb +72 -0
- data/lib/deltacloud/client/methods/blob.rb +91 -0
- data/lib/deltacloud/client/methods/bucket.rb +55 -0
- data/lib/deltacloud/client/methods/common.rb +46 -0
- data/lib/deltacloud/client/methods/driver.rb +53 -0
- data/lib/deltacloud/client/methods/firewall.rb +67 -0
- data/lib/deltacloud/client/methods/hardware_profile.rb +41 -0
- data/lib/deltacloud/client/methods/image.rb +61 -0
- data/lib/deltacloud/client/methods/instance.rb +141 -0
- data/lib/deltacloud/client/methods/instance_state.rb +41 -0
- data/lib/deltacloud/client/methods/key.rb +58 -0
- data/lib/deltacloud/client/methods/load_balancer.rb +96 -0
- data/lib/deltacloud/client/methods/metric.rb +54 -0
- data/lib/deltacloud/client/methods/realm.rb +42 -0
- data/lib/deltacloud/client/methods/storage_snapshot.rb +61 -0
- data/lib/deltacloud/client/methods/storage_volume.rb +94 -0
- data/lib/deltacloud/client/models.rb +32 -0
- data/lib/deltacloud/client/models/address.rb +57 -0
- data/lib/deltacloud/client/models/base.rb +153 -0
- data/lib/deltacloud/client/models/blob.rb +56 -0
- data/lib/deltacloud/client/models/bucket.rb +65 -0
- data/lib/deltacloud/client/models/driver.rb +87 -0
- data/lib/deltacloud/client/models/firewall.rb +64 -0
- data/lib/deltacloud/client/models/hardware_profile.rb +68 -0
- data/lib/deltacloud/client/models/image.rb +60 -0
- data/lib/deltacloud/client/models/instance.rb +142 -0
- data/lib/deltacloud/client/models/instance_address.rb +40 -0
- data/lib/{instance_state.rb → deltacloud/client/models/instance_state.rb} +11 -3
- data/lib/deltacloud/client/models/key.rb +52 -0
- data/lib/deltacloud/client/models/load_balancer.rb +55 -0
- data/lib/deltacloud/client/models/metric.rb +72 -0
- data/lib/deltacloud/client/models/realm.rb +29 -0
- data/lib/deltacloud/client/models/storage_snapshot.rb +54 -0
- data/lib/deltacloud/client/models/storage_volume.rb +96 -0
- data/lib/deltacloud/core_ext.rb +19 -0
- data/lib/deltacloud/core_ext/element.rb +32 -0
- data/lib/deltacloud/core_ext/fixnum.rb +30 -0
- data/lib/deltacloud/core_ext/nil.rb +22 -0
- data/lib/{string.rb → deltacloud/core_ext/string.rb} +16 -26
- data/lib/deltacloud/error_response.rb +93 -0
- data/tests/client/client_test.rb +51 -0
- data/tests/client/connection_test.rb +77 -0
- data/tests/core_ext/element_test.rb +40 -0
- data/tests/core_ext/fixnum_test.rb +35 -0
- data/tests/core_ext/nil.rb +27 -0
- data/tests/core_ext/string_test.rb +47 -0
- data/tests/fixtures/instances_cleanup.yml +681 -0
- data/tests/fixtures/test_0001_connects_to_Deltacloud_API.yml +60 -0
- data/tests/fixtures/test_0001_support_cpu.yml +444 -0
- data/tests/fixtures/test_0001_support_original_body.yml +116 -0
- data/tests/fixtures/test_0001_supports_addresses.yml +178 -0
- data/tests/fixtures/test_0001_supports_api_host.yml +60 -0
- data/tests/fixtures/test_0001_supports_attached_.yml +282 -0
- data/tests/fixtures/test_0001_supports_blobs.yml +475 -0
- data/tests/fixtures/test_0001_supports_bucket.yml +200 -0
- data/tests/fixtures/test_0001_supports_buckets.yml +160 -0
- data/tests/fixtures/test_0001_supports_drivers.yml +202 -0
- data/tests/fixtures/test_0001_supports_firewalls.yml +399 -0
- data/tests/fixtures/test_0001_supports_hardware_profiles.yml +262 -0
- data/tests/fixtures/test_0001_supports_images.yml +224 -0
- data/tests/fixtures/test_0001_supports_instance_states.yml +156 -0
- data/tests/fixtures/test_0001_supports_instances.yml +486 -0
- data/tests/fixtures/test_0001_supports_keys.yml +198 -0
- data/tests/fixtures/test_0001_supports_path.yml +60 -0
- data/tests/fixtures/test_0001_supports_realms.yml +152 -0
- data/tests/fixtures/test_0001_supports_storage_snapshots.yml +164 -0
- data/tests/fixtures/test_0001_supports_storage_volumes.yml +176 -0
- data/tests/fixtures/test_0001_supports_to_get_providers.yml +410 -0
- data/tests/fixtures/test_0002_support_blob.yml +148 -0
- data/tests/fixtures/test_0002_support_instance_state.yml +204 -0
- data/tests/fixtures/test_0002_support_memory.yml +444 -0
- data/tests/fixtures/test_0002_support_on_Provider.yml +130 -0
- data/tests/fixtures/test_0002_supports_api_port.yml +60 -0
- data/tests/fixtures/test_0002_supports_api_uri.yml +60 -0
- data/tests/fixtures/test_0002_supports_driver.yml +219 -0
- data/tests/fixtures/test_0002_supports_extract_xml_body_using_faraday_connection.yml +117 -0
- data/tests/fixtures/test_0002_supports_filtering_addresses_by_id_param.yml +156 -0
- data/tests/fixtures/test_0002_supports_filtering_buckets_by_id_param.yml +156 -0
- data/tests/fixtures/test_0002_supports_filtering_firewalls_by_id_param.yml +207 -0
- data/tests/fixtures/test_0002_supports_filtering_hardware_profiles_by_id_param.yml +158 -0
- data/tests/fixtures/test_0002_supports_filtering_images_by_id_param.yml +165 -0
- data/tests/fixtures/test_0002_supports_filtering_instances_by_id_param.yml +164 -0
- data/tests/fixtures/test_0002_supports_filtering_keys_by_id_param.yml +178 -0
- data/tests/fixtures/test_0002_supports_filtering_realms_by_id.yml +104 -0
- data/tests/fixtures/test_0002_supports_filtering_storage_snapshots_by_id_param.yml +155 -0
- data/tests/fixtures/test_0002_supports_filtering_storage_volumes_by_id_param.yml +157 -0
- data/tests/fixtures/test_0002_supports_hardware_profiles.yml +262 -0
- data/tests/fixtures/test_0002_supports_is_compatible_.yml +116 -0
- data/tests/fixtures/test_0002_supports_snapshot_.yml +202 -0
- data/tests/fixtures/test_0002_supports_version.yml +60 -0
- data/tests/fixtures/test_0003_caches_the_API_entrypoint.yml +60 -0
- data/tests/fixtures/test_0003_support_address.yml +197 -0
- data/tests/fixtures/test_0003_support_bucket.yml +198 -0
- data/tests/fixtures/test_0003_support_create_blob.yml +105 -0
- data/tests/fixtures/test_0003_support_create_blob_and_destroy_blob.yml +138 -0
- data/tests/fixtures/test_0003_support_firewall.yml +768 -0
- data/tests/fixtures/test_0003_support_hardware_profile.yml +199 -0
- data/tests/fixtures/test_0003_support_image.yml +207 -0
- data/tests/fixtures/test_0003_support_instance.yml +206 -0
- data/tests/fixtures/test_0003_support_key.yml +220 -0
- data/tests/fixtures/test_0003_support_realm.yml +195 -0
- data/tests/fixtures/test_0003_support_storage.yml +444 -0
- data/tests/fixtures/test_0003_support_storage_snapshot.yml +196 -0
- data/tests/fixtures/test_0003_support_storage_volume.yml +197 -0
- data/tests/fixtures/test_0003_support_to_change_driver_with_Client.yml +72 -0
- data/tests/fixtures/test_0003_supports_connect.yml +60 -0
- data/tests/fixtures/test_0003_supports_extract_xml_body_using_nokogiri_document.yml +117 -0
- data/tests/fixtures/test_0003_supports_instance.yml +396 -0
- data/tests/fixtures/test_0003_supports_is_compatible_.yml +116 -0
- data/tests/fixtures/test_0003_supports_lunch_image.yml +367 -0
- data/tests/fixtures/test_0003_supports_providers.yml +102 -0
- data/tests/fixtures/test_0003_supports_version.yml +60 -0
- data/tests/fixtures/test_0004_support_architecture.yml +444 -0
- data/tests/fixtures/test_0004_support_create_address.yml +197 -0
- data/tests/fixtures/test_0004_support_create_blob_and_destroy_blob_with_meta_params.yml +139 -0
- data/tests/fixtures/test_0004_support_create_bucket.yml +180 -0
- data/tests/fixtures/test_0004_support_create_bucket_and_destroy_bucket.yml +180 -0
- data/tests/fixtures/test_0004_support_create_firewall_and_destroy_firewall.yml +496 -0
- data/tests/fixtures/test_0004_support_create_image_and_destroy_image.yml +1527 -0
- data/tests/fixtures/test_0004_support_create_instance.yml +115 -0
- data/tests/fixtures/test_0004_support_create_key_and_destroy_key.yml +206 -0
- data/tests/fixtures/test_0004_support_create_volume.yml +105 -0
- data/tests/fixtures/test_0004_support_create_volume_and_destroy_volume.yml +181 -0
- data/tests/fixtures/test_0004_support_to_test_of_valid_DC_connection.yml +60 -0
- data/tests/fixtures/test_0004_supports_current_driver.yml +60 -0
- data/tests/fixtures/test_0004_supports_extract_xml_body_using_nokogiri_element.yml +117 -0
- data/tests/fixtures/test_0004_supports_lunch_image.yml +312 -0
- data/tests/fixtures/test_0004_supports_valid_credentials_.yml +215 -0
- data/tests/fixtures/test_0004_supports_with_config.yml +129 -0
- data/tests/fixtures/test_0005_support_attach_storage_volume.yml +102 -0
- data/tests/fixtures/test_0005_support_attach_storage_volume_and_detach_storage_volume.yml +142 -0
- data/tests/fixtures/test_0005_support_create_instance_with_hwp_id.yml +115 -0
- data/tests/fixtures/test_0005_support_opaque_.yml +152 -0
- data/tests/fixtures/test_0005_supports_current_provider.yml +134 -0
- data/tests/fixtures/test_0005_supports_id.yml +116 -0
- data/tests/fixtures/test_0005_supports_switching_drivers_per_instance.yml +129 -0
- data/tests/fixtures/test_0005_supports_use_driver.yml +60 -0
- data/tests/fixtures/test_0006_support_create_instance_with_realm_id.yml +115 -0
- data/tests/fixtures/test_0006_supports_discovered_.yml +60 -0
- data/tests/fixtures/test_0006_supports_supported_collections.yml +60 -0
- data/tests/fixtures/test_0006_supports_switching_providers_per_instance.yml +208 -0
- data/tests/fixtures/test_0007_support_create_instance_with_name.yml +115 -0
- data/tests/fixtures/test_0007_support_switching_provider_without_credentials.yml +208 -0
- data/tests/fixtures/test_0007_supports_support_.yml +60 -0
- data/tests/fixtures/test_0007_supports_valid_credentials_on_class.yml +370 -0
- data/tests/fixtures/test_0008_support_stop_instance.yml +166 -0
- data/tests/fixtures/test_0008_supports_must_support_.yml +60 -0
- data/tests/fixtures/test_0009_support_start_instance.yml +217 -0
- data/tests/fixtures/test_0009_supports_features.yml +60 -0
- data/tests/fixtures/test_0010_support_reboot_instance.yml +166 -0
- data/tests/fixtures/test_0010_supports_feature_.yml +60 -0
- data/tests/helpers/model_test.rb +33 -0
- data/tests/helpers/xml_test.rb +56 -0
- data/tests/methods/address_test.rb +64 -0
- data/tests/methods/api_test.rb +97 -0
- data/tests/methods/backward_compatibility_test.rb +87 -0
- data/tests/methods/blob_test.rb +64 -0
- data/tests/methods/bucket_test.rb +62 -0
- data/tests/methods/driver_test.rb +48 -0
- data/tests/methods/firewall_test.rb +84 -0
- data/tests/methods/hardware_profile_test.rb +53 -0
- data/tests/methods/image_test.rb +64 -0
- data/tests/methods/instance_state_test.rb +43 -0
- data/tests/methods/instance_test.rb +126 -0
- data/tests/methods/key_test.rb +63 -0
- data/tests/methods/realm_test.rb +50 -0
- data/tests/methods/storage_snapshot_test.rb +53 -0
- data/tests/methods/storage_volume_test.rb +81 -0
- data/tests/models/blob_test.rb +40 -0
- data/tests/models/bucket_test.rb +37 -0
- data/tests/models/driver_test.rb +42 -0
- data/tests/models/hardware_profile_test.rb +80 -0
- data/tests/models/image_test.rb +65 -0
- data/tests/models/storage_volume_test.rb +52 -0
- data/tests/test_helper.rb +59 -11
- metadata +392 -41
- data/lib/base_object.rb +0 -386
- data/lib/client_bucket_methods.rb +0 -69
- data/lib/deltacloud.rb +0 -486
- data/lib/documentation.rb +0 -59
- data/lib/errors.rb +0 -140
- data/lib/hwp_properties.rb +0 -61
- data/tests/buckets_test.rb +0 -141
- data/tests/client_test.rb +0 -59
- data/tests/content_negotiation_test.rb +0 -127
- data/tests/errors_test.rb +0 -57
- data/tests/hardware_profiles_test.rb +0 -75
- data/tests/images_test.rb +0 -102
- data/tests/instance_states_test.rb +0 -66
- data/tests/instances_test.rb +0 -203
- data/tests/keys_test.rb +0 -81
- data/tests/realms_test.rb +0 -64
- data/tests/storage_snapshot_test.rb +0 -76
- data/tests/storage_volume_test.rb +0 -86
@@ -0,0 +1,91 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Blob
|
19
|
+
|
20
|
+
# Retrieve a list of all blob entities from given bucket
|
21
|
+
#
|
22
|
+
def blobs(bucket_id=nil)
|
23
|
+
raise error.new("The :bucket_id cannot be nil.") if bucket_id.nil?
|
24
|
+
bucket(bucket_id).blob_ids.map { |blob_id| blob(bucket_id, blob_id) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Retrieve the single blob entity
|
28
|
+
#
|
29
|
+
# - blob_id -> Blob entity to retrieve
|
30
|
+
#
|
31
|
+
def blob(bucket_id, blob_id)
|
32
|
+
model(:blob).convert(
|
33
|
+
self,
|
34
|
+
connection.get(api_uri("buckets/#{bucket_id}/#{blob_id}"))
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create a new blob
|
39
|
+
#
|
40
|
+
# - bucket_id -> A bucket ID that new blob should belong to
|
41
|
+
# - blob_name -> A name for new blob
|
42
|
+
# - blob_data -> Data stored in this blob
|
43
|
+
# - create_opts
|
44
|
+
# - :user_metadata -> A Ruby +Hash+ with key => value metadata
|
45
|
+
#
|
46
|
+
def create_blob(bucket_id, blob_name, blob_data, create_opts={})
|
47
|
+
must_support! :buckets
|
48
|
+
create_opts.merge!(convert_meta_params(create_opts.delete(:user_metadata)))
|
49
|
+
response = connection.post(api_uri("buckets/#{bucket_id}")) do |request|
|
50
|
+
request.params = create_opts.merge(
|
51
|
+
:blob_id => blob_name,
|
52
|
+
:blob_data => blob_data
|
53
|
+
)
|
54
|
+
end
|
55
|
+
model(:blob).convert(self, response.body)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Destroy given bucket blob
|
59
|
+
#
|
60
|
+
def destroy_blob(bucket_id, blob_id)
|
61
|
+
must_support! :buckets
|
62
|
+
r = connection.delete(api_uri("buckets/#{bucket_id}/#{blob_id}"))
|
63
|
+
r.status == 204
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Convert the user_metadata into POST params compatible with
|
69
|
+
# blob creation
|
70
|
+
#
|
71
|
+
# - params -> Simple Ruby +Hash+
|
72
|
+
#
|
73
|
+
# @return { :meta_params => COUNTER, :meta_name1 => '', :meta_value1 => ''}
|
74
|
+
#
|
75
|
+
def convert_meta_params(params)
|
76
|
+
meta_params = {}
|
77
|
+
counter = 0
|
78
|
+
(params || {}).each do |key, value|
|
79
|
+
counter += 1
|
80
|
+
meta_params["meta_name#{counter}"] = key
|
81
|
+
meta_params["meta_value#{counter}"] = value
|
82
|
+
end
|
83
|
+
if counter >= 1
|
84
|
+
meta_params.merge!(:meta_params => counter.to_s)
|
85
|
+
end
|
86
|
+
meta_params
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Bucket
|
19
|
+
|
20
|
+
# Retrieve list of all bucket entities
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter entities using 'id' attribute
|
24
|
+
#
|
25
|
+
def buckets(filter_opts={})
|
26
|
+
from_collection :buckets,
|
27
|
+
connection.get(api_uri('buckets'), filter_opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieve the single bucket entity
|
31
|
+
#
|
32
|
+
# - bucket_id -> Bucket entity to retrieve
|
33
|
+
#
|
34
|
+
def bucket(bucket_id)
|
35
|
+
from_resource :bucket,
|
36
|
+
connection.get(api_uri("buckets/#{bucket_id}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new bucket
|
40
|
+
#
|
41
|
+
# - name: Bucket name
|
42
|
+
#
|
43
|
+
def create_bucket(name)
|
44
|
+
create_resource :bucket, :name => name
|
45
|
+
end
|
46
|
+
|
47
|
+
# Destroy given bucket
|
48
|
+
#
|
49
|
+
def destroy_bucket(bucket_id)
|
50
|
+
destroy_resource :bucket, bucket_id
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Common
|
19
|
+
|
20
|
+
# A generic method for creating a new resources
|
21
|
+
#
|
22
|
+
# - resource_name -> A resource name to create (eg. :image)
|
23
|
+
# - create_opts -> HTTP options to pass into the create operation
|
24
|
+
#
|
25
|
+
def create_resource(resource_name, create_opts={})
|
26
|
+
no_convert_model = create_opts.delete(:no_convert_model)
|
27
|
+
must_support! resource_name.to_s.pluralize
|
28
|
+
response = connection.post(api_uri(resource_name.to_s.pluralize)) do |request|
|
29
|
+
request.params = create_opts
|
30
|
+
end
|
31
|
+
no_convert_model ? response : model(resource_name).convert(self, response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
# A generic method for destroying resources
|
35
|
+
#
|
36
|
+
def destroy_resource(resource_name, resource_id)
|
37
|
+
must_support! resource_name.to_s.pluralize
|
38
|
+
result = connection.delete(
|
39
|
+
api_uri([resource_name.to_s.pluralize, resource_id].join('/'))
|
40
|
+
)
|
41
|
+
result.status.is_no_content?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Driver
|
19
|
+
|
20
|
+
# Retrieve list of all drivers
|
21
|
+
#
|
22
|
+
# - filter_opt:
|
23
|
+
# - :id -> Filter drivers using their 'id'
|
24
|
+
# - :state -> Filter drivers by their 'state'
|
25
|
+
#
|
26
|
+
def drivers(filter_opts={})
|
27
|
+
from_collection(
|
28
|
+
:drivers,
|
29
|
+
connection.get(api_uri('drivers'), filter_opts)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Retrieve the given driver
|
34
|
+
#
|
35
|
+
# - driver_id -> Driver to retrieve
|
36
|
+
#
|
37
|
+
def driver(driver_id)
|
38
|
+
from_resource(
|
39
|
+
:driver,
|
40
|
+
connection.get(api_uri("drivers/#{driver_id}"))
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# List of the current driver providers
|
45
|
+
#
|
46
|
+
def providers
|
47
|
+
driver(current_driver).providers
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Firewall
|
19
|
+
|
20
|
+
# Retrieve list of all firewall entities
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter entities using 'id' attribute
|
24
|
+
#
|
25
|
+
def firewalls(filter_opts={})
|
26
|
+
from_collection :firewalls,
|
27
|
+
connection.get(api_uri('firewalls'), filter_opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieve the single firewall entity
|
31
|
+
#
|
32
|
+
# - firewall_id -> Firewall entity to retrieve
|
33
|
+
#
|
34
|
+
def firewall(firewall_id)
|
35
|
+
from_resource :firewall,
|
36
|
+
connection.get(api_uri("firewalls/#{firewall_id}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new firewall
|
40
|
+
#
|
41
|
+
# - name - Name to associate with new firewall
|
42
|
+
# - create_opts
|
43
|
+
# :name -> Name of firewall
|
44
|
+
#
|
45
|
+
def create_firewall(name, create_opts={})
|
46
|
+
create_resource :firewall, { :name => name }.merge(create_opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy_firewall(firewall_id)
|
50
|
+
destroy_resource :firewall, firewall_id
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_firewall_rule(firewall_id, protocol, port_from, port_to, opts={})
|
54
|
+
r = connection.post(api_uri("firewalls/#{firewall_id}/rules")) do |request|
|
55
|
+
request.params = {
|
56
|
+
:protocol => protocol,
|
57
|
+
:port_from => port_from,
|
58
|
+
:port_to => port_to
|
59
|
+
}
|
60
|
+
# TODO: Add support for sources
|
61
|
+
end
|
62
|
+
model(:firewall).convert(self, r.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module HardwareProfile
|
19
|
+
|
20
|
+
# Retrieve list of all hardware_profiles
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter hardware_profiles using their 'id'
|
24
|
+
#
|
25
|
+
def hardware_profiles(filter_opts={})
|
26
|
+
from_collection :hardware_profiles,
|
27
|
+
connection.get(api_uri('hardware_profiles'), filter_opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieve the given hardware_profile
|
31
|
+
#
|
32
|
+
# - hwp_id -> hardware_profile to retrieve
|
33
|
+
#
|
34
|
+
def hardware_profile(hwp_id)
|
35
|
+
from_resource :hardware_profile,
|
36
|
+
connection.get(api_uri("hardware_profiles/#{hwp_id}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Image
|
19
|
+
|
20
|
+
# Retrieve list of all images
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter images using their 'id'
|
24
|
+
# - :state -> Filter images by their 'state'
|
25
|
+
# - :architecture -> Filter images by their 'architecture'
|
26
|
+
#
|
27
|
+
def images(filter_opts={})
|
28
|
+
from_collection :images,
|
29
|
+
connection.get(api_uri('images'), filter_opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Retrieve the given image
|
33
|
+
#
|
34
|
+
# - image_id -> Image to retrieve
|
35
|
+
#
|
36
|
+
def image(image_id)
|
37
|
+
from_resource :image,
|
38
|
+
connection.get(api_uri("images/#{image_id}"))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create a new image from instance
|
42
|
+
#
|
43
|
+
# - instance_id -> The stopped instance used for creation
|
44
|
+
# - create_opts
|
45
|
+
# - :name -> Name of the new image
|
46
|
+
# - :description -> Description of the new image
|
47
|
+
#
|
48
|
+
def create_image(instance_id, create_opts={})
|
49
|
+
create_resource :image, { :instance_id => instance_id }.merge(create_opts)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Destroy given image
|
53
|
+
# NOTE: This operation might not be supported for all drivers.
|
54
|
+
#
|
55
|
+
def destroy_image(image_id)
|
56
|
+
destroy_resource :image, image_id
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
module Deltacloud::Client
|
17
|
+
module Methods
|
18
|
+
module Instance
|
19
|
+
|
20
|
+
# Retrieve list of all instances
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter instances using their 'id'
|
24
|
+
# - :state -> Filter instances by their 'state'
|
25
|
+
# - :realm_id -> Filter instances based on their 'realm_id'
|
26
|
+
#
|
27
|
+
def instances(filter_opts={})
|
28
|
+
from_collection(
|
29
|
+
:instances,
|
30
|
+
connection.get(api_uri('/instances'), filter_opts)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Retrieve the given instance
|
35
|
+
#
|
36
|
+
# - instance_id -> Instance to retrieve
|
37
|
+
#
|
38
|
+
def instance(instance_id)
|
39
|
+
from_resource(
|
40
|
+
:instance,
|
41
|
+
connection.get(api_uri("instances/#{instance_id}"))
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Create a new instance
|
46
|
+
#
|
47
|
+
# - image_id -> Image to use for instance creation
|
48
|
+
# (img1, ami-12345, etc...)
|
49
|
+
# - create_opts -> Various options that DC support for the current
|
50
|
+
# provider.
|
51
|
+
#
|
52
|
+
# Returns created instance, or list of created instances or all instances.
|
53
|
+
#
|
54
|
+
def create_instance(image_id, create_opts={})
|
55
|
+
create_opts[:user_data] = Base64::encode64(create_opts[:user_data]) if create_opts[:user_data]
|
56
|
+
r = create_resource :instance, create_opts.merge(
|
57
|
+
:image_id => image_id,
|
58
|
+
:no_convert_model => true
|
59
|
+
)
|
60
|
+
parse_create_instance(r)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Destroy the current +Instance+
|
64
|
+
# Returns 'true' if the response was 204 No Content
|
65
|
+
#
|
66
|
+
# - instance_id -> The 'id' of the Instance to destroy
|
67
|
+
#
|
68
|
+
def destroy_instance(instance_id)
|
69
|
+
destroy_resource :instance, instance_id
|
70
|
+
end
|
71
|
+
|
72
|
+
# Attempt to change the +Instance+ state to STOPPED
|
73
|
+
#
|
74
|
+
# - instance_id -> The 'id' of the Instance to stop
|
75
|
+
#
|
76
|
+
def stop_instance(instance_id)
|
77
|
+
instance_action :stop, instance_id
|
78
|
+
end
|
79
|
+
|
80
|
+
# Attempt to change the +Instance+ state to STARTED
|
81
|
+
#
|
82
|
+
# - instance_id -> The 'id' of the Instance to start
|
83
|
+
#
|
84
|
+
def start_instance(instance_id)
|
85
|
+
instance_action :start, instance_id
|
86
|
+
end
|
87
|
+
|
88
|
+
# Attempt to reboot the +Instance+
|
89
|
+
#
|
90
|
+
# - instance_id -> The 'id' of the Instance to reboot
|
91
|
+
#
|
92
|
+
def reboot_instance(instance_id)
|
93
|
+
instance_action :reboot, instance_id
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
# Avoid codu duplication ;-)
|
99
|
+
#
|
100
|
+
def instance_action(action, instance_id)
|
101
|
+
result = connection.post(
|
102
|
+
api_uri("/instances/#{instance_id}/#{action}")
|
103
|
+
)
|
104
|
+
if result.status.is_ok?
|
105
|
+
from_resource(:instance, result)
|
106
|
+
else
|
107
|
+
instance(instance_id)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Handles parsing of +create_instance+ method
|
112
|
+
#
|
113
|
+
# - response -> +create_instance+ HTTP response body
|
114
|
+
#
|
115
|
+
def parse_create_instance(response)
|
116
|
+
# If Deltacloud API return only Location (30x), follow it and
|
117
|
+
# retrieve created instance from there.
|
118
|
+
#
|
119
|
+
if response.status.is_redirect?
|
120
|
+
# If Deltacloud API redirect to list of instances
|
121
|
+
# then return list of **all** instances, otherwise
|
122
|
+
# grab the instance_id from Location header
|
123
|
+
#
|
124
|
+
redirect_instance = response.headers['Location'].split('/').last
|
125
|
+
if redirect_instance == 'instances'
|
126
|
+
instances
|
127
|
+
else
|
128
|
+
instance(redirect_instance)
|
129
|
+
end
|
130
|
+
elsif response.body.to_xml.root.name == 'instances'
|
131
|
+
# If more than 1 instance was created, return list
|
132
|
+
#
|
133
|
+
from_collection(:instances, response.body)
|
134
|
+
else
|
135
|
+
from_resource(:instance, response)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|