deltacloud-client-vm 1.1.4.2 → 1.1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +176 -0
- data/NOTICE +8 -0
- data/README.md +73 -0
- data/Rakefile +122 -0
- data/deltacloud-client-vm.gemspec +24 -0
- data/lib/deltacloud_vm/client.rb +79 -0
- data/lib/deltacloud_vm/client/base_error.rb +80 -0
- data/lib/deltacloud_vm/client/connection.rb +139 -0
- data/lib/deltacloud_vm/client/helpers/model_helper.rb +69 -0
- data/lib/deltacloud_vm/client/helpers/property_helper.rb +103 -0
- data/lib/deltacloud_vm/client/helpers/xml_helper.rb +33 -0
- data/lib/deltacloud_vm/client/methods.rb +33 -0
- data/lib/deltacloud_vm/client/methods/address.rb +67 -0
- data/lib/deltacloud_vm/client/methods/api.rb +96 -0
- data/lib/deltacloud_vm/client/methods/backward_compatiblity.rb +72 -0
- data/lib/deltacloud_vm/client/methods/blob.rb +91 -0
- data/lib/deltacloud_vm/client/methods/bucket.rb +55 -0
- data/lib/deltacloud_vm/client/methods/common.rb +46 -0
- data/lib/deltacloud_vm/client/methods/driver.rb +53 -0
- data/lib/deltacloud_vm/client/methods/firewall.rb +67 -0
- data/lib/deltacloud_vm/client/methods/hardware_profile.rb +41 -0
- data/lib/deltacloud_vm/client/methods/image.rb +61 -0
- data/lib/deltacloud_vm/client/methods/instance.rb +141 -0
- data/lib/deltacloud_vm/client/methods/instance_state.rb +41 -0
- data/lib/deltacloud_vm/client/methods/key.rb +58 -0
- data/lib/deltacloud_vm/client/methods/load_balancer.rb +96 -0
- data/lib/deltacloud_vm/client/methods/metric.rb +54 -0
- data/lib/deltacloud_vm/client/methods/realm.rb +42 -0
- data/lib/deltacloud_vm/client/methods/storage_snapshot.rb +61 -0
- data/lib/deltacloud_vm/client/methods/storage_volume.rb +94 -0
- data/lib/deltacloud_vm/client/models.rb +32 -0
- data/lib/deltacloud_vm/client/models/address.rb +57 -0
- data/lib/deltacloud_vm/client/models/base.rb +153 -0
- data/lib/deltacloud_vm/client/models/blob.rb +56 -0
- data/lib/deltacloud_vm/client/models/bucket.rb +65 -0
- data/lib/deltacloud_vm/client/models/driver.rb +87 -0
- data/lib/deltacloud_vm/client/models/firewall.rb +64 -0
- data/lib/deltacloud_vm/client/models/hardware_profile.rb +68 -0
- data/lib/deltacloud_vm/client/models/image.rb +60 -0
- data/lib/deltacloud_vm/client/models/instance.rb +142 -0
- data/lib/deltacloud_vm/client/models/instance_address.rb +40 -0
- data/lib/deltacloud_vm/client/models/instance_state.rb +52 -0
- data/lib/deltacloud_vm/client/models/key.rb +52 -0
- data/lib/deltacloud_vm/client/models/load_balancer.rb +55 -0
- data/lib/deltacloud_vm/client/models/metric.rb +72 -0
- data/lib/deltacloud_vm/client/models/realm.rb +29 -0
- data/lib/deltacloud_vm/client/models/storage_snapshot.rb +54 -0
- data/lib/deltacloud_vm/client/models/storage_volume.rb +96 -0
- data/lib/deltacloud_vm/core_ext.rb +19 -0
- data/lib/deltacloud_vm/core_ext/element.rb +32 -0
- data/lib/deltacloud_vm/core_ext/fixnum.rb +30 -0
- data/lib/deltacloud_vm/core_ext/nil.rb +22 -0
- data/lib/deltacloud_vm/core_ext/string.rb +49 -0
- data/lib/deltacloud_vm/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 +64 -0
- metadata +191 -2
@@ -0,0 +1,54 @@
|
|
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 DeltacloudVM::Client
|
17
|
+
module Methods
|
18
|
+
module Metric
|
19
|
+
|
20
|
+
# Retrieve list of all metric entities
|
21
|
+
#
|
22
|
+
# Filter options:
|
23
|
+
#
|
24
|
+
# - :id -> Filter entities using 'id' attribute
|
25
|
+
#
|
26
|
+
def metrics(filter_opts={})
|
27
|
+
from_collection :metrics,
|
28
|
+
connection.get(api_uri('metrics'), filter_opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Retrieve the single metric entity
|
32
|
+
#
|
33
|
+
# - metric_id -> Metric entity to retrieve
|
34
|
+
#
|
35
|
+
def metric(metric_id)
|
36
|
+
from_resource :metric,
|
37
|
+
connection.get(api_uri("metrics/#{metric_id}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create a new metric
|
41
|
+
#
|
42
|
+
# - create_opts
|
43
|
+
#
|
44
|
+
# def create_metric(create_opts={})
|
45
|
+
# must_support! :metrics
|
46
|
+
# response = connection.post(api_uri('metrics')) do |request|
|
47
|
+
# request.params = create_opts
|
48
|
+
# end
|
49
|
+
# model(:metric).convert(self, response.body)
|
50
|
+
# end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 DeltacloudVM::Client
|
17
|
+
module Methods
|
18
|
+
module Realm
|
19
|
+
|
20
|
+
# Retrieve list of all realms
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter realms using their 'id'
|
24
|
+
# - :state -> Filter realms by their 'state'
|
25
|
+
#
|
26
|
+
def realms(filter_opts={})
|
27
|
+
from_collection :realms,
|
28
|
+
connection.get(api_uri("realms"), filter_opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Retrieve the given realm
|
32
|
+
#
|
33
|
+
# - realm_id -> Instance to retrieve
|
34
|
+
#
|
35
|
+
def realm(realm_id)
|
36
|
+
from_resource :realm,
|
37
|
+
connection.get(api_uri("realms/#{realm_id}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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 DeltacloudVM::Client
|
17
|
+
module Methods
|
18
|
+
module StorageSnapshot
|
19
|
+
|
20
|
+
# Retrieve list of all storage_snapshot entities
|
21
|
+
#
|
22
|
+
# - filter_options:
|
23
|
+
# - :id -> Filter entities using 'id' attribute
|
24
|
+
#
|
25
|
+
def storage_snapshots(filter_opts={})
|
26
|
+
from_collection :storage_snapshots,
|
27
|
+
connection.get(api_uri('storage_snapshots'), filter_opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieve the single storage_snapshot entity
|
31
|
+
#
|
32
|
+
# - storage_snapshot_id -> StorageSnapshot entity to retrieve
|
33
|
+
#
|
34
|
+
def storage_snapshot(storage_snapshot_id)
|
35
|
+
from_resource :storage_snapshot,
|
36
|
+
connection.get(api_uri("storage_snapshots/#{storage_snapshot_id}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new StorageSnapshot based on +volume_id+
|
40
|
+
#
|
41
|
+
# - volume_id -> ID of the +StorageVolume+ to create snapshot from
|
42
|
+
# - create_opts ->
|
43
|
+
# - :name -> Name of the StorageSnapshot
|
44
|
+
# - :description -> Description of the StorageSnapshot
|
45
|
+
#
|
46
|
+
def create_storage_snapshot(volume_id, create_opts={})
|
47
|
+
create_resource :storage_snapshot, create_opts.merge(:volume_id => volume_id)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Destroy the current +StorageSnapshot+
|
51
|
+
# Returns 'true' if the response was 204 No Content
|
52
|
+
#
|
53
|
+
# - snapshot_id -> The 'id' of the snapshot to destroy
|
54
|
+
#
|
55
|
+
def destroy_storage_snapshot(snapshot_id)
|
56
|
+
destroy_resource :storage_snapshot, snapshot_id
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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 DeltacloudVM::Client
|
17
|
+
module Methods
|
18
|
+
module StorageVolume
|
19
|
+
|
20
|
+
# Retrieve list of all storage_volumes
|
21
|
+
#
|
22
|
+
# - filter_opts:
|
23
|
+
# - :id -> Filter storage_volumes using their 'id'
|
24
|
+
# - :state -> Filter storage_volumes by their 'state'
|
25
|
+
#
|
26
|
+
def storage_volumes(filter_opts={})
|
27
|
+
from_collection :storage_volumes,
|
28
|
+
connection.get(api_uri("storage_volumes"), filter_opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Retrieve the given storage_volume
|
32
|
+
#
|
33
|
+
# - storage_volume_id -> Instance to retrieve
|
34
|
+
#
|
35
|
+
def storage_volume(storage_volume_id)
|
36
|
+
from_resource :storage_volume,
|
37
|
+
connection.get(api_uri("storage_volumes/#{storage_volume_id}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create new storage volume
|
41
|
+
#
|
42
|
+
# - :snapshot_id -> Snapshot to use for creating a new volume
|
43
|
+
# - :capacity -> Initial Volume capacity
|
44
|
+
# - :realm_id -> Create volume in this realm
|
45
|
+
# - :name -> Volume name
|
46
|
+
# - :description -> Volume description
|
47
|
+
#
|
48
|
+
# NOTE: Some create options might not be supported by backend cloud
|
49
|
+
#
|
50
|
+
def create_storage_volume(create_opts={})
|
51
|
+
create_resource :storage_volume, create_opts
|
52
|
+
end
|
53
|
+
|
54
|
+
# Destroy the current +StorageVolume+
|
55
|
+
# Returns 'true' if the response was 204 No Content
|
56
|
+
#
|
57
|
+
# - volume_id -> The 'id' of the volume to destroy
|
58
|
+
#
|
59
|
+
def destroy_storage_volume(volume_id)
|
60
|
+
destroy_resource :storage_volume, volume_id
|
61
|
+
end
|
62
|
+
|
63
|
+
# Attach the Storage Volume to the Instance
|
64
|
+
# The +device+ parameter could be used if supported.
|
65
|
+
#
|
66
|
+
# - volume_id -> Volume ID (eg. 'vol1')
|
67
|
+
# - instance_id -> Target Instance ID (eg. 'inst1')
|
68
|
+
# - device -> Target device in Instance (eg. '/dev/sda2')
|
69
|
+
#
|
70
|
+
def attach_storage_volume(volume_id, instance_id, device=nil)
|
71
|
+
must_support! :storage_volumes
|
72
|
+
result = connection.post(api_uri("/storage_volumes/#{volume_id}/attach")) do |r|
|
73
|
+
r.params = { :instance_id => instance_id, :device => device }
|
74
|
+
end
|
75
|
+
if result.status.is_ok?
|
76
|
+
from_resource(:storage_volume, result)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Detach the Storage Volume from the Instance
|
81
|
+
#
|
82
|
+
# -volume_id -> Volume to detach
|
83
|
+
#
|
84
|
+
def detach_storage_volume(volume_id)
|
85
|
+
must_support! :storage_volumes
|
86
|
+
result = connection.post(api_uri("/storage_volumes/#{volume_id}/detach"))
|
87
|
+
if result.status.is_ok?
|
88
|
+
from_resource(:storage_volume, result)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
+
require_relative './models/base'
|
17
|
+
require_relative './models/address'
|
18
|
+
require_relative './models/blob'
|
19
|
+
require_relative './models/bucket'
|
20
|
+
require_relative './models/driver'
|
21
|
+
require_relative './models/firewall'
|
22
|
+
require_relative './models/hardware_profile'
|
23
|
+
require_relative './models/image'
|
24
|
+
require_relative './models/instance_address'
|
25
|
+
require_relative './models/instance'
|
26
|
+
require_relative './models/instance_state'
|
27
|
+
require_relative './models/key'
|
28
|
+
require_relative './models/realm'
|
29
|
+
require_relative './models/storage_volume'
|
30
|
+
require_relative './models/storage_snapshot'
|
31
|
+
require_relative './models/load_balancer'
|
32
|
+
require_relative './models/metric'
|
@@ -0,0 +1,57 @@
|
|
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 DeltacloudVM::Client
|
17
|
+
class Address < Base
|
18
|
+
include DeltacloudVM::Client::Methods::Address
|
19
|
+
|
20
|
+
# Inherited attributes: :_id, :name, :description
|
21
|
+
|
22
|
+
# Custom attributes:
|
23
|
+
#
|
24
|
+
attr_reader :ip
|
25
|
+
attr_reader :instance_id
|
26
|
+
|
27
|
+
# Address model methods
|
28
|
+
#
|
29
|
+
|
30
|
+
# Associate the IP address to the +Instance+
|
31
|
+
#
|
32
|
+
def associate(instance_id)
|
33
|
+
associate_address(_id, instance_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Disassociate the IP address from +Instance+
|
37
|
+
#
|
38
|
+
def disassociate
|
39
|
+
disassociate_address(_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy!
|
43
|
+
destroy_address(_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Parse the Address entity from XML body
|
47
|
+
#
|
48
|
+
# - xml_body -> DeltacloudVM API XML representation of the address
|
49
|
+
#
|
50
|
+
def self.parse(xml_body)
|
51
|
+
{
|
52
|
+
:ip => xml_body.text_at(:ip),
|
53
|
+
:instance_id => xml_body.attr_at('instance', :id)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,153 @@
|
|
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 DeltacloudVM::Client
|
17
|
+
|
18
|
+
class Base
|
19
|
+
|
20
|
+
extend Helpers::XmlHelper
|
21
|
+
|
22
|
+
include DeltacloudVM::Client::Helpers::Model
|
23
|
+
include DeltacloudVM::Client::Methods::Api
|
24
|
+
|
25
|
+
# These attributes are common for all models
|
26
|
+
#
|
27
|
+
# - obj_id -> The :id of DeltacloudVM API model (eg. instance ID)
|
28
|
+
#
|
29
|
+
attr_reader :obj_id
|
30
|
+
attr_reader :url
|
31
|
+
attr_reader :name
|
32
|
+
attr_reader :description
|
33
|
+
|
34
|
+
# The Base class that other models should inherit from
|
35
|
+
# To initialize, you need to supply these mandatory params:
|
36
|
+
#
|
37
|
+
# - :_client -> Reference to Client instance
|
38
|
+
# - :_id -> The 'id' of resource. The '_' is there to avoid conflicts
|
39
|
+
#
|
40
|
+
def initialize(opts={})
|
41
|
+
@options = opts
|
42
|
+
@obj_id = @options.delete(:_id)
|
43
|
+
# Do not allow to modify the object#base_id
|
44
|
+
@obj_id.freeze
|
45
|
+
@client = @options.delete(:_client)
|
46
|
+
@original_body = @options.delete(:original_body)
|
47
|
+
update_instance_variables!(@options)
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :_id, :obj_id
|
51
|
+
|
52
|
+
# Populate instance variables in model
|
53
|
+
# This method could also be used to update the variables for already
|
54
|
+
# initialized models. Look at +Instance#reload!+ method.
|
55
|
+
#
|
56
|
+
def update_instance_variables!(opts={})
|
57
|
+
@options.merge!(opts)
|
58
|
+
@options.each { |key, val| self.instance_variable_set("@#{key}", val) unless val.nil? }
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
# Eye-candy representation of model, without ugly @client representation
|
63
|
+
#
|
64
|
+
def to_s
|
65
|
+
"#<#{self.class.name}> #{@options.merge(:_id => @obj_id).inspect}"
|
66
|
+
end
|
67
|
+
|
68
|
+
# An internal reference to the current DeltacloudVM::Client::Connection
|
69
|
+
# instance. Used for implementing the model methods
|
70
|
+
#
|
71
|
+
def client
|
72
|
+
@client
|
73
|
+
end
|
74
|
+
|
75
|
+
# Shorthand for +client+.connection
|
76
|
+
#
|
77
|
+
# Return Faraday connection object.
|
78
|
+
#
|
79
|
+
def connection
|
80
|
+
client.connection
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return the cached version of DeltacloudVM API entrypoint
|
84
|
+
#
|
85
|
+
def entrypoint
|
86
|
+
client.entrypoint
|
87
|
+
end
|
88
|
+
|
89
|
+
# Return the original XML body model was constructed from
|
90
|
+
# This might help debugging broken XML
|
91
|
+
#
|
92
|
+
def original_body
|
93
|
+
@original_body
|
94
|
+
end
|
95
|
+
|
96
|
+
# The model#id is the old way for getting the DeltacloudVM API resource
|
97
|
+
# 'id'. However this collide with the Ruby Object#id.
|
98
|
+
#
|
99
|
+
def id
|
100
|
+
warn '[DEPRECATION] `id` is deprecated because of a possible conflict with Object#id. Use `_id` instead.'
|
101
|
+
_id
|
102
|
+
end
|
103
|
+
|
104
|
+
class << self
|
105
|
+
|
106
|
+
# Parse the XML response body from DeltacloudVM API
|
107
|
+
# to +Hash+. Result is then used to create an instance of DeltacloudVM model
|
108
|
+
#
|
109
|
+
# NOTE: Children classes **must** implement this class method
|
110
|
+
#
|
111
|
+
def parse(client_ref, inst)
|
112
|
+
warn "The self#parse method **must** be defined in #{self.class.name}"
|
113
|
+
{}
|
114
|
+
end
|
115
|
+
|
116
|
+
# Convert the parsed +Hash+ from +parse+ method to instance of DeltacloudVM model
|
117
|
+
#
|
118
|
+
# - client_ref -> Reference to the Client instance
|
119
|
+
# - obj -> Might be a Nokogiri::Element or Response
|
120
|
+
#
|
121
|
+
def convert(client_ref, obj)
|
122
|
+
body = extract_xml_body(obj).to_xml.root
|
123
|
+
attrs = parse(body)
|
124
|
+
attrs.merge!({
|
125
|
+
:_id => body['id'],
|
126
|
+
:url => body['href'],
|
127
|
+
:_client => client_ref,
|
128
|
+
:name => body.text_at(:name),
|
129
|
+
:description => body.text_at(:description)
|
130
|
+
})
|
131
|
+
validate_attrs!(attrs)
|
132
|
+
new(attrs.merge(:original_body => obj))
|
133
|
+
end
|
134
|
+
|
135
|
+
# Convert response for the collection responses.
|
136
|
+
#
|
137
|
+
def from_collection(client_ref, response)
|
138
|
+
response.body.to_xml.xpath('/*/*').map do |entity|
|
139
|
+
convert(client_ref, entity)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# The :_id and :_client attributes are mandotory
|
144
|
+
# to construct a Base model object.
|
145
|
+
#
|
146
|
+
def validate_attrs!(attrs)
|
147
|
+
raise error.new('The :_id must not be nil.') if attrs[:_id].nil?
|
148
|
+
raise error.new('The :_client reference is missing.') if attrs[:_client].nil?
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|