1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-24 02:03:52 +03:00

feature #4217: Add Marketplace and MarketplaceApp JSON resources and pools

This commit is contained in:
Daniel Molina 2016-02-03 16:53:01 +01:00
parent 1428a84fbb
commit a097e183b2
6 changed files with 134 additions and 43 deletions

View File

@ -1664,7 +1664,9 @@ SUNSTONE_MODELS_JSON_FILES="src/sunstone/models/OpenNebulaJSON/HostJSON.rb \
src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb \
src/sunstone/models/OpenNebulaJSON/SecurityGroupJSON.rb \
src/sunstone/models/OpenNebulaJSON/VdcJSON.rb \
src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb"
src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb \
src/sunstone/models/OpenNebulaJSON/MarketPlaceJSON.rb \
src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb"
SUNSTONE_VIEWS_FILES="src/sunstone/views/index.erb \
src/sunstone/views/login.erb \

View File

@ -33,6 +33,8 @@ require 'OpenNebulaJSON/ZoneJSON'
require 'OpenNebulaJSON/SecurityGroupJSON'
require 'OpenNebulaJSON/VdcJSON'
require 'OpenNebulaJSON/VirtualRouterJSON'
require 'OpenNebulaJSON/MarketPlaceJSON'
require 'OpenNebulaJSON/MarketPlaceAppJSON'
module OpenNebula
class Error

View File

@ -0,0 +1,79 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# 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 MarketPlaceAppJSON < OpenNebula::MarketPlaceApp
include JSONUtils
def create(template_json)
mp_hash = parse_json(template_json, 'marketplaceapp')
if OpenNebula.is_error?(mp_hash)
return mp_hash
end
mp_id = parse_json(template_json, 'mp_id')
if OpenNebula.is_error?(mp_id)
return mp_id
end
if mp_hash['marketplaceapp_raw']
template = mp_hash['marketplaceapp_raw']
else
template = template_to_str(mp_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 "update" then self.update(action_hash['params'])
when "chown" then self.chown(action_hash['params'])
when "chmod" then self.chmod_octet(action_hash['params'])
when "rename" then self.rename(action_hash['params'])
when "disable" then self.disable
when "enable" then self.enable
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 chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
def chmod_octet(params=Hash.new)
super(params['octet'])
end
def rename(params=Hash.new)
super(params['name'])
end
end
end

View File

@ -26,10 +26,10 @@ module OpenNebulaJSON
return mp_hash
end
if ds_hash['marketplace_raw']
template = ds_hash['marketplace_raw']
if mp_hash['marketplace_raw']
template = mp_hash['marketplace_raw']
else
template = template_to_str(ds_hash)
template = template_to_str(mp_hash)
end
self.allocate(template)

View File

@ -31,4 +31,6 @@ module OpenNebulaJSON
class SecurityGroupPoolJSON < OpenNebula::SecurityGroupPool; include JSONUtils; end
class VdcPoolJSON < OpenNebula::VdcPool; include JSONUtils; end
class VirtualRouterPoolJSON < OpenNebula::VirtualRouterPool; include JSONUtils; end
class MarketPlacePoolJSON < OpenNebula::MarketPlacePool; include JSONUtils; end
class MarketpPlaceAppPoolJSON < OpenNebula::MarketPlaceAppPool; include JSONUtils; end
end

View File

@ -48,20 +48,22 @@ class SunstoneServer < CloudServer
end
pool = case kind
when "group" then GroupPoolJSON.new(client)
when "cluster" then ClusterPoolJSON.new(client)
when "host" then HostPoolJSON.new(client)
when "image" then ImagePoolJSON.new(client, user_flag)
when "vmtemplate" 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)
when "acl" then AclPoolJSON.new(client)
when "datastore" then DatastorePoolJSON.new(client)
when "zone" then ZonePoolJSON.new(client)
when "group" then GroupPoolJSON.new(client)
when "cluster" then ClusterPoolJSON.new(client)
when "host" then HostPoolJSON.new(client)
when "image" then ImagePoolJSON.new(client, user_flag)
when "vmtemplate" 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)
when "acl" then AclPoolJSON.new(client)
when "datastore" then DatastorePoolJSON.new(client)
when "zone" then ZonePoolJSON.new(client)
when "security_group" then SecurityGroupPoolJSON.new(client, user_flag)
when "vdc" then VdcPoolJSON.new(client)
when "vrouter" then VirtualRouterPoolJSON.new(client, user_flag)
when "vdc" then VdcPoolJSON.new(client)
when "vrouter" then VirtualRouterPoolJSON.new(client, user_flag)
when "marketplace" then MarketPlacePoolJSON.new(client, user_flag)
when "marketplaceapp" then MarketPlaceAppPoolJSON.new(client, user_flag)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -106,20 +108,22 @@ class SunstoneServer < CloudServer
############################################################################
def create_resource(kind, template)
resource = case kind
when "group" then GroupJSON.new(Group.build_xml, @client)
when "cluster" then ClusterJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "vmtemplate" 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)
when "acl" then AclJSON.new(Acl.build_xml, @client)
when "datastore" then DatastoreJSON.new(Datastore.build_xml, @client)
when "zone" then ZoneJSON.new(Zone.build_xml, @client)
when "group" then GroupJSON.new(Group.build_xml, @client)
when "cluster" then ClusterJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "vmtemplate" 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)
when "acl" then AclJSON.new(Acl.build_xml, @client)
when "datastore" then DatastoreJSON.new(Datastore.build_xml, @client)
when "zone" then ZoneJSON.new(Zone.build_xml, @client)
when "security_group" then SecurityGroupJSON.new(SecurityGroup.build_xml, @client)
when "vdc" then VdcJSON.new(Vdc.build_xml, @client)
when "vrouter" then VirtualRouterJSON.new(VirtualRouter.build_xml, @client)
when "vdc" then VdcJSON.new(Vdc.build_xml, @client)
when "vrouter" then VirtualRouterJSON.new(VirtualRouter.build_xml, @client)
when "marketplace" then MarketPlaceJSON.new(MarketPlace.build_xml, @client)
when "marketplaceapp" then MarketPlaceAppJSON.new(MarketPlaceApp.build_xml, @client)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -428,20 +432,22 @@ class SunstoneServer < CloudServer
############################################################################
def retrieve_resource(kind, id, extended=false)
resource = case kind
when "group" then GroupJSON.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 "vmtemplate" 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)
when "acl" then AclJSON.new_with_id(id, @client)
when "datastore" then DatastoreJSON.new_with_id(id, @client)
when "zone" then ZoneJSON.new_with_id(id, @client)
when "group" then GroupJSON.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 "vmtemplate" 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)
when "acl" then AclJSON.new_with_id(id, @client)
when "datastore" then DatastoreJSON.new_with_id(id, @client)
when "zone" then ZoneJSON.new_with_id(id, @client)
when "security_group" then SecurityGroupJSON.new_with_id(id, @client)
when "vdc" then VdcJSON.new_with_id(id, @client)
when "vrouter" then VirtualRouterJSON.new_with_id(id, @client)
when "vdc" then VdcJSON.new_with_id(id, @client)
when "vrouter" then VirtualRouterJSON.new_with_id(id, @client)
when "marketplace" then MarketPlaceJSON.new(id, @client)
when "marketplaceapp" then MarketPlaceAppJSON.new(id, @client)
else
error = Error.new("Error: #{kind} resource not supported")
return error