Files
one/src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb
T
2014-03-04 12:53:44 +01:00

60 lines
2.4 KiB
Ruby

# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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 ZoneJSON < OpenNebula::Zone
include JSONUtils
def create(template_json)
zone_hash = parse_json(template_json, 'zone')
if OpenNebula.is_error?(zone_hash)
return zone_hash
end
template = template_to_str(zone_hash)
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 "update" then self.update(action_hash['params'])
when "rename" then self.rename(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['template_raw'])
end
def rename(params=Hash.new)
super(params['name'])
end
end
end