1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Merge remote-tracking branch 'remotes/github-hector/feature-789' into feature-789

This commit is contained in:
Ruben S. Montero 2011-10-11 16:27:15 +02:00
commit 0d66f1e53f
13 changed files with 473 additions and 17 deletions

View File

@ -198,6 +198,7 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
LIB_DIRS="$LIB_LOCATION/ruby \
$LIB_LOCATION/ruby/OpenNebula \
$LIB_LOCATION/ruby/zona \
$LIB_LOCATION/ruby/cloud/ \
$LIB_LOCATION/ruby/cloud/econe \
$LIB_LOCATION/ruby/cloud/econe/views \
@ -272,7 +273,8 @@ OZONES_DIRS="$OZONES_LOCATION/lib \
OZONES_CLIENT_DIRS="$LIB_LOCATION/ruby \
$LIB_LOCATION/ruby/OpenNebula \
$LIB_LOCATION/ruby/cli \
$LIB_LOCATION/ruby/cli/ozones_helper"
$LIB_LOCATION/ruby/cli/ozones_helper \
$LIB_LOCATION/ruby/zona"
LIB_ECO_CLIENT_DIRS="$LIB_LOCATION/ruby \
$LIB_LOCATION/ruby/OpenNebula \
@ -374,6 +376,8 @@ INSTALL_CLIENT_FILES=(
OZONES_BIN_CLIENT_FILES:$BIN_LOCATION
OZONES_LIB_CLIENT_CLI_FILES:$LIB_LOCATION/ruby/cli
OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper
OZONES_LIB_API_FILES:$LIB_LOCATION/ruby
OZONES_LIB_API_ZONA_FILES:$LIB_LOCATION/ruby/zona
CLI_CONF_FILES:$ETC_LOCATION/cli
OCA_LIB_FILES:$LIB_LOCATION/ruby
RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula
@ -432,6 +436,8 @@ INSTALL_OZONES_FILES=(
OZONES_BIN_CLIENT_FILES:$BIN_LOCATION
OZONES_LIB_CLIENT_CLI_FILES:$LIB_LOCATION/ruby/cli
OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper
OZONES_LIB_API_FILES:$LIB_LOCATION/ruby
OZONES_LIB_API_ZONA_FILES:$LIB_LOCATION/ruby/zona
)
INSTALL_OZONES_ETC_FILES=(
@ -1055,6 +1061,16 @@ OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \
src/ozones/Server/lib/OZones/AggregatedImages.rb \
src/ozones/Server/lib/OZones/AggregatedTemplates.rb"
OZONES_LIB_API_FILES="src/ozones/Client/lib/api/zona.rb"
OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/api/zona/ZoneElement.rb \
src/ozones/Client/lib/api/zona/OZonesPool.rb \
src/ozones/Client/lib/api/zona/OZonesJSON.rb \
src/ozones/Client/lib/api/zona/VDCPool.rb \
src/ozones/Client/lib/api/zona/VDCElement.rb \
src/ozones/Client/lib/api/zona/OZonesElement.rb \
src/ozones/Client/lib/api/zona/ZonePool.rb"
OZONES_PUBLIC_VENDOR_JQUERY=$SUNSTONE_PUBLIC_VENDOR_JQUERY
OZONES_PUBLIC_VENDOR_DATATABLES=$SUNSTONE_PUBLIC_VENDOR_DATATABLES

View File

@ -64,7 +64,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
command :delhost, 'Deletes the set of hosts from the VDC',
:vdcid, :range, :options=>[FORCE] do
:vdcid, :range do
helper.delhost(args[0], args[1], options)
end
end

View File

@ -90,18 +90,21 @@ EOT
# Post a new Resource to the relevant OZones Pool
# :zonetemplate
######################################################################
def post_resource(kind, template)
def post_resource_file(kind, template)
tmpl_str = File.read(template)
post_resource_str(kind, tmpl_str)
end
def post_resource_str(kind, tmpl_str)
body_str = OZonesClient::to_body(kind, tmpl_str)
tmpl_json = OZonesClient::tobody(tmpl_str)
post_resource(kind, tmpl_json)
end
def post_resource(kind, tmpl_json)
url = URI.parse("#{@endpoint}/#{kind}")
req = Net::HTTP::Post.new(url.path)
req.body=body_str
req.body=tmpl_json
req.basic_auth @ozonesauth[0], @ozonesauth[1]
@ -112,13 +115,16 @@ EOT
return OZonesClient::parse_error(res, kind)
end
def put_resource(kind, id, tmpl_str)
body_str = OZonesClient::to_body(kind, tmpl_str)
def put_resource_str(kind, id, tmpl_str)
tmpl_json = OZonesClient::to_body(kind, tmpl_str)
put_resource(kind, id, tmpl_json)
end
def put_resource(kind, id, tmpl_json)
url = URI.parse("#{@endpoint}/#{kind}/#{id}")
req = Net::HTTP::Put.new(url.path)
req.body=body_str
req.body=tmpl_json
req.basic_auth @ozonesauth[0], @ozonesauth[1]

View File

@ -0,0 +1,33 @@
# -------------------------------------------------------------------------- #
# 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 'rubygems'
require 'OZonesClient.rb'
require 'zona/OZonesJSON'
require 'zona/OZonesPool'
require 'zona/OZonesElement'
require 'zona/ZonePool'
require 'zona/ZoneElement'
require 'zona/VDCPool'
require 'zona/VDCElement'
module Zona
end

View File

@ -0,0 +1,79 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class OZonesElement < JSONElement
protected
def initialize(hash, client)
@client = client
@json_hash = hash
@pe_id = self["id"] ? self["id"].to_i : nil
@name = self["name"] ? self["name"] : nil
end
def info(kind, root_element)
return Error.new('ID not defined') if !@pe_id
rc = @client.get_resource(kind,@pe_id)
if !OZonesClient.is_error?(rc)
initialize_json(rc.body,root_element)
rc = nil
@pe_id = self["id"] ? self["id"].to_i : nil
@name = self["name"] ? self["name"] : nil
end
rc
end
def allocate_hash(kind, tmpl_hash)
allocate(kind, tmpl_hash.to_json)
end
def allocate(kind, tmpl_json)
rc = @client.post_resource(kind, tmpl_json)
if !OZonesClient.is_error?(rc)
initialize_json(rc.body,kind.upcase)
@pe_id = self["id"].to_i
rc = nil
end
rc
end
def delete(kind)
return Error.new('ID not defined') if !@pe_id
rc = @client.delete_resource(kind,@pe_id)
return rc if OZonesClient.is_error?(rc)
nil
end
public
attr_reader :pe_id, :name
def self.new_with_id(id, client=nil)
self.new(self.build_json(id),client)
end
end
end

View File

@ -0,0 +1,63 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
require 'json'
class JSONElement
def initialize(json_hash=nil)
@json_hash=json_hash
end
def initialize_json(json_str, root_element)
rc = JSONElement.build_json(json_str,root_element)
@json_hash = rc
if OZonesClient.is_error?(rc) || (rc.size == 0)
@json_hash=nil
end
end
def self.build_json(json_str, root_element)
begin
parser = JSON.parser.new(json_str, {:symbolize_names => false})
hash = parser.parse
hash[root_element]
rescue => e
OZonesClient::Error.new(e.message)
end
end
def [](key)
@json_hash[key]
end
end
class JSONPool < JSONElement
def initialize(json_hash=nil)
super(json_hash)
end
def each_element(block)
@json_hash[@element_name].each do |elem|
block.call self.factory(elem)
end
end
end
end

View File

@ -0,0 +1,54 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class OZonesPool < JSONPool
protected
def initialize(pool,element,client)
super(nil)
@client = client
@pool_name = pool.upcase
@element_name = element.upcase
end
def factory(element_json)
Zona::OZonesPoolElement.new(element_json, @client)
end
def info(kind)
rc = @client.get_pool(kind)
if !OZonesClient.is_error?(rc)
initialize_json(rc.body,@pool_name)
rc=nil
end
rc
end
public
def each(&block)
each_element(block) if @json_hash
end
end
end

View File

@ -0,0 +1,87 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class VDC < OZonesElement
VDC_KIND = "vdc"
def self.build_json(pe_id=nil)
if pe_id
json = "{\"VDC\":{\"id\":#{pe_id}}}"
else
json = '{"VDC":{}}'
end
JSONElement.build_json(json,"VDC")
end
def initialize(hash, client)
super(hash, client)
end
def info
super(VDC_KIND,"VDC")
end
def allocate_hash(template)
super(VDC_KIND,template)
end
def allocate(template)
super(VDC_KIND,template)
end
def delete
super(VDC_KIND)
end
def addhosts(hosts_array,options={})
return Error.new('VDC not info-ed') if !@json_hash
# array of hosts, integers
hosts = self["hosts"].split(',').collect!{|x| x.to_i}
hosts.concat(hosts_array).uniq!
new_hosts = hosts.join(',')
template = {:id => @pe_id, :hosts => new_hosts}
template[:force] = "yes" if options[:force]
template = {:vdc => template}
rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
return rc if OZonesClient.is_error?(rc)
nil
end
def delhosts(hosts_array)
return Error.new('VDC not info-ed') if !@json_hash
hosts = self["hosts"].split(',').collect!{|x| x.to_i}
new_hosts = (hosts - hosts_array).join(',')
template = {:vdc => {:id => @pe_id, :hosts => new_hosts}}
rc = @client.put_resource(VDC_KIND,@pe_id,template.to_json)
return rc if OZonesClient.is_error?(rc)
nil
end
alias :addhost :addhosts
alias :delhost :delhosts
end
end

View File

@ -0,0 +1,34 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class VDCPool < OZonesPool
VDC_POOL_KIND="vdc"
def initialize(client)
super("VDC_POOL", "VDC", client)
end
def factory(element_json)
Zona::VDC.new(element_json,@client)
end
def info
super(VDC_POOL_KIND)
end
end
end

View File

@ -0,0 +1,52 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class Zone < OZonesElement
ZONE_KIND = "zone"
def self.build_json(pe_id=nil)
if pe_id
json = "{\"ZONE\":{\"id\":#{pe_id}}}"
else
json = '{"ZONE":{}}'
end
JSONElement.build_json(json,"ZONE")
end
def initialize(hash, client)
super(hash, client)
end
def info
super(ZONE_KIND,"ZONE")
end
def allocate_hash(template)
super(ZONE_KIND,template)
end
def allocate(template)
super(ZONE_KIND,template)
end
def delete
super(ZONE_KIND)
end
end
end

View File

@ -0,0 +1,36 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
module Zona
class ZonePool < OZonesPool
ZONE_POOL_KIND = "zone"
def initialize(client)
super("ZONE_POOL", "ZONE", client)
end
def factory(element_json)
Zona::Zone.new(element_json,@client)
end
def info
super(ZONE_POOL_KIND)
end
end
end

View File

@ -29,7 +29,7 @@ module OZonesHelper
end
def create_resource(kind, template)
rc = @client.post_resource(kind, template)
rc = @client.post_resource_file(kind, template)
if OZonesClient::is_error?(rc)
[-1, rc.message]

View File

@ -72,7 +72,7 @@ class VDCHelper < OZonesHelper::OZHelper
template << "FORCE=YES\n"
end
rc = @client.put_resource(@vdc_str, id, template)
rc = @client.put_resource_str(@vdc_str, id, template)
if OZonesClient::is_error?(rc)
return [-1, rc.message]
@ -95,11 +95,7 @@ class VDCHelper < OZonesHelper::OZHelper
new_host = (hosts - host_array).join(',')
template = "ID=#{id}\nHOSTS=#{new_host}\n"
if options[:force]
template << "FORCE=YES\n"
end
rc = @client.put_resource(@vdc_str, id, template)
rc = @client.put_resource_str(@vdc_str, id, template)
if OZonesClient::is_error?(rc)
return [-1, rc.message]