diff --git a/src/sunstone/models/OpenNebulaJSON.rb b/src/sunstone/models/OpenNebulaJSON.rb index 9fb45fac7d..cfdb0d162e 100644 --- a/src/sunstone/models/OpenNebulaJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON.rb @@ -20,6 +20,7 @@ include OpenNebula require 'OpenNebulaJSON/ClusterJSON' require 'OpenNebulaJSON/HostJSON' require 'OpenNebulaJSON/ImageJSON' +require 'OpenNebulaJSON/TemplateJSON' require 'OpenNebulaJSON/JSONUtils' require 'OpenNebulaJSON/PoolJSON' require 'OpenNebulaJSON/UserJSON' diff --git a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb index d32241c5d7..578082bdbf 100644 --- a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb @@ -21,6 +21,7 @@ module OpenNebulaJSON class VirtualMachinePoolJSON < OpenNebula::VirtualMachinePool; include JSONUtils; end class VirtualNetworkPoolJSON < OpenNebula::VirtualNetworkPool; include JSONUtils; end class ImagePoolJSON < OpenNebula::ImagePool; include JSONUtils; end + class TemplatePoolJSON < OpenNebula::ImagePool; include JSONUtils; end class ClusterPoolJSON < OpenNebula::ClusterPool; include JSONUtils; end class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end end diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb new file mode 100644 index 0000000000..9680ad2a8b --- /dev/null +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -0,0 +1,65 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require 'OpenNebulaJSON/JSONUtils' + +module OpenNebulaJSON + class TemplateJSON < OpenNebula::VirtualMachine + include JSONUtils + + def create(template_json) + template_hash = parse_json(template_json, 'template') + if OpenNebula.is_error?(template_hash) + return template_hash + end + + if template_hash['template_raw'] + template = vm_hash['template_raw'] + else + template = template_to_str(template_hash) + end + + self.allocate(template) + end + + def perform_action(template_json) + action_hash = parse_json(template_json, 'action') + if OpenNebula.is_error?(action_hash) + return action_hash + end + + rc = case action_hash['perform'] + when "publish" then self.publish + when "rm_attr" then self.remove_attr(action_hash['params']) + when "unpublish" then self.unpublish + when "update" then self.update(action_hash['params']) + else + error_msg = "#{action_hash['perform']} action not " << + " available for this resource" + OpenNebula::Error.new(error_msg) + end + + end + + def update(params=Hash.new) + super(params['name'], params['value']) + end + + def remove_attr(params=Hash.new) + super(params['name']) + end + end +end diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index ea690c33a9..c79854694d 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -68,12 +68,13 @@ class SunstoneServer def get_pool(kind) user_flag = -2 pool = case kind - when "cluster" then ClusterPoolJSON.new(@client) - when "host" then HostPoolJSON.new(@client) - when "image" then ImagePoolJSON.new(@client, user_flag) - when "vm" then VirtualMachinePoolJSON.new(@client, user_flag) - when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag) - when "user" then UserPoolJSON.new(@client) + when "cluster" then ClusterPoolJSON.new(@client) + when "host" then HostPoolJSON.new(@client) + when "image" then ImagePoolJSON.new(@client, user_flag) + when "template" then TemplatePoolJSON.new(@client, user_flag) + when "vm" then VirtualMachinePoolJSON.new(@client, user_flag) + when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag) + when "user" then UserPoolJSON.new(@client) else error = Error.new("Error: #{kind} resource not supported") return [404, error.to_json] @@ -104,12 +105,13 @@ class SunstoneServer ############################################################################ def create_resource(kind, template) resource = case kind - when "cluster" then ClusterJSON.new(Cluster.build_xml, @client) - when "host" then HostJSON.new(Host.build_xml, @client) - when "image" then ImageJSON.new(Image.build_xml, @client) - when "vm" then VirtualMachineJSON.new(VirtualMachine.build_xml,@client) - when "vnet" then VirtualNetworkJSON.new(VirtualNetwork.build_xml, @client) - when "user" then UserJSON.new(User.build_xml, @client) + when "cluster" then ClusterJSON.new(Cluster.build_xml, @client) + when "host" then HostJSON.new(Host.build_xml, @client) + when "image" then ImageJSON.new(Image.build_xml, @client) + when "template" then TemplateJSON.new(Template.build_xml, @client) + when "vm" then VirtualMachineJSON.new(VirtualMachine.build_xml,@client) + when "vnet" then VirtualNetworkJSON.new(VirtualNetwork.build_xml, @client) + when "user" then UserJSON.new(User.build_xml, @client) else error = Error.new("Error: #{kind} resource not supported") return [404, error.to_json] @@ -217,12 +219,13 @@ class SunstoneServer def retrieve_resource(kind, id) resource = case kind - when "cluster" then ClusterJSON.new_with_id(id, @client) - when "host" then HostJSON.new_with_id(id, @client) - when "image" then ImageJSON.new_with_id(id, @client) - when "vm" then VirtualMachineJSON.new_with_id(id, @client) - when "vnet" then VirtualNetworkJSON.new_with_id(id, @client) - when "user" then UserJSON.new_with_id(id, @client) + when "cluster" then ClusterJSON.new_with_id(id, @client) + when "host" then HostJSON.new_with_id(id, @client) + when "image" then ImageJSON.new_with_id(id, @client) + when "template" then TemplateJSON.new_with_id(id, @client) + when "vm" then VirtualMachineJSON.new_with_id(id, @client) + when "vnet" then VirtualNetworkJSON.new_with_id(id, @client) + when "user" then UserJSON.new_with_id(id, @client) else error = Error.new("Error: #{kind} resource not supported") return error