deltacloud-core 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +63 -7
- data/bin/deltacloudd +29 -17
- data/config.ru +5 -3
- data/config/drivers/ec2.yaml +9 -0
- data/config/drivers/google.yaml +3 -0
- data/config/drivers/openstack.yaml +3 -0
- data/deltacloud-core.gemspec +1 -1
- data/lib/cimi/dependencies.rb +62 -0
- data/lib/cimi/helpers/cimi_helper.rb +50 -0
- data/lib/cimi/model.rb +52 -0
- data/lib/cimi/model/action.rb +24 -0
- data/lib/cimi/model/base.rb +249 -0
- data/lib/cimi/model/cloud_entry_point.rb +48 -0
- data/lib/cimi/model/entity_metadata.rb +83 -0
- data/lib/cimi/model/entity_metadata_collection.rb +31 -0
- data/lib/cimi/model/errors.rb +40 -0
- data/lib/cimi/model/machine.rb +227 -0
- data/lib/cimi/model/machine_admin.rb +59 -0
- data/lib/cimi/model/machine_admin_collection.rb +34 -0
- data/lib/cimi/model/machine_collection.rb +34 -0
- data/lib/cimi/model/machine_configuration.rb +67 -0
- data/lib/cimi/model/machine_configuration_collection.rb +34 -0
- data/lib/cimi/model/machine_image.rb +46 -0
- data/lib/cimi/model/machine_image_collection.rb +34 -0
- data/lib/cimi/model/machine_template.rb +41 -0
- data/lib/cimi/model/machine_template_collection.rb +34 -0
- data/lib/cimi/model/network.rb +69 -0
- data/lib/cimi/model/network_collection.rb +34 -0
- data/lib/cimi/model/network_configuration.rb +50 -0
- data/lib/cimi/model/network_configuration_collection.rb +34 -0
- data/lib/cimi/model/network_template.rb +26 -0
- data/lib/cimi/model/schema.rb +277 -0
- data/lib/cimi/model/volume.rb +103 -0
- data/lib/cimi/model/volume_collection.rb +34 -0
- data/lib/cimi/model/volume_configuration.rb +60 -0
- data/lib/cimi/model/volume_configuration_collection.rb +34 -0
- data/lib/cimi/model/volume_image.rb +49 -0
- data/lib/cimi/model/volume_image_collection.rb +34 -0
- data/lib/cimi/model/volume_template.rb +23 -0
- data/lib/cimi/model/volume_template_collection.rb +34 -0
- data/lib/cimi/server.rb +575 -0
- data/lib/deltacloud/base_driver/base_driver.rb +11 -1
- data/lib/deltacloud/core_ext.rb +2 -0
- data/lib/deltacloud/core_ext/array.rb +25 -0
- data/lib/deltacloud/core_ext/hash.rb +7 -0
- data/lib/deltacloud/core_ext/proc.rb +31 -0
- data/lib/deltacloud/core_ext/string.rb +15 -0
- data/lib/deltacloud/drivers/condor/condor_driver.rb +2 -1
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +32 -10
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
- data/lib/deltacloud/drivers/google/google_driver.rb +233 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +7 -2
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +7 -2
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +7 -2
- data/lib/deltacloud/drivers/mock/mock_client.rb +17 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +82 -8
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +1 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +47 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +8 -8
- data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +122 -49
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +42 -22
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +1 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -2
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +2 -2
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +25 -4
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +35 -12
- data/lib/deltacloud/hardware_profile.rb +34 -10
- data/lib/deltacloud/helpers/application_helper.rb +3 -28
- data/lib/deltacloud/helpers/blob_stream.rb +2 -1
- data/lib/deltacloud/models.rb +2 -0
- data/lib/deltacloud/models/bucket.rb +1 -1
- data/lib/deltacloud/models/image.rb +1 -1
- data/lib/deltacloud/models/instance.rb +2 -1
- data/lib/deltacloud/models/instance_address.rb +56 -0
- data/lib/deltacloud/models/provider.rb +27 -0
- data/{server.rb → lib/deltacloud/server.rb} +72 -14
- data/lib/deltacloud/validation.rb +31 -10
- data/lib/sinatra/rabbit.rb +34 -26
- data/lib/sinatra/rack_accept.rb +5 -5
- data/lib/sinatra/rack_matrix_params.rb +6 -2
- data/lib/sinatra/rack_syslog.rb +3 -3
- data/lib/sinatra/static_assets.rb +1 -1
- data/lib/sinatra/url_for.rb +1 -7
- data/public/images/bread-bg.png +0 -0
- data/public/images/logo-wide.png +0 -0
- data/public/images/topbar-bg.png +0 -0
- data/public/javascripts/application.js +5 -0
- data/public/javascripts/cmwgapp.js +249 -0
- data/public/javascripts/jquery-1.4.2.min.js +154 -0
- data/public/javascripts/jquery.mobile-1.0rc1.min.js +170 -0
- data/public/stylesheets/images/icons-18-black.png +0 -0
- data/public/stylesheets/images/icons-18-white.png +0 -0
- data/public/stylesheets/images/icons-36-black.png +0 -0
- data/public/stylesheets/images/icons-36-white.png +0 -0
- data/public/stylesheets/jquery.mobile-1.0rc1.min.css +12 -0
- data/public/stylesheets/new.css +4 -0
- data/support/fedora/deltacloud-core.init +20 -13
- data/tests/cimi/features/step_definitions/common_steps.rb +59 -0
- data/tests/cimi/features/step_definitions/machine_images_steps.rb +0 -0
- data/tests/cimi/features/step_definitions/machines_steps.rb +99 -0
- data/tests/cimi/features/step_definitions/volumes_steps.rb +115 -0
- data/tests/cimi/features/support/env.rb +53 -0
- data/tests/common.rb +89 -11
- data/tests/core_ext/string.rb +31 -0
- data/tests/drivers/google/api_test.rb +35 -0
- data/tests/drivers/google/buckets_test.rb +116 -0
- data/tests/drivers/google/setup.rb +38 -0
- data/tests/drivers/mock/instances_test.rb +20 -5
- data/tests/drivers/openstack/api_test.rb +41 -0
- data/tests/drivers/openstack/hardware_profiles_test.rb +53 -0
- data/tests/drivers/openstack/images_test.rb +40 -0
- data/tests/drivers/openstack/instances_test.rb +163 -0
- data/tests/drivers/openstack/realms_test.rb +36 -0
- data/tests/drivers/openstack/setup.rb +20 -0
- data/tests/drivers/rackspace/buckets_test.rb +145 -0
- data/tests/drivers/rackspace/setup.rb +3 -3
- data/tests/drivers/rhevm/api_test.rb +1 -1
- data/tests/drivers/rhevm/images_test.rb +2 -2
- data/tests/drivers/rhevm/instances_test.rb +10 -12
- data/tests/drivers/rhevm/realms_test.rb +4 -4
- data/tests/drivers/rhevm/setup.rb +3 -3
- data/tests/rabbit_test.rb +1 -1
- data/views/api/show.html.haml +13 -0
- data/views/cimi/cloudEntryPoint/index.html.haml +5 -0
- data/views/cimi/cloudEntryPoint/index.xml.haml +9 -0
- data/views/cimi/collection/index.html.haml +45 -0
- data/views/cimi/collection/response.xml.haml +3 -0
- data/views/cimi/error.html.haml +31 -0
- data/views/cimi/errors/400.html.haml +41 -0
- data/views/cimi/errors/400.xml.haml +3 -0
- data/views/cimi/errors/401.html.haml +41 -0
- data/views/cimi/errors/401.xml.haml +2 -0
- data/views/cimi/errors/403.html.haml +42 -0
- data/views/cimi/errors/403.xml.haml +2 -0
- data/views/cimi/errors/404.html.haml +29 -0
- data/views/cimi/errors/404.xml.haml +2 -0
- data/views/cimi/errors/405.html.haml +29 -0
- data/views/cimi/errors/405.xml.haml +5 -0
- data/views/cimi/errors/500.html.haml +43 -0
- data/views/cimi/errors/500.xml.haml +6 -0
- data/views/cimi/errors/502.html.haml +43 -0
- data/views/cimi/errors/502.xml.haml +7 -0
- data/views/cimi/errors/backend_capability_failure.html.haml +29 -0
- data/views/cimi/layout.html.haml +32 -0
- data/views/cimi/machine_configurations/show.html.haml +159 -0
- data/views/cimi/machine_configurations/show.xml.haml +27 -0
- data/views/cimi/machine_images/show.html.haml +79 -0
- data/views/cimi/machine_images/show.xml.haml +17 -0
- data/views/cimi/machines/show.html.haml +177 -0
- data/views/cimi/machines/show.xml.haml +28 -0
- data/views/cimi/volumes/show.html.haml +68 -0
- data/views/cimi/volumes/show.xml.haml +17 -0
- data/views/drivers/show.html.haml +10 -5
- data/views/drivers/show.xml.haml +9 -4
- data/views/error.html.haml +2 -2
- data/views/errors/500.xml.haml +7 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/new.html.haml +19 -16
- data/views/instances/show.html.haml +7 -2
- data/views/instances/show.xml.haml +8 -7
- data/views/layout.html.haml +2 -2
- data/views/storage_volumes/show.html.haml +1 -1
- metadata +296 -204
- data/public/javascripts/jquery.mobile-1.0b1.min.js +0 -146
- data/public/stylesheets/jquery.mobile-1.0b1.min.css +0 -8
@@ -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
|
+
class CIMI::Model::MachineImage < CIMI::Model::Base
|
17
|
+
|
18
|
+
href :image_location
|
19
|
+
text :image_data
|
20
|
+
|
21
|
+
array :operations do
|
22
|
+
scalar :rel, :href
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find(id, context)
|
26
|
+
images = []
|
27
|
+
if id == :all
|
28
|
+
images = context.driver.images(context.credentials)
|
29
|
+
images.map { |image| from_image(image, context) }
|
30
|
+
else
|
31
|
+
image = context.driver.image(context.credentials, :id => id)
|
32
|
+
from_image(image, context)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.from_image(image, context)
|
37
|
+
self.new(
|
38
|
+
:name => image.id,
|
39
|
+
:uri => context.machine_image_url(image.id),
|
40
|
+
:description => image.description,
|
41
|
+
:created => Time.now.to_s,
|
42
|
+
:image_location => { :href => "#{context.driver.name}://#{image.id}" } # FIXME
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class CIMI::Model::MachineImageCollection < CIMI::Model::Base
|
17
|
+
|
18
|
+
act_as_root_entity :machine_image
|
19
|
+
|
20
|
+
array :machine_images do
|
21
|
+
scalar :href
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default(context)
|
25
|
+
self.new(
|
26
|
+
:uri => context.machine_images_url,
|
27
|
+
:name => 'default',
|
28
|
+
:created => Time.now,
|
29
|
+
:description => "#{context.driver.name.capitalize} MachineImageCollection",
|
30
|
+
:machine_images => MachineImage.all_uri(context)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
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
|
+
class CIMI::Model::MachineTemplate < CIMI::Model::Base
|
17
|
+
|
18
|
+
href :machine_config
|
19
|
+
href :machine_image
|
20
|
+
href :machine_admin
|
21
|
+
|
22
|
+
array :volumes do
|
23
|
+
scalar :href
|
24
|
+
scalar :protocol
|
25
|
+
scalar :attachment_point
|
26
|
+
end
|
27
|
+
|
28
|
+
array :volume_templates do
|
29
|
+
scalar :href, :attachment_point, :protocol
|
30
|
+
end
|
31
|
+
|
32
|
+
array :network_interfaces do
|
33
|
+
href :vsp
|
34
|
+
text :hostname, :mac_address, :state, :protocol, :allocation
|
35
|
+
text :address, :default_gateway, :dns, :max_transmission_unit
|
36
|
+
end
|
37
|
+
|
38
|
+
array :operations do
|
39
|
+
scalar :rel, :href
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class CIMI::Model::MachineTemplateCollection < CIMI::Model::Base
|
17
|
+
|
18
|
+
act_as_root_entity :machine_template
|
19
|
+
|
20
|
+
array :machine_templates do
|
21
|
+
scalar :href
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default(context)
|
25
|
+
self.new(
|
26
|
+
:uri => context.machine_template_url,
|
27
|
+
:name => 'default',
|
28
|
+
:created => Time.now,
|
29
|
+
:description => "#{context.driver.name.capitalize} MachineTemplateCollection",
|
30
|
+
:machine_templates => MachineTemplate.all_uri(context)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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
|
+
class CIMI::Model::Network < CIMI::Model::Base
|
17
|
+
|
18
|
+
text :state
|
19
|
+
|
20
|
+
text :access
|
21
|
+
|
22
|
+
text :bandwidth_limit
|
23
|
+
|
24
|
+
text :traffic_priority
|
25
|
+
|
26
|
+
text :max_traffic_delay
|
27
|
+
|
28
|
+
text :max_traffic_loss
|
29
|
+
|
30
|
+
text :max_traffic_jitter
|
31
|
+
|
32
|
+
href :routing_group
|
33
|
+
|
34
|
+
href :event_log
|
35
|
+
|
36
|
+
array :meters do
|
37
|
+
scalar :href
|
38
|
+
end
|
39
|
+
|
40
|
+
array :operations do
|
41
|
+
scalar :rel, :href
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.find(id, context)
|
45
|
+
networks=[]
|
46
|
+
if id==:all
|
47
|
+
networks = context.driver.networks(context.credentials, {:env=>context})
|
48
|
+
else
|
49
|
+
networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
|
50
|
+
end
|
51
|
+
networks
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.create_from_xml(request_body, context)
|
55
|
+
#FIXME
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.create_from_json(request_body,context)
|
59
|
+
#FIXME
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.delete!(id, context)
|
63
|
+
#FIXME
|
64
|
+
end
|
65
|
+
|
66
|
+
#FIXME
|
67
|
+
#actions - needs method(s) to facilitate stop/start/suspend/delete
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class CIMI::Model::NetworkCollection < CIMI::Model::Base
|
17
|
+
|
18
|
+
act_as_root_entity :network
|
19
|
+
|
20
|
+
array :networks do
|
21
|
+
scalar :href
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default(context)
|
25
|
+
self.new(
|
26
|
+
:uri => context.networks_url,
|
27
|
+
:name => 'default',
|
28
|
+
:created => Time.now,
|
29
|
+
:description => "#{context.driver.name.capitalize} NetworkCollection",
|
30
|
+
:networks => Network.all(context).map { |c| { :href => c.uri } }
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
class CIMI::Model::NetworkConfiguration < CIMI::Model::Base
|
17
|
+
|
18
|
+
text :access
|
19
|
+
|
20
|
+
text :bandwidth_limit
|
21
|
+
|
22
|
+
text :traffic_priority
|
23
|
+
|
24
|
+
text :max_traffic_delay
|
25
|
+
|
26
|
+
text :max_traffic_loss
|
27
|
+
|
28
|
+
text :max_traffic_jitter
|
29
|
+
|
30
|
+
array :operations do
|
31
|
+
scalar :rel, :href
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.find(id, context)
|
35
|
+
network_configs = []
|
36
|
+
if id==:all
|
37
|
+
|
38
|
+
else
|
39
|
+
|
40
|
+
end
|
41
|
+
network_configs
|
42
|
+
end
|
43
|
+
require 'cimi/model/network_configuration_collection'
|
44
|
+
def self.create_from_xml(request_body, context)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.create_from_json(request_body, context)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class CIMI::Model::NetworkConfigurationCollection < CIMI::Model::Base
|
17
|
+
|
18
|
+
act_as_root_entity :network_configuration
|
19
|
+
|
20
|
+
array :network_configurations do
|
21
|
+
scalar :href
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default(context)
|
25
|
+
self.new(
|
26
|
+
:uri => context.network_configurations_url,
|
27
|
+
:name => 'default',
|
28
|
+
:created => Time.now,
|
29
|
+
:description => "#{context.driver.name.capitalize} NetworkConfigurationCollection",
|
30
|
+
:network_configurations => NetworkConfiguration.all(context).map { |c| { :href => c.uri } }
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
class CIMI::Model::NetworkTemplate < CIMI::Model::Base
|
17
|
+
|
18
|
+
href :network_config
|
19
|
+
|
20
|
+
href :routing_group
|
21
|
+
|
22
|
+
array :operations do
|
23
|
+
scalar :rel, :href
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,277 @@
|
|
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
|
+
# The smarts of converting from XML and JSON into internal objects
|
18
|
+
class CIMI::Model::Schema
|
19
|
+
|
20
|
+
#
|
21
|
+
# Attributes describe how we extract values from XML/JSON
|
22
|
+
#
|
23
|
+
class Attribute
|
24
|
+
attr_reader :name, :xml_name, :json_name
|
25
|
+
|
26
|
+
def initialize(name, opts = {})
|
27
|
+
@name = name
|
28
|
+
@xml_name = (opts[:xml_name] || name).to_s.camelize(true)
|
29
|
+
@json_name = (opts[:json_name] || name).to_s.camelize(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def from_xml(xml, model)
|
33
|
+
model[@name] = xml[@xml_name].first if xml.has_key?(@xml_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_json(json, model)
|
37
|
+
model[@name] = json[@json_name]
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_xml(model, xml)
|
41
|
+
xml[@xml_name] = [model[@name]] if model[@name]
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_json(model, json)
|
45
|
+
json[@json_name] = model[@name] if model and model[@name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Scalar < Attribute
|
50
|
+
def initialize(name, opts)
|
51
|
+
@text = opts[:text]
|
52
|
+
if ! [nil, :nested, :direct].include?(@text)
|
53
|
+
raise "text option for scalar must be :nested or :direct"
|
54
|
+
end
|
55
|
+
super(name, opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def text?; @text; end
|
59
|
+
|
60
|
+
def nested_text?; @text == :nested; end
|
61
|
+
|
62
|
+
def from_xml(xml, model)
|
63
|
+
case @text
|
64
|
+
when :nested then model[@name] = xml[@xml_name].first["content"] if xml[@xml_name]
|
65
|
+
when :direct then model[@name] = xml["content"]
|
66
|
+
else model[@name] = xml[@xml_name]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_xml(model, xml)
|
71
|
+
return unless model
|
72
|
+
return unless model[@name]
|
73
|
+
case @text
|
74
|
+
when :nested then xml[@xml_name] = [{ "content" => model[@name] }]
|
75
|
+
when :direct then xml["content"] = model[@name]
|
76
|
+
else xml[@xml_name] = model[@name]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Struct < Attribute
|
82
|
+
def initialize(name, opts, &block)
|
83
|
+
content = opts[:content]
|
84
|
+
super(name, opts)
|
85
|
+
@schema = CIMI::Model::Schema.new
|
86
|
+
@schema.instance_eval(&block) if block_given?
|
87
|
+
@schema.scalar(content, :text => :direct) if content
|
88
|
+
end
|
89
|
+
|
90
|
+
def from_xml(xml, model)
|
91
|
+
xml = xml.has_key?(xml_name) ? xml[xml_name].first : {}
|
92
|
+
model[name] = convert_from_xml(xml)
|
93
|
+
end
|
94
|
+
|
95
|
+
def from_json(json, model)
|
96
|
+
json = json.has_key?(json_name) ? json[json_name] : {}
|
97
|
+
model[name] = convert_from_json(json)
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_xml(model, xml)
|
101
|
+
conv = convert_to_xml(model[name])
|
102
|
+
xml[xml_name] = [conv] unless conv.empty?
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_json(model, json)
|
106
|
+
conv = convert_to_json(model[name])
|
107
|
+
json[json_name] = conv unless conv.empty?
|
108
|
+
end
|
109
|
+
|
110
|
+
def convert_from_xml(xml)
|
111
|
+
sub = struct.new
|
112
|
+
@schema.from_xml(xml, sub)
|
113
|
+
sub
|
114
|
+
end
|
115
|
+
|
116
|
+
def convert_from_json(json)
|
117
|
+
sub = struct.new
|
118
|
+
@schema.from_json(json, sub)
|
119
|
+
sub
|
120
|
+
end
|
121
|
+
|
122
|
+
def convert_to_xml(model)
|
123
|
+
xml = {}
|
124
|
+
@schema.to_xml(model, xml)
|
125
|
+
xml
|
126
|
+
end
|
127
|
+
|
128
|
+
def convert_to_json(model)
|
129
|
+
json = {}
|
130
|
+
@schema.to_json(model, json)
|
131
|
+
json
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
def struct
|
136
|
+
cname = "CIMI_#{json_name.upcase_first}"
|
137
|
+
if ::Struct.const_defined?(cname)
|
138
|
+
::Struct.const_get(cname)
|
139
|
+
else
|
140
|
+
::Struct.new("CIMI_#{json_name.upcase_first}",
|
141
|
+
*@schema.attribute_names)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Array < Attribute
|
147
|
+
# For an array :things, we collect all <thing/> elements (XmlSimple
|
148
|
+
# actually does the collecting)
|
149
|
+
def initialize(name, opts = {}, &block)
|
150
|
+
opts[:xml_name] = name.to_s.singularize unless opts[:xml_name]
|
151
|
+
super(name, opts)
|
152
|
+
@struct = Struct.new(name, opts, &block)
|
153
|
+
end
|
154
|
+
|
155
|
+
def from_xml(xml, model)
|
156
|
+
model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
|
157
|
+
end
|
158
|
+
|
159
|
+
def from_json(json, model)
|
160
|
+
model[name] = (json[json_name] || []).map { |elt| @struct.convert_from_json(elt) }
|
161
|
+
end
|
162
|
+
|
163
|
+
def to_xml(model, xml)
|
164
|
+
ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
|
165
|
+
xml[xml_name] = ary unless ary.empty?
|
166
|
+
end
|
167
|
+
|
168
|
+
def to_json(model, json)
|
169
|
+
ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
|
170
|
+
json[json_name] = ary unless ary.empty?
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class Hash < Attribute
|
175
|
+
|
176
|
+
def initialize(name, opts = {}, &block)
|
177
|
+
opts[:json_name] = name.to_s.pluralize unless opts[:json_name]
|
178
|
+
super(name, opts)
|
179
|
+
@struct = Struct.new(name, opts, &block)
|
180
|
+
end
|
181
|
+
|
182
|
+
def from_xml(xml, model)
|
183
|
+
model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
|
184
|
+
end
|
185
|
+
|
186
|
+
def from_json(json, model)
|
187
|
+
model[name] = (json[json_name] || {}).inject([]) do |result,item|
|
188
|
+
result << @struct.convert_from_json({ 'name' => item[0], 'value' => item[1] })
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def to_xml(model, xml)
|
193
|
+
ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
|
194
|
+
xml[xml_name] = ary unless ary.empty?
|
195
|
+
end
|
196
|
+
|
197
|
+
def to_json(model, json)
|
198
|
+
ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
|
199
|
+
json[json_name] = ary.inject({}) { |result, item| result[item['name']] = item['value']; result } unless ary.empty?
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# The actual Schema class
|
205
|
+
#
|
206
|
+
def initialize
|
207
|
+
@attributes = []
|
208
|
+
end
|
209
|
+
|
210
|
+
def from_xml(xml, model = {})
|
211
|
+
@attributes.freeze
|
212
|
+
@attributes.each { |attr| attr.from_xml(xml, model) }
|
213
|
+
model
|
214
|
+
end
|
215
|
+
|
216
|
+
def from_json(json, model = {})
|
217
|
+
@attributes.freeze
|
218
|
+
@attributes.each { |attr| attr.from_json(json, model) }
|
219
|
+
model
|
220
|
+
end
|
221
|
+
|
222
|
+
def to_xml(model, xml = {})
|
223
|
+
@attributes.freeze
|
224
|
+
@attributes.each { |attr| attr.to_xml(model, xml) }
|
225
|
+
xml
|
226
|
+
end
|
227
|
+
|
228
|
+
def to_json(model, json = {})
|
229
|
+
@attributes.freeze
|
230
|
+
@attributes.each { |attr| attr.to_json(model, json) }
|
231
|
+
json
|
232
|
+
end
|
233
|
+
|
234
|
+
def attribute_names
|
235
|
+
@attributes.map { |a| a.name }
|
236
|
+
end
|
237
|
+
|
238
|
+
#
|
239
|
+
# The DSL
|
240
|
+
#
|
241
|
+
# Requires that the class into which this is included has a
|
242
|
+
# +add_attributes!+ method
|
243
|
+
module DSL
|
244
|
+
def href(*args)
|
245
|
+
args.each { |arg| struct(arg) { scalar :href } }
|
246
|
+
end
|
247
|
+
|
248
|
+
def text(*args)
|
249
|
+
args.expand_opts!(:text => :nested)
|
250
|
+
scalar(*args)
|
251
|
+
end
|
252
|
+
|
253
|
+
def scalar(*args)
|
254
|
+
add_attributes!(args, Scalar)
|
255
|
+
end
|
256
|
+
|
257
|
+
def array(name, opts={}, &block)
|
258
|
+
add_attributes!([name, opts], Array, &block)
|
259
|
+
end
|
260
|
+
|
261
|
+
def struct(name, opts={}, &block)
|
262
|
+
add_attributes!([name, opts], Struct, &block)
|
263
|
+
end
|
264
|
+
|
265
|
+
def hash(name, opts={}, &block)
|
266
|
+
add_attributes!([name, opts], Hash, &block)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
include DSL
|
271
|
+
|
272
|
+
def add_attributes!(args, attr_klass, &block)
|
273
|
+
raise "The schema has already been used to convert objects" if @attributes.frozen?
|
274
|
+
opts = args.extract_opts!
|
275
|
+
args.each { |arg| @attributes << attr_klass.new(arg, opts, &block) }
|
276
|
+
end
|
277
|
+
end
|