deltacloud-core 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTICE +1 -1
- data/Rakefile +63 -21
- data/bin/deltacloudd +10 -6
- data/config.ru +62 -6
- data/config/drivers/ec2.yaml +8 -0
- data/config/drivers/fgcp.yaml +13 -0
- data/deltacloud-core.gemspec +10 -2
- data/lib/cimi/collections.rb +58 -0
- data/lib/cimi/collections/address_templates.rb +49 -0
- data/lib/cimi/collections/addresses.rb +74 -0
- data/lib/cimi/collections/cloud_entry_point.rb +37 -0
- data/lib/{deltacloud/helpers/conversion_helper.rb → cimi/collections/entity_metadata.rb} +24 -16
- data/lib/cimi/collections/machine_admins.rb +74 -0
- data/lib/cimi/collections/machine_configurations.rb +49 -0
- data/lib/cimi/collections/machine_images.rb +50 -0
- data/lib/cimi/collections/machines.rb +157 -0
- data/lib/cimi/collections/network_configurations.rb +47 -0
- data/lib/cimi/collections/network_templates.rb +48 -0
- data/lib/cimi/collections/networks.rb +125 -0
- data/lib/cimi/collections/routing_group_templates.rb +47 -0
- data/lib/cimi/collections/routing_groups.rb +48 -0
- data/lib/cimi/collections/volume_configurations.rb +48 -0
- data/lib/cimi/collections/volume_images.rb +50 -0
- data/lib/cimi/collections/volumes.rb +80 -0
- data/lib/cimi/collections/vsp_configurations.rb +48 -0
- data/lib/cimi/collections/vsp_templates.rb +50 -0
- data/lib/cimi/collections/vsps.rb +108 -0
- data/lib/cimi/dependencies.rb +1 -0
- data/lib/cimi/helpers.rb +116 -0
- data/lib/cimi/helpers/cimi_helper.rb +6 -2
- data/lib/cimi/models.rb +72 -0
- data/lib/cimi/{model → models}/action.rb +1 -1
- data/lib/cimi/models/address.rb +72 -0
- data/lib/cimi/models/address_collection.rb +34 -0
- data/lib/cimi/models/address_template.rb +54 -0
- data/lib/cimi/models/address_template_collection.rb +34 -0
- data/lib/cimi/{model → models}/base.rb +2 -2
- data/lib/cimi/{model → models}/cloud_entry_point.rb +3 -5
- data/lib/cimi/{model → models}/entity_metadata.rb +7 -6
- data/lib/cimi/{model → models}/entity_metadata_collection.rb +2 -2
- data/lib/cimi/{model → models}/errors.rb +8 -0
- data/lib/cimi/{model → models}/machine.rb +10 -10
- data/lib/cimi/{model → models}/machine_admin.rb +1 -1
- data/lib/cimi/{model → models}/machine_admin_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_configuration.rb +9 -6
- data/lib/cimi/{model → models}/machine_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_image.rb +1 -1
- data/lib/cimi/{model → models}/machine_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_template.rb +0 -0
- data/lib/cimi/{model → models}/machine_template_collection.rb +2 -2
- data/lib/cimi/models/network.rb +109 -0
- data/lib/cimi/{model → models}/network_collection.rb +2 -2
- data/lib/cimi/{model → models}/network_configuration.rb +3 -4
- data/lib/cimi/{model → models}/network_configuration_collection.rb +2 -2
- data/lib/cimi/models/network_template.rb +36 -0
- data/lib/cimi/models/network_template_collection.rb +35 -0
- data/lib/cimi/models/routing_group.rb +34 -0
- data/lib/cimi/models/routing_group_collection.rb +34 -0
- data/lib/cimi/models/routing_group_template.rb +34 -0
- data/lib/cimi/models/routing_group_template_collection.rb +35 -0
- data/lib/cimi/{model → models}/schema.rb +0 -0
- data/lib/cimi/{model → models}/volume.rb +4 -4
- data/lib/cimi/{model → models}/volume_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_configuration.rb +1 -1
- data/lib/cimi/{model → models}/volume_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_image.rb +1 -1
- data/lib/cimi/{model → models}/volume_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_template.rb +0 -0
- data/lib/cimi/{model → models}/volume_template_collection.rb +2 -2
- data/lib/cimi/models/vsp.rb +102 -0
- data/lib/cimi/models/vsp_collection.rb +34 -0
- data/lib/cimi/models/vsp_configuration.rb +40 -0
- data/lib/cimi/models/vsp_configuration_collection.rb +34 -0
- data/lib/cimi/models/vsp_template.rb +34 -0
- data/lib/cimi/models/vsp_template_collection.rb +34 -0
- data/lib/cimi/server.rb +27 -549
- data/lib/deltacloud/api.rb +79 -0
- data/lib/deltacloud/collections.rb +54 -0
- data/lib/deltacloud/collections/addresses.rb +91 -0
- data/lib/deltacloud/collections/buckets.rb +273 -0
- data/lib/deltacloud/collections/drivers.rb +51 -0
- data/lib/deltacloud/collections/firewalls.rb +116 -0
- data/lib/deltacloud/collections/hardware_profiles.rb +29 -0
- data/lib/deltacloud/collections/images.rb +73 -0
- data/lib/deltacloud/collections/instance_states.rb +59 -0
- data/lib/deltacloud/collections/instances.rb +113 -0
- data/lib/deltacloud/collections/keys.rb +61 -0
- data/lib/deltacloud/collections/load_balancers.rb +102 -0
- data/lib/deltacloud/collections/metrics.rb +28 -0
- data/lib/deltacloud/collections/realms.rb +28 -0
- data/lib/deltacloud/collections/storage_snapshots.rb +51 -0
- data/lib/deltacloud/collections/storage_volumes.rb +99 -0
- data/lib/deltacloud/core_ext.rb +14 -6
- data/lib/deltacloud/core_ext/string.rb +17 -5
- data/lib/deltacloud/drivers.rb +6 -42
- data/lib/deltacloud/drivers/azure/azure_driver.rb +0 -4
- data/lib/deltacloud/{base_driver → drivers}/base_driver.rb +56 -18
- data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +142 -33
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +2 -6
- data/lib/deltacloud/{base_driver → drivers}/exceptions.rb +25 -2
- data/lib/deltacloud/drivers/features.rb +154 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +387 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1435 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +8 -11
- data/lib/deltacloud/drivers/google/google_driver.rb +2 -5
- data/lib/deltacloud/drivers/mock/data/keys/test-key.yml +28 -0
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -2
- data/lib/deltacloud/drivers/mock/mock_driver.rb +58 -40
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +145 -0
- data/lib/deltacloud/drivers/opennebula/cloud_client.rb +107 -73
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +285 -145
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +189 -126
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +427 -8
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +7 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +48 -66
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +44 -51
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +7 -8
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +1 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -3
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +8 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +39 -13
- data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +1 -0
- data/lib/deltacloud/helpers.rb +79 -7
- data/lib/{sinatra/lazy_auth.rb → deltacloud/helpers/auth_helper.rb} +5 -9
- data/lib/deltacloud/helpers/{blob_stream.rb → blob_stream_helper.rb} +7 -7
- data/lib/deltacloud/helpers/deltacloud_helper.rb +286 -0
- data/lib/deltacloud/helpers/driver_helper.rb +58 -0
- data/lib/deltacloud/helpers/rabbit_helper.rb +34 -0
- data/lib/{sinatra/url_for.rb → deltacloud/helpers/url_helper.rb} +31 -9
- data/lib/deltacloud/models.rb +19 -17
- data/lib/deltacloud/models/bucket.rb +4 -0
- data/lib/deltacloud/{hardware_profile.rb → models/hardware_profile.rb} +4 -2
- data/lib/deltacloud/models/image.rb +1 -0
- data/lib/deltacloud/models/instance.rb +4 -2
- data/lib/deltacloud/models/instance_address.rb +4 -0
- data/lib/deltacloud/models/key.rb +4 -0
- data/lib/deltacloud/models/metric.rb +40 -0
- data/lib/deltacloud/{state_machine.rb → models/state_machine.rb} +18 -1
- data/lib/deltacloud/server.rb +41 -1222
- data/lib/deltacloud_rack.rb +79 -0
- data/lib/{cimi/model/network_template.rb → ec2/helpers.rb} +7 -10
- data/lib/{deltacloud/backend_capability.rb → ec2/helpers/errors.rb} +24 -29
- data/lib/ec2/helpers/result.rb +31 -0
- data/lib/ec2/query_parser.rb +152 -0
- data/lib/ec2/server.rb +70 -0
- data/lib/{deltacloud.rb → sinatra.rb} +7 -12
- data/lib/sinatra/rack_accept.rb +13 -7
- data/lib/sinatra/rack_driver_select.rb +1 -1
- data/lib/sinatra/rack_matrix_params.rb +1 -3
- data/public/images/metric.png +0 -0
- data/public/javascripts/jquery.mobile-1.0.1.min.js +177 -0
- data/public/stylesheets/jquery.mobile-1.0.1.min.css +2 -0
- data/public/stylesheets/new.css +10 -0
- data/support/fedora/deltacloud-core.spec +1 -1
- data/tests/api/common.rb +1 -0
- data/tests/api/driver_test.rb +79 -0
- data/tests/api/library_test.rb +48 -0
- data/tests/cimi/features/step_definitions/common_steps.rb +2 -2
- data/tests/cimi/features/step_definitions/machines_steps.rb +5 -4
- data/tests/cimi/features/step_definitions/volumes_steps.rb +8 -8
- data/tests/cimi/features/support/env.rb +33 -11
- data/tests/common.rb +7 -8
- data/tests/drivers/ec2/api_test.rb +19 -0
- data/tests/drivers/ec2/common.rb +23 -0
- data/tests/drivers/ec2/drivers_test.rb +120 -0
- data/tests/drivers/ec2/hardware_profiles_test.rb +224 -0
- data/tests/drivers/ec2/images_test.rb +230 -0
- data/tests/drivers/ec2/instances_test.rb +356 -0
- data/tests/drivers/ec2/keys_test.rb +181 -0
- data/tests/drivers/ec2/realms_test.rb +146 -0
- data/tests/drivers/fgcp/api_test.rb +47 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +54 -0
- data/tests/drivers/fgcp/realms_test.rb +42 -0
- data/tests/drivers/{rackspace → fgcp}/setup.rb +5 -6
- data/tests/drivers/google/api_test.rb +10 -26
- data/tests/drivers/google/buckets_test.rb +79 -95
- data/tests/drivers/google/common.rb +54 -0
- data/tests/drivers/mock/api_test.rb +4 -127
- data/tests/drivers/mock/buckets_test.rb +195 -0
- data/tests/drivers/mock/common.rb +7 -0
- data/tests/drivers/mock/drivers_test.rb +123 -0
- data/tests/drivers/mock/hardware_profiles_test.rb +190 -100
- data/tests/drivers/mock/images_test.rb +162 -103
- data/tests/drivers/mock/instances_test.rb +310 -220
- data/tests/drivers/mock/keys_test.rb +161 -0
- data/tests/drivers/mock/realms_test.rb +109 -70
- data/tests/drivers/mock/storage_snapshots_test.rb +114 -0
- data/tests/drivers/mock/storage_volumes_test.rb +122 -0
- data/tests/drivers/openstack/api_test.rb +8 -3
- data/tests/drivers/openstack/common.rb +21 -0
- data/tests/drivers/openstack/hardware_profiles_test.rb +20 -9
- data/tests/drivers/openstack/images_test.rb +11 -5
- data/tests/drivers/openstack/instances_test.rb +61 -16
- data/tests/drivers/openstack/realms_test.rb +11 -7
- data/tests/drivers/rackspace/api_test.rb +7 -2
- data/tests/drivers/rackspace/buckets_test.rb +7 -2
- data/tests/drivers/rackspace/common.rb +16 -0
- data/tests/drivers/rackspace/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rackspace/images_test.rb +7 -2
- data/tests/drivers/rackspace/instances_test.rb +10 -5
- data/tests/drivers/rackspace/realms_test.rb +7 -2
- data/tests/drivers/rhevm/api_test.rb +12 -6
- data/tests/drivers/rhevm/{setup.rb → common.rb} +8 -1
- data/tests/drivers/rhevm/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rhevm/images_test.rb +8 -2
- data/tests/drivers/rhevm/instances_test.rb +7 -2
- data/tests/drivers/rhevm/realms_test.rb +7 -2
- data/tests/minitest_common.rb +58 -0
- data/tests/minitest_common_api_test.rb +115 -0
- data/views/addresses/associate.html.haml +1 -1
- data/views/addresses/index.html.haml +1 -1
- data/views/addresses/show.html.haml +2 -3
- data/views/api/show.html.haml +22 -9
- data/views/api/show.xml.haml +8 -7
- data/views/blobs/show.xml.haml +7 -4
- data/views/buckets/new.html.haml +2 -2
- data/views/cimi/errors/401.xml.haml +1 -1
- data/views/error.html.haml +3 -3
- data/views/errors/400.html.haml +1 -1
- data/views/errors/400.xml.haml +1 -2
- data/views/errors/401.html.haml +8 -7
- data/views/errors/401.xml.haml +1 -1
- data/views/errors/404.xml.haml +1 -0
- data/views/errors/500.xml.haml +4 -2
- data/views/{cimi/errors/403.html.haml → errors/501.html.haml} +4 -2
- data/views/errors/501.xml.haml +1 -0
- data/views/errors/502.xml.haml +1 -7
- data/views/{cimi/errors/500.html.haml → errors/504.html.haml} +0 -0
- data/views/errors/504.xml.haml +1 -0
- data/views/firewalls/new.html.haml +2 -2
- data/views/firewalls/new_rule.html.haml +1 -1
- data/views/firewalls/show.html.haml +1 -1
- data/views/hardware_profiles/index.html.haml +3 -1
- data/views/hardware_profiles/index.xml.haml +2 -2
- data/views/hardware_profiles/show.html.haml +3 -3
- data/views/hardware_profiles/show.xml.haml +3 -3
- data/views/images/show.html.haml +5 -0
- data/views/images/show.xml.haml +6 -1
- data/views/instance_states/show.html.haml +1 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/new.html.haml +54 -39
- data/views/instances/run_command.html.haml +24 -15
- data/views/instances/show.html.haml +7 -3
- data/views/instances/show.xml.haml +2 -2
- data/views/keys/show.xml.haml +1 -0
- data/views/layout.html.haml +5 -9
- data/views/load_balancers/show.html.haml +12 -6
- data/views/metrics/index.html.haml +13 -0
- data/views/metrics/index.xml.haml +5 -0
- data/views/metrics/show.html.haml +23 -0
- data/views/metrics/show.xml.haml +9 -0
- data/views/realms/show.xml.haml +2 -1
- data/views/root/index.html.haml +1 -1
- data/views/storage_snapshots/show.html.haml +1 -1
- data/views/storage_snapshots/show.xml.haml +1 -0
- data/views/storage_volumes/attach.html.haml +1 -2
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +22 -16
- data/views/storage_volumes/show.html.haml +10 -4
- data/views/storage_volumes/show.xml.haml +3 -4
- metadata +547 -519
- data/DISCLAIMER +0 -8
- data/lib/cimi/model.rb +0 -52
- data/lib/cimi/model/network.rb +0 -69
- data/lib/deltacloud/base_driver.rb +0 -18
- data/lib/deltacloud/base_driver/features.rb +0 -262
- data/lib/deltacloud/base_driver/mock_driver.rb +0 -78
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -186
- data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +0 -521
- data/lib/deltacloud/helpers/application_helper.rb +0 -267
- data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -50
- data/lib/deltacloud/helpers/json_helper.rb +0 -31
- data/lib/deltacloud/method_serializer.rb +0 -83
- data/lib/deltacloud/validation.rb +0 -107
- data/lib/sinatra/rabbit.rb +0 -441
- data/lib/sinatra/rack_runtime.rb +0 -47
- data/lib/sinatra/rack_syslog.rb +0 -86
- data/lib/sinatra/sinatra_verbose.rb +0 -73
- data/lib/sinatra/static_assets.rb +0 -99
- data/public/javascripts/jquery.mobile-1.0rc1.min.js +0 -170
- data/public/stylesheets/jquery.mobile-1.0rc1.min.css +0 -12
- data/tests/drivers/google/setup.rb +0 -38
- data/tests/drivers/mock/instance_states_test.rb +0 -71
- data/tests/drivers/mock/setup.rb +0 -3
- data/tests/drivers/mock/url_for_test.rb +0 -67
- data/tests/drivers/openstack/setup.rb +0 -20
- data/views/cimi/errors/400.html.haml +0 -41
- data/views/cimi/errors/401.html.haml +0 -41
- data/views/cimi/errors/404.html.haml +0 -29
- data/views/cimi/errors/405.html.haml +0 -29
- data/views/cimi/errors/502.html.haml +0 -43
- data/views/cimi/errors/backend_capability_failure.html.haml +0 -29
@@ -1,186 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
-
# contributor license agreements. See the NOTICE file distributed with
|
4
|
-
# this work for additional information regarding copyright ownership. The
|
5
|
-
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
6
|
-
# "License"); you may not use this file except in compliance with the
|
7
|
-
# License. You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
-
# License for the specific language governing permissions and limitations
|
15
|
-
# under the License.
|
16
|
-
|
17
|
-
module RightAws
|
18
|
-
class MockEc2
|
19
|
-
|
20
|
-
def initialize(opts={})
|
21
|
-
end
|
22
|
-
|
23
|
-
def describe_images(id)
|
24
|
-
load_fixtures_for(:images).select { |i| i[:aws_id].eql?(id) }
|
25
|
-
end
|
26
|
-
|
27
|
-
def describe_images_by_owner(id)
|
28
|
-
load_fixtures_for(:images).select { |i| i[:aws_owner].eql?(id) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def describe_images(opts={})
|
32
|
-
load_fixtures_for(:images)
|
33
|
-
end
|
34
|
-
|
35
|
-
def describe_availability_zones(opts={})
|
36
|
-
load_fixtures_for(:realms)
|
37
|
-
end
|
38
|
-
|
39
|
-
def describe_instances(opts={})
|
40
|
-
instances = load_fixtures_for(:instances)
|
41
|
-
instances.each_with_index do |instance, i|
|
42
|
-
instances[i] = update_delayed_state(instance)
|
43
|
-
return [instance] if opts and opts[:id] and instance[:aws_instance_id].eql?(opts[:id])
|
44
|
-
end
|
45
|
-
update_fixtures_for(:instances, instances)
|
46
|
-
instances
|
47
|
-
end
|
48
|
-
|
49
|
-
def run_instances(image_id, min_count, max_count, group_ids, key_name, user_data='', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil)
|
50
|
-
|
51
|
-
instances = load_fixtures_for(:instances)
|
52
|
-
image = load_fixtures_for(:images).select { |img| img[:aws_id].eql?(image_id) }.first
|
53
|
-
|
54
|
-
if availability_zone
|
55
|
-
realm = load_fixtures_for(:realms).select { |realm| realm[:zone_name].eql?(availability_zone) }.first
|
56
|
-
else
|
57
|
-
realm = load_fixtures_for(:realms).first
|
58
|
-
end
|
59
|
-
|
60
|
-
raise Exception unless image
|
61
|
-
raise Exception unless realm
|
62
|
-
|
63
|
-
instance = { }
|
64
|
-
instance[:aws_image_id] = image[:aws_id]
|
65
|
-
instance[:aws_availability_zone] = realm[:zone_name]
|
66
|
-
instance[:aws_instance_type] = instance_type
|
67
|
-
instance[:aws_owner] = user_data
|
68
|
-
instance[:aws_state] = 'pending'
|
69
|
-
instance[:aws_reason] = ''
|
70
|
-
instance[:dns_name] = "#{random_dns}-01-C9.usma2.compute.amazonaws.com"
|
71
|
-
instance[:private_dns_name] = "#{random_dns}-02-P9.usma2.compute.amazonaws.com"
|
72
|
-
instance[:aws_state_code] = "0"
|
73
|
-
instance[:aws_key_name] = "staging"
|
74
|
-
instance[:aws_kernel_id] = "aki-be3adfd7"
|
75
|
-
instance[:aws_ramdisk_id] = "ari-ce34gad7"
|
76
|
-
instance[:aws_groups] = ["default"]
|
77
|
-
instance[:aws_instance_id] = random_instance_id
|
78
|
-
instance[:aws_reservation_id] = "r-aabbccdd"
|
79
|
-
instance[:aws_launch_time] = instance_time_format
|
80
|
-
|
81
|
-
instances << instance
|
82
|
-
|
83
|
-
update_fixtures_for(:instances, instances)
|
84
|
-
|
85
|
-
return [instance]
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
def terminate_instances(id)
|
90
|
-
update_instance_state(id, 'stopping', '80')
|
91
|
-
end
|
92
|
-
|
93
|
-
def reboot_instances(id)
|
94
|
-
update_instance_state(id, 'pending', '0')
|
95
|
-
end
|
96
|
-
|
97
|
-
alias :destroy_instance :terminate_instances
|
98
|
-
|
99
|
-
def describe_snapshots(opts={})
|
100
|
-
load_fixtures_for(:storage_snapshot)
|
101
|
-
end
|
102
|
-
|
103
|
-
def describe_volumes(opts={})
|
104
|
-
load_fixtures_for(:storage_volume)
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def driver_dir
|
110
|
-
File::expand_path(File::join(File::dirname(__FILE__), '../../../../features/support/ec2'))
|
111
|
-
end
|
112
|
-
|
113
|
-
def fixtures_path
|
114
|
-
File::expand_path(File::join(driver_dir, 'fixtures'))
|
115
|
-
end
|
116
|
-
|
117
|
-
def load_fixtures_for(collection)
|
118
|
-
YAML.load_file(File::join(fixtures_path, "#{collection}.yaml"))
|
119
|
-
end
|
120
|
-
|
121
|
-
def update_fixtures_for(collection, new_data)
|
122
|
-
File.open(File::join(fixtures_path, "#{collection}.yaml"), 'w' ) do |out|
|
123
|
-
YAML.dump(new_data, out)
|
124
|
-
end
|
125
|
-
return new_data
|
126
|
-
end
|
127
|
-
|
128
|
-
def instance_time_format
|
129
|
-
DateTime.now.to_s.gsub(/\+(.+)$/, '.000Z')
|
130
|
-
end
|
131
|
-
|
132
|
-
def random_instance_id
|
133
|
-
id_1 = ("%.4s" % Time.now.to_i.to_s.reverse).reverse
|
134
|
-
id_2 = ("%.3s" % Time.now.to_i.to_s.reverse)
|
135
|
-
"i-#{id_1}f#{id_2}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def random_dns
|
139
|
-
"domU-#{rand(90)+10}-#{rand(90)+10}-#{rand(90)+10}-#{rand(90)+10}"
|
140
|
-
end
|
141
|
-
|
142
|
-
def update_delayed_state(instance)
|
143
|
-
time = DateTime.now - DateTime.parse(instance[:aws_launch_time])
|
144
|
-
hours, minutes, seconds, frac = Date.day_fraction_to_time(time)
|
145
|
-
|
146
|
-
if (minutes>(rand(2)+1) or hours>0) and instance[:aws_state].eql?('pending')
|
147
|
-
instance[:aws_state], instance[:aws_state_code] = 'running', '16'
|
148
|
-
end
|
149
|
-
|
150
|
-
if (minutes>(rand(1)+1) or hours>0) and instance[:aws_state].eql?('stopping')
|
151
|
-
instance[:aws_state], instance[:aws_state_code] = 'stopped', '80'
|
152
|
-
end
|
153
|
-
|
154
|
-
return instance
|
155
|
-
end
|
156
|
-
|
157
|
-
def update_instance_state(id, state, state_code)
|
158
|
-
instance = describe_instances(:id => id).first
|
159
|
-
if instance
|
160
|
-
instance[:aws_state], instance[:aws_state_code] = state, state_code
|
161
|
-
instance[:aws_launch_time] = instance_time_format
|
162
|
-
instances = load_fixtures_for(:instances)
|
163
|
-
instances.each_with_index do |inst, i|
|
164
|
-
instances[i] = instance if inst[:aws_instance_id].eql?(id)
|
165
|
-
end
|
166
|
-
update_fixtures_for(:instances, instances)
|
167
|
-
return instance
|
168
|
-
else
|
169
|
-
raise Exception
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
Deltacloud::Drivers::EC2::EC2Driver.class_eval do
|
177
|
-
alias_method :original_new_client, :new_client
|
178
|
-
|
179
|
-
def new_client(credentials, opts={})
|
180
|
-
if credentials.user != 'mockuser' and credentials.password != 'mockpassword'
|
181
|
-
raise "AuthFailure"
|
182
|
-
end
|
183
|
-
RightAws::MockEc2.new
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
@@ -1,521 +0,0 @@
|
|
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
|
-
|
17
|
-
require 'rubygems'
|
18
|
-
require 'restclient'
|
19
|
-
require 'nokogiri'
|
20
|
-
require 'digest/md5'
|
21
|
-
require 'json'
|
22
|
-
|
23
|
-
module RHEVM
|
24
|
-
|
25
|
-
# NOTE: Injected file will be available in floppy drive inside
|
26
|
-
# the instance. (Be sure you 'modprobe floppy' on Linux)
|
27
|
-
FILEINJECT_PATH = "deltacloud-user-data.txt"
|
28
|
-
|
29
|
-
def self.client(url)
|
30
|
-
RestClient::Resource.new(url)
|
31
|
-
end
|
32
|
-
|
33
|
-
class BackendVersionUnsupportedException < StandardError; end
|
34
|
-
class RHEVMBackendException < StandardError
|
35
|
-
def initialize(message)
|
36
|
-
@message = message
|
37
|
-
super
|
38
|
-
end
|
39
|
-
|
40
|
-
def message
|
41
|
-
@message
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Client
|
46
|
-
|
47
|
-
attr_reader :credentials, :api_entrypoint, :datacenter_id
|
48
|
-
|
49
|
-
def initialize(username, password, api_entrypoint, datacenter_id=nil)
|
50
|
-
@credentials = { :username => username, :password => password }
|
51
|
-
@datacenter_id = datacenter_id
|
52
|
-
@api_entrypoint = api_entrypoint
|
53
|
-
end
|
54
|
-
|
55
|
-
def vms(opts={})
|
56
|
-
headers = {
|
57
|
-
:accept => "application/xml; detail=disks; detail=nics; detail=hosts"
|
58
|
-
}
|
59
|
-
headers.merge!(auth_header)
|
60
|
-
if opts[:id]
|
61
|
-
vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/vms/%s" % opts[:id]].get(headers)).root
|
62
|
-
return [] unless current_datacenter.cluster_ids.include?((vm/'cluster').first[:id])
|
63
|
-
[ RHEVM::VM::new(self, vm)]
|
64
|
-
else
|
65
|
-
Client::parse_response(RHEVM::client(@api_entrypoint)["/vms"].get(headers)).xpath('/vms/vm').collect do |vm|
|
66
|
-
next unless current_datacenter.cluster_ids.include?((vm/'cluster').first[:id])
|
67
|
-
RHEVM::VM::new(self, vm)
|
68
|
-
end.compact
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def vm_action(id, action, headers={})
|
73
|
-
headers.merge!(auth_header)
|
74
|
-
headers.merge!({:accept => 'application/xml'})
|
75
|
-
vm = vms(:id => id)
|
76
|
-
raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") if vm.empty?
|
77
|
-
if action==:delete
|
78
|
-
RHEVM::client(@api_entrypoint)["/vms/%s" % id].delete(headers)
|
79
|
-
else
|
80
|
-
headers.merge!({ :content_type => 'application/xml' })
|
81
|
-
begin
|
82
|
-
client_response = RHEVM::client(@api_entrypoint)["/vms/%s/%s" % [id, action]].post('<action/>', headers)
|
83
|
-
rescue
|
84
|
-
if $!.is_a?(RestClient::BadRequest)
|
85
|
-
fault = (Nokogiri::XML($!.http_body)/'//fault/detail')
|
86
|
-
fault = fault.text.gsub(/\[|\]/, '') if fault
|
87
|
-
end
|
88
|
-
fault ||= $!.message
|
89
|
-
raise RHEVMBackendException::new(fault)
|
90
|
-
end
|
91
|
-
xml_response = Client::parse_response(client_response)
|
92
|
-
|
93
|
-
return false if (xml_response/'action/status').first.text.strip.upcase!="COMPLETE"
|
94
|
-
end
|
95
|
-
return true
|
96
|
-
end
|
97
|
-
|
98
|
-
def api_version?(major)
|
99
|
-
headers = {
|
100
|
-
:content_type => 'application/xml',
|
101
|
-
:accept => 'application/xml'
|
102
|
-
}
|
103
|
-
headers.merge!(auth_header)
|
104
|
-
result_xml = Nokogiri::XML(RHEVM::client(@api_entrypoint)["/"].get(headers))
|
105
|
-
if (result_xml/'api/system_version').empty?
|
106
|
-
(result_xml/'/api/product_info/version').first[:major].strip == major
|
107
|
-
else
|
108
|
-
(result_xml/'/api/system_version').first[:major].strip == major
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def cluster_version?(cluster_id, major)
|
113
|
-
headers = {
|
114
|
-
:content_type => 'application/xml',
|
115
|
-
:accept => 'application/xml'
|
116
|
-
}
|
117
|
-
headers.merge!(auth_header)
|
118
|
-
result_xml = Nokogiri::XML(RHEVM::client(@api_entrypoint)["/clusters/%s" % cluster_id].get(headers))
|
119
|
-
(result_xml/'/cluster/version').first[:major].strip == major
|
120
|
-
end
|
121
|
-
|
122
|
-
def capability?(name)
|
123
|
-
headers = {
|
124
|
-
:content_type => 'application/xml',
|
125
|
-
:accept => 'application/xml'
|
126
|
-
}
|
127
|
-
headers.merge!(auth_header)
|
128
|
-
result_xml = Nokogiri::XML(RHEVM::client(@api_entrypoint)["/capabilities"].get(headers))
|
129
|
-
!(result_xml/"/capabilities/version/custom_properties/custom_property[@name='#{name}']").empty?
|
130
|
-
end
|
131
|
-
|
132
|
-
def create_vm(template_id, opts={})
|
133
|
-
opts ||= {}
|
134
|
-
templ = template(template_id)
|
135
|
-
raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") unless templ
|
136
|
-
builder = Nokogiri::XML::Builder.new do
|
137
|
-
vm {
|
138
|
-
name opts[:name] || "i-#{Time.now.to_i}"
|
139
|
-
template_(:id => template_id)
|
140
|
-
cluster_(:id => opts[:realm_id].nil? ? templ.cluster.id : opts[:realm_id])
|
141
|
-
type_ opts[:hwp_id] || 'desktop'
|
142
|
-
memory opts[:hwp_memory] ? (opts[:hwp_memory].to_i*1024*1024).to_s : (512*1024*1024).to_s
|
143
|
-
cpu {
|
144
|
-
topology( :cores => (opts[:hwp_cpu] || '1'), :sockets => '1' )
|
145
|
-
}
|
146
|
-
if opts[:user_data] and not opts[:user_data].empty?
|
147
|
-
if api_version?('3') and cluster_version?((opts[:realm_id] || clusters.first.id), '3')
|
148
|
-
raise "Required VDSM hook 'floppyinject' not supported by RHEV-M" unless capability?(:floppyinject)
|
149
|
-
custom_properties {
|
150
|
-
custom_property({
|
151
|
-
:name => "floppyinject",
|
152
|
-
:value => "#{RHEVM::FILEINJECT_PATH}:#{opts[:user_data]}",
|
153
|
-
:regexp => "^([^:]+):(.*)$"})
|
154
|
-
}
|
155
|
-
else
|
156
|
-
raise BackendVersionUnsupportedException.new
|
157
|
-
end
|
158
|
-
end
|
159
|
-
}
|
160
|
-
end
|
161
|
-
headers = opts[:headers] || {}
|
162
|
-
headers.merge!({
|
163
|
-
:content_type => 'application/xml',
|
164
|
-
:accept => 'application/xml',
|
165
|
-
})
|
166
|
-
templates = templates(:id => template_id)
|
167
|
-
raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") if templates.empty?
|
168
|
-
headers.merge!(auth_header)
|
169
|
-
begin
|
170
|
-
vm = RHEVM::client(@api_entrypoint)["/vms"].post(Nokogiri::XML(builder.to_xml).root.to_s, headers)
|
171
|
-
rescue
|
172
|
-
if $!.respond_to?(:http_body)
|
173
|
-
fault = (Nokogiri::XML($!.http_body)/'/fault/detail').first
|
174
|
-
fault = fault.text.gsub(/\[|\]/, '') if fault
|
175
|
-
end
|
176
|
-
fault ||= $!.message
|
177
|
-
raise RHEVMBackendException::new(fault)
|
178
|
-
end
|
179
|
-
RHEVM::VM::new(self, Nokogiri::XML(vm).root)
|
180
|
-
end
|
181
|
-
|
182
|
-
def create_template(vm_id, opts={})
|
183
|
-
opts ||= {}
|
184
|
-
builder = Nokogiri::XML::Builder.new do
|
185
|
-
template_ {
|
186
|
-
name opts[:name]
|
187
|
-
description opts[:description]
|
188
|
-
vm(:id => vm_id)
|
189
|
-
}
|
190
|
-
end
|
191
|
-
headers = opts[:headers] || {}
|
192
|
-
headers.merge!({
|
193
|
-
:content_type => 'application/xml',
|
194
|
-
:accept => 'application/xml',
|
195
|
-
})
|
196
|
-
headers.merge!(auth_header)
|
197
|
-
template = RHEVM::client(@api_entrypoint)["/templates"].post(Nokogiri::XML(builder.to_xml).root.to_s, headers)
|
198
|
-
RHEVM::Template::new(self, Nokogiri::XML(template).root)
|
199
|
-
end
|
200
|
-
|
201
|
-
def destroy_template(id, headers={})
|
202
|
-
headers.merge!({
|
203
|
-
:content_type => 'application/xml',
|
204
|
-
:accept => 'application/xml',
|
205
|
-
})
|
206
|
-
tmpl = template(id)
|
207
|
-
raise RHEVMBackendException::new("Requested VM not found in datacenter #{self.current_datacenter.id}") unless tmpl
|
208
|
-
headers.merge!(auth_header)
|
209
|
-
RHEVM::client(@api_entrypoint)["/templates/%s" % id].delete(headers)
|
210
|
-
return true
|
211
|
-
end
|
212
|
-
|
213
|
-
def templates(opts={})
|
214
|
-
headers = {
|
215
|
-
:accept => "application/xml"
|
216
|
-
}
|
217
|
-
headers.merge!(auth_header)
|
218
|
-
rhevm_templates = RHEVM::client(@api_entrypoint)["/templates"].get(headers)
|
219
|
-
Client::parse_response(rhevm_templates).xpath('/templates/template').collect do |t|
|
220
|
-
next unless current_datacenter.cluster_ids.include?((t/'cluster').first[:id])
|
221
|
-
RHEVM::Template::new(self, t)
|
222
|
-
end.compact
|
223
|
-
end
|
224
|
-
|
225
|
-
def template(template_id)
|
226
|
-
headers = {
|
227
|
-
:accept => "application/xml"
|
228
|
-
}
|
229
|
-
headers.merge!(auth_header)
|
230
|
-
rhevm_template = RHEVM::client(@api_entrypoint)["/templates/%s" % template_id].get(headers)
|
231
|
-
RHEVM::Template::new(self, Client::parse_response(rhevm_template).root)
|
232
|
-
end
|
233
|
-
|
234
|
-
def datacenters(opts={})
|
235
|
-
headers = {
|
236
|
-
:accept => "application/xml"
|
237
|
-
}
|
238
|
-
headers.merge!(auth_header)
|
239
|
-
rhevm_datacenters = RHEVM::client(@api_entrypoint)["/datacenters"].get(headers)
|
240
|
-
Client::parse_response(rhevm_datacenters).xpath('/data_centers/data_center').collect do |dc|
|
241
|
-
RHEVM::DataCenter::new(self, dc)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
def clusters
|
246
|
-
current_datacenter.clusters
|
247
|
-
end
|
248
|
-
|
249
|
-
def cluster(cluster_id)
|
250
|
-
current_datacenter.cluster(cluster_id)
|
251
|
-
end
|
252
|
-
|
253
|
-
def current_datacenter
|
254
|
-
@current_datacenter ||= self.datacenter_id ? datacenter(self.datacenter_id) : datacenters.first
|
255
|
-
end
|
256
|
-
|
257
|
-
def datacenter(datacenter_id)
|
258
|
-
headers = {
|
259
|
-
:accept => "application/xml"
|
260
|
-
}
|
261
|
-
headers.merge!(auth_header)
|
262
|
-
rhevm_datacenter = RHEVM::client(@api_entrypoint)["/datacenters/%s" % datacenter_id].get(headers)
|
263
|
-
RHEVM::DataCenter::new(self, Client::parse_response(rhevm_datacenter).root)
|
264
|
-
end
|
265
|
-
|
266
|
-
def hosts(opts={})
|
267
|
-
headers = {
|
268
|
-
:accept => "application/xml"
|
269
|
-
}
|
270
|
-
headers.merge!(auth_header)
|
271
|
-
if opts[:id]
|
272
|
-
vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/hosts/%s" % opts[:id]].get(headers)).root
|
273
|
-
[ RHEVM::Host::new(self, vm)]
|
274
|
-
else
|
275
|
-
Client::parse_response(RHEVM::client(@api_entrypoint)["/hosts"].get(headers)).xpath('/hosts/host').collect do |vm|
|
276
|
-
RHEVM::Host::new(self, vm)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
def storagedomains(opts={})
|
282
|
-
headers = {
|
283
|
-
:accept => "application/xml"
|
284
|
-
}
|
285
|
-
headers.merge!(auth_header)
|
286
|
-
if opts[:id]
|
287
|
-
vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/storagedomains/%s" % opts[:id]].get(headers)).root
|
288
|
-
[ RHEVM::StorageDomain::new(self, vm)]
|
289
|
-
else
|
290
|
-
Client::parse_response(RHEVM::client(@api_entrypoint)["/storagedomains"].get(headers)).xpath('/storage_domains/storage_domain').collect do |vm|
|
291
|
-
RHEVM::StorageDomain::new(self, vm)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def auth_header
|
297
|
-
# As RDOC says this is the function for strict_encode64:
|
298
|
-
encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
|
299
|
-
{ :authorization => "Basic " + encoded_credentials }
|
300
|
-
end
|
301
|
-
|
302
|
-
def base_url
|
303
|
-
url = URI.parse(@api_entrypoint)
|
304
|
-
"#{url.scheme}://#{url.host}:#{url.port}"
|
305
|
-
end
|
306
|
-
|
307
|
-
def self.parse_response(response)
|
308
|
-
Nokogiri::XML(response)
|
309
|
-
end
|
310
|
-
|
311
|
-
def has_datacenter?(vm)
|
312
|
-
value=!(vm/'data_center').empty?
|
313
|
-
value
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
class BaseObject
|
318
|
-
attr_accessor :id, :href, :name
|
319
|
-
attr_reader :client
|
320
|
-
|
321
|
-
def initialize(client, id, href, name)
|
322
|
-
@id, @href, @name = id, href, name
|
323
|
-
@client = client
|
324
|
-
self
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
class Link
|
329
|
-
attr_accessor :id, :href, :client
|
330
|
-
|
331
|
-
def initialize(client, id, href)
|
332
|
-
@id, @href = id, href
|
333
|
-
@client = client
|
334
|
-
end
|
335
|
-
|
336
|
-
def follow
|
337
|
-
xml = Client::parse_response(RHEVM::client(@client.base_url)[@href].get(@client.auth_header))
|
338
|
-
object_class = ::RHEVM.const_get(xml.root.name.camelize)
|
339
|
-
object_class.new(@client, (xml.root))
|
340
|
-
end
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
|
-
class VM < BaseObject
|
345
|
-
attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template, :macs
|
346
|
-
attr_reader :storage, :cores, :username, :creation_time
|
347
|
-
attr_reader :ip, :vnc
|
348
|
-
|
349
|
-
def initialize(client, xml)
|
350
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
351
|
-
@username = client.credentials[:username]
|
352
|
-
parse_xml_attributes!(xml)
|
353
|
-
self
|
354
|
-
end
|
355
|
-
|
356
|
-
private
|
357
|
-
|
358
|
-
def parse_xml_attributes!(xml)
|
359
|
-
@description = ((xml/'description').first.text rescue '')
|
360
|
-
@status = (xml/'status').first.text
|
361
|
-
@memory = (xml/'memory').first.text
|
362
|
-
@profile = (xml/'type').first.text
|
363
|
-
@template = Link::new(@client, (xml/'template').first[:id], (xml/'template').first[:href])
|
364
|
-
@host = Link::new(@client, (xml/'host').first[:id], (xml/'host').first[:href]) rescue nil
|
365
|
-
@cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
|
366
|
-
@display = {
|
367
|
-
:type => (xml/'display/type').first.text,
|
368
|
-
:address => ((xml/'display/address').first.text rescue nil),
|
369
|
-
:port => ((xml/'display/port').first.text rescue nil),
|
370
|
-
:monitors => (xml/'display/monitors').first.text
|
371
|
-
}
|
372
|
-
@cores = ((xml/'cpu/topology').first[:cores] rescue nil)
|
373
|
-
@storage = ((xml/'disks/disk/size').first.text rescue nil)
|
374
|
-
@macs = (xml/'nics/nic/mac').collect { |mac| mac[:address] }
|
375
|
-
@creation_time = (xml/'creation_time').text
|
376
|
-
@ip = ((xml/'guest_info/ips/ip').first[:address] rescue nil)
|
377
|
-
@vnc = {
|
378
|
-
:address => ((xml/'display/address').first.text rescue "127.0.0.1"),
|
379
|
-
:port => ((xml/'display/port').first.text rescue "5890")
|
380
|
-
} unless @ip
|
381
|
-
end
|
382
|
-
|
383
|
-
end
|
384
|
-
|
385
|
-
class Template < BaseObject
|
386
|
-
attr_reader :description, :status, :cluster
|
387
|
-
|
388
|
-
def initialize(client, xml)
|
389
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
390
|
-
parse_xml_attributes!(xml)
|
391
|
-
self
|
392
|
-
end
|
393
|
-
|
394
|
-
private
|
395
|
-
|
396
|
-
def parse_xml_attributes!(xml)
|
397
|
-
@description = ((xml/'description').first.text rescue nil)
|
398
|
-
@status = (xml/'status').first.text
|
399
|
-
@cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
class Cluster < BaseObject
|
404
|
-
attr_reader :description, :datacenter, :version
|
405
|
-
|
406
|
-
def initialize(client, xml)
|
407
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
408
|
-
parse_xml_attributes!(xml)
|
409
|
-
self
|
410
|
-
end
|
411
|
-
|
412
|
-
private
|
413
|
-
|
414
|
-
def parse_xml_attributes!(xml)
|
415
|
-
@description = ((xml/'description').first.text rescue nil)
|
416
|
-
@version =((xml/'version').first[:major].strip rescue nil)
|
417
|
-
unless (xml/'data_center').empty?
|
418
|
-
@datacenter = Link::new(@client, (xml/'data_center').first[:id], (xml/'data_center').first[:href])
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
end
|
423
|
-
|
424
|
-
class DataCenter < BaseObject
|
425
|
-
attr_reader :description, :status
|
426
|
-
|
427
|
-
def initialize(client, xml)
|
428
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
429
|
-
parse_xml_attributes!(xml)
|
430
|
-
self
|
431
|
-
end
|
432
|
-
|
433
|
-
def clusters
|
434
|
-
headers = {
|
435
|
-
:accept => "application/xml; detail=datacenters"
|
436
|
-
}
|
437
|
-
headers.merge!(client.auth_header)
|
438
|
-
clusters_list = RHEVM::client(client.api_entrypoint)["/clusters"].get(headers)
|
439
|
-
cluster_arr = Client::parse_response(clusters_list).xpath('/clusters/cluster')
|
440
|
-
clusters_arr = []
|
441
|
-
cluster_arr.each do |cluster|
|
442
|
-
cluster = RHEVM::Cluster.new(self.client, cluster)
|
443
|
-
clusters_arr << cluster if cluster.datacenter && cluster.datacenter.id == client.datacenter_id
|
444
|
-
end
|
445
|
-
clusters_arr
|
446
|
-
end
|
447
|
-
|
448
|
-
def cluster(cluster_id)
|
449
|
-
headers = {
|
450
|
-
:accept => "application/xml; detail=datacenters"
|
451
|
-
}
|
452
|
-
headers.merge!(client.auth_header)
|
453
|
-
cluster_xml = RHEVM::client(client.api_entrypoint)["/clusters/%s" % cluster_id].get(headers)
|
454
|
-
cluster = RHEVM::Cluster.new(self.client, cluster_xml)
|
455
|
-
if cluster.datacenter && cluster.datacenter.id == client.datacenter_id
|
456
|
-
cluster
|
457
|
-
else
|
458
|
-
nil
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
def cluster_ids
|
463
|
-
@cluster_ids ||= clusters.collect { |c| c.id }
|
464
|
-
end
|
465
|
-
|
466
|
-
private
|
467
|
-
|
468
|
-
def parse_xml_attributes!(xml)
|
469
|
-
@description = ((xml/'description').first.text rescue nil)
|
470
|
-
@status = (xml/'status').first.text
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
class Host < BaseObject
|
475
|
-
attr_reader :description, :status, :cluster
|
476
|
-
|
477
|
-
def initialize(client, xml)
|
478
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
479
|
-
parse_xml_attributes!(xml)
|
480
|
-
self
|
481
|
-
end
|
482
|
-
|
483
|
-
private
|
484
|
-
|
485
|
-
def parse_xml_attributes!(xml)
|
486
|
-
@description = ((xml/'description').first.text rescue nil)
|
487
|
-
@status = (xml/'status').first.text
|
488
|
-
@clister = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
class StorageDomain < BaseObject
|
493
|
-
attr_reader :available, :used, :kind, :address, :path
|
494
|
-
|
495
|
-
def initialize(client, xml)
|
496
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
497
|
-
parse_xml_attributes!(xml)
|
498
|
-
self
|
499
|
-
end
|
500
|
-
|
501
|
-
private
|
502
|
-
|
503
|
-
def parse_xml_attributes!(xml)
|
504
|
-
@available = (xml/'available').first.text
|
505
|
-
@used = (xml/'used').first.text
|
506
|
-
@kind = (xml/'storage/type').first.text
|
507
|
-
@address = ((xml/'storage/address').first.text rescue nil)
|
508
|
-
@path = ((xml/'storage/path').first.text rescue nil)
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
end
|
513
|
-
|
514
|
-
class String
|
515
|
-
unless method_defined?(:camelize)
|
516
|
-
# Camelize converts strings to UpperCamelCase
|
517
|
-
def camelize
|
518
|
-
self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
519
|
-
end
|
520
|
-
end
|
521
|
-
end
|