mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-12 09:17:41 +03:00
Feature #789: Whitespace cleanup, correct indentation in OZones ruby files
That means, no spaces at the end of lines, no tabs, 4-space indent...
This commit is contained in:
parent
a48ba32dfd
commit
d481b332bb
@ -33,14 +33,14 @@ require 'ozones_helper/vdc_helper.rb'
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onevdc` command [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
|
||||
set :format, :vdcid, "VDC ID" do |arg|
|
||||
arg.match(/^[0123456789]+$/) ? [0,arg] : [-1]
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
FORCE={
|
||||
@ -52,34 +52,34 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
begin
|
||||
helper = VDCHelper.new "vdc"
|
||||
rescue Exception => e
|
||||
rescue Exception => e
|
||||
warn e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
command :create, 'Create a new VDC', :file, :options=>[FORCE] do
|
||||
helper.create_resource(args[0], options)
|
||||
end
|
||||
|
||||
|
||||
command :show, 'Show information of a particular VDC', :vdcid do
|
||||
helper.show_resource(args[0],options)
|
||||
end
|
||||
|
||||
|
||||
command :list, 'Lists VDCs in the pool' do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
command :delete, 'Deletes a VDC', :vdcid do
|
||||
helper.delete_resource(args[0],options)
|
||||
helper.delete_resource(args[0],options)
|
||||
end
|
||||
|
||||
command :addhost, 'Adds the set of hosts to the VDC',
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
command :addhost, 'Adds the set of hosts to the VDC',
|
||||
:vdcid, :range, :options=>[FORCE] do
|
||||
helper.addhost(args[0], args[1], options)
|
||||
end
|
||||
|
||||
command :delhost, 'Deletes the set of hosts from the VDC',
|
||||
:vdcid, :range do
|
||||
:vdcid, :range do
|
||||
helper.delhost(args[0], args[1], options)
|
||||
end
|
||||
end
|
||||
|
@ -66,50 +66,50 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
zone=helper.show_resource(args[0],options)[1]
|
||||
|
||||
case args[1]
|
||||
when "host"
|
||||
aux_helper = OneHostHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
when "host"
|
||||
aux_helper = OneHostHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
when "vm"
|
||||
aux_helper = OneVMHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
aux_helper.list_pool(options)
|
||||
when "vm"
|
||||
aux_helper = OneVMHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
when "image"
|
||||
aux_helper = OneImageHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
aux_helper.list_pool(options)
|
||||
when "image"
|
||||
aux_helper = OneImageHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
when "vn"
|
||||
aux_helper = OneVNetHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
aux_helper.list_pool(options)
|
||||
when "vn"
|
||||
aux_helper = OneVNetHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper.list_pool(options)
|
||||
|
||||
when "template"
|
||||
aux_helper = OneTemplateHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
when "template"
|
||||
aux_helper = OneTemplateHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper.list_pool(options)
|
||||
|
||||
when "user"
|
||||
aux_helper = OneUserHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
when "user"
|
||||
aux_helper = OneUserHelper.new(
|
||||
zone[:ONENAME] + ":" + zone[:ONEPASS],
|
||||
zone[:ENDPOINT],
|
||||
false)
|
||||
|
||||
aux_helper.list_pool(options)
|
||||
aux_helper.list_pool(options)
|
||||
end
|
||||
0
|
||||
end
|
||||
|
@ -17,58 +17,58 @@
|
||||
require 'zona'
|
||||
|
||||
module OZonesHelper
|
||||
|
||||
|
||||
class OZHelper
|
||||
def initialize(user=nil, pass=nil, endpoint_str=nil,
|
||||
timeout=nil, debug_flag=true)
|
||||
@client = Zona::Client.new(user,
|
||||
pass,
|
||||
endpoint_str,
|
||||
timeout,
|
||||
debug_flag)
|
||||
@client = Zona::Client.new(user,
|
||||
pass,
|
||||
endpoint_str,
|
||||
timeout,
|
||||
debug_flag)
|
||||
end
|
||||
|
||||
def create_resource(kind, template)
|
||||
rc = @client.post_resource_file(kind, template)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def list_pool(kind, options)
|
||||
rc = @client.get_pool(kind)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
pool=Zona::OZonesJSON.parse_json(rc.body, kind.upcase + "_POOL")
|
||||
format_pool(pool, options)
|
||||
pool=Zona::OZonesJSON.parse_json(rc.body, kind.upcase + "_POOL")
|
||||
format_pool(pool, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show_resource(kind, id, options)
|
||||
rc = @client.get_resource(kind, id)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
resource=Zona::OZonesJSON.parse_json(rc.body, kind.upcase)
|
||||
format_resource(resource, options)
|
||||
resource=Zona::OZonesJSON.parse_json(rc.body, kind.upcase)
|
||||
format_resource(resource, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete_resource(kind, id, options)
|
||||
rc = @client.delete_resource(kind, id)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
message=Zona::OZonesJSON.parse_json(rc.body, "message")
|
||||
[0, "#{message}"]
|
||||
message=Zona::OZonesJSON.parse_json(rc.body, "message")
|
||||
[0, "#{message}"]
|
||||
end
|
||||
end
|
||||
|
||||
@ -80,7 +80,7 @@ module OZonesHelper
|
||||
def get_id(rc)
|
||||
id = rc.body.match('\"ID\":(.*)$')[1].strip
|
||||
if id[-1..-1] == ","
|
||||
id = id[0..id.size-2]
|
||||
id = id[0..id.size-2]
|
||||
end
|
||||
|
||||
return id
|
||||
|
@ -19,7 +19,7 @@ require 'cli/one_helper'
|
||||
|
||||
class VDCHelper < OZonesHelper::OZHelper
|
||||
def initialize(kind, user=nil, pass=nil, endpoint_str=nil,
|
||||
timeout=nil, debug_flag=true)
|
||||
timeout=nil, debug_flag=true)
|
||||
@vdc_str = kind
|
||||
super(user, pass, endpoint_str, timeout, debug_flag)
|
||||
end
|
||||
@ -33,8 +33,8 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
rc = @client.post_resource_str(@vdc_str, tmpl_str)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
if Zona::is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
id = get_id(rc)
|
||||
[0, "ID: #{id}"]
|
||||
@ -48,7 +48,7 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
def show_resource(id, options)
|
||||
super(@vdc_str,id, options)
|
||||
end
|
||||
|
||||
|
||||
def delete_resource(id, options)
|
||||
super(@vdc_str,id, options)
|
||||
end
|
||||
@ -56,8 +56,8 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
def addhost(id, host_array, options)
|
||||
rc = @client.get_resource(@vdc_str, id)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
else
|
||||
vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
@ -74,18 +74,18 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
rc = @client.put_resource_str(@vdc_str, id, template)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
end
|
||||
|
||||
[0, ""]
|
||||
end
|
||||
|
||||
|
||||
def delhost(id, host_array, options)
|
||||
rc = @client.get_resource(@vdc_str, id)
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
|
||||
if Zona::is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
else
|
||||
vdc = Zona::OZonesJSON.parse_json(rc.body, @vdc_str.upcase)
|
||||
end
|
||||
@ -97,8 +97,8 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
|
||||
rc = @client.put_resource_str(@vdc_str, id, template)
|
||||
|
||||
if Zona.is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
if Zona.is_error?(rc)
|
||||
return [-1, rc.message]
|
||||
end
|
||||
|
||||
[0, ""]
|
||||
@ -109,9 +109,9 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
def format_resource(vdc, options)
|
||||
str_h1="%-60s"
|
||||
str="%-10s: %-20s"
|
||||
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["VDC #{vdc['name']} INFORMATION"])
|
||||
|
||||
|
||||
puts str % ["ID ", vdc[:ID].to_s]
|
||||
puts str % ["NAME ", vdc[:NAME].to_s]
|
||||
puts str % ["GROUP_ID ", vdc[:GROUP_ID].to_s]
|
||||
@ -119,11 +119,11 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
puts str % ["VDCADMIN ", vdc[:VDCADMINNAME].to_s]
|
||||
puts str % ["HOST IDs ", vdc[:HOSTS].to_s]
|
||||
puts
|
||||
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def format_pool(pool, options)
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for VDC", :size=>4 do |d,e|
|
||||
d[:ID]
|
||||
@ -133,15 +133,15 @@ class VDCHelper < OZonesHelper::OZHelper
|
||||
d[:NAME]
|
||||
end
|
||||
|
||||
column :ZONEID, "Id of the Zone where it belongs",
|
||||
:right, :size=>40 do |d,e|
|
||||
column :ZONEID, "Id of the Zone where it belongs",
|
||||
:right, :size=>40 do |d,e|
|
||||
d[:ZONES_ID]
|
||||
end
|
||||
|
||||
|
||||
default :ID, :NAME, :ZONEID
|
||||
end
|
||||
end
|
||||
st.show(pool[:VDC], options)
|
||||
|
||||
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
@ -9,13 +9,13 @@ require 'cli/one_helper/oneuser_helper'
|
||||
|
||||
class ZonesHelper < OZonesHelper::OZHelper
|
||||
def initialize(kind, user=nil, pass=nil, endpoint_str=nil,
|
||||
timeout=nil, debug_flag=true)
|
||||
timeout=nil, debug_flag=true)
|
||||
@zone_str = kind
|
||||
super(user, pass, endpoint_str, timeout, debug_flag)
|
||||
end
|
||||
|
||||
def create_resource(template)
|
||||
super(@zone_str,template)
|
||||
super(@zone_str,template)
|
||||
end
|
||||
|
||||
def list_pool(options)
|
||||
@ -25,19 +25,19 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
def show_resource(id, options)
|
||||
super(@zone_str,id, options)
|
||||
end
|
||||
|
||||
|
||||
def delete_resource(id, options)
|
||||
super(@zone_str,id, options)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def format_resource(zone, options)
|
||||
str_h1="%-61s"
|
||||
str="%-15s: %-20s"
|
||||
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["ZONE #{zone[:NAME]} INFORMATION"])
|
||||
|
||||
|
||||
puts str % ["ID ", zone[:ID].to_s]
|
||||
puts str % ["NAME ", zone[:NAME].to_s]
|
||||
puts str % ["ZONE ADMIN ",zone[:ONENAME].to_s]
|
||||
@ -45,14 +45,14 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
puts str % ["ENDPOINT ", zone[:ENDPOINT].to_s]
|
||||
puts str % ["# VDCS ", zone[:VDCS].size.to_s]
|
||||
puts
|
||||
|
||||
|
||||
if zone[:VDCS].size == 0
|
||||
return [0, zone]
|
||||
end
|
||||
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["VDCS INFORMATION"])
|
||||
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for VDC", :size=>4 do |d,e|
|
||||
d[:ID]
|
||||
end
|
||||
@ -60,16 +60,16 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
column :NAME, "Name of the VDC", :right, :size=>15 do |d,e|
|
||||
d[:NAME]
|
||||
end
|
||||
|
||||
|
||||
default :ID, :NAME
|
||||
end
|
||||
|
||||
st.show(zone[:VDCS], options)
|
||||
|
||||
|
||||
return [0, zone]
|
||||
end
|
||||
|
||||
def format_pool(pool, options)
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil) do
|
||||
column :ID, "Identifier for Zone", :size=>4 do |d,e|
|
||||
d[:ID]
|
||||
@ -82,11 +82,11 @@ class ZonesHelper < OZonesHelper::OZHelper
|
||||
column :ENDPOINT, "Endpoint of the Zone", :right, :size=>40 do |d,e|
|
||||
d[:ENDPOINT]
|
||||
end
|
||||
|
||||
|
||||
default :ID, :NAME, :ENDPOINT
|
||||
end
|
||||
st.show(pool[:ZONE], options)
|
||||
|
||||
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
@ -267,7 +267,7 @@ EOT
|
||||
begin
|
||||
str << "Body: " <<
|
||||
OZonesJSON.parse_json(value.body,
|
||||
"error")["message"]
|
||||
"error")["message"]
|
||||
rescue
|
||||
str.gsub!("\nBody:","")
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ module OZones
|
||||
def to_str
|
||||
@message
|
||||
end
|
||||
|
||||
|
||||
def to_json
|
||||
message = { :message => @message }
|
||||
error_hash = { :error => message }
|
||||
@ -54,7 +54,7 @@ module OZones
|
||||
return JSON.pretty_generate error_hash
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Returns true if the object returned by a method of the OZones
|
||||
# library is an Error
|
||||
@ -62,10 +62,8 @@ module OZones
|
||||
def self.is_error?(value)
|
||||
value.class==OZones::Error
|
||||
end
|
||||
|
||||
|
||||
def self.str_to_json(str)
|
||||
return JSON.pretty_generate({:message => str})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedHosts < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedHosts < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
def factory(client)
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::HostPoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedImages < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedImages < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::ImagePoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,54 +15,54 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedPool
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
|
||||
|
||||
class AggregatedPool
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
|
||||
def initialize(tag)
|
||||
@tag = tag
|
||||
end
|
||||
|
||||
|
||||
def info
|
||||
@sup_aggregated_pool = Hash.new
|
||||
@sup_aggregated_pool[@tag] = Hash.new
|
||||
@sup_aggregated_pool[@tag]["ZONE"] = Array.new
|
||||
|
||||
|
||||
OZones::Zones.all.each{|zone|
|
||||
|
||||
|
||||
zone_pool_hash = Hash.new
|
||||
|
||||
|
||||
zone_pool_hash = zone.to_hash["ZONE"]
|
||||
|
||||
|
||||
client = OpenNebula::Client.new(
|
||||
zone.ONENAME + ":" + zone.ONEPASS,
|
||||
zone.ENDPOINT,
|
||||
false)
|
||||
|
||||
pool = factory(client)
|
||||
|
||||
zone.ONENAME + ":" + zone.ONEPASS,
|
||||
zone.ENDPOINT,
|
||||
false)
|
||||
|
||||
pool = factory(client)
|
||||
|
||||
if OpenNebula.is_error?(pool)
|
||||
zone_pool_hash.merge!(pool.to_hash)
|
||||
next
|
||||
end
|
||||
|
||||
|
||||
rc = pool.info
|
||||
|
||||
if !rc
|
||||
zone_pool_hash.merge!(pool.to_hash)
|
||||
if !rc
|
||||
zone_pool_hash.merge!(pool.to_hash)
|
||||
else
|
||||
zone_pool_hash.merge!(rc.to_hash)
|
||||
end
|
||||
|
||||
|
||||
@sup_aggregated_pool[@tag]["ZONE"] << zone_pool_hash
|
||||
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def to_hash
|
||||
info
|
||||
return @sup_aggregated_pool
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedTemplates < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedTemplates < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
def factory(client)
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::TemplatePoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedUsers < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedUsers < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
def factory(client)
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::UserPoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedVirtualMachines < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedVirtualMachines < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
def factory(client)
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::VirtualMachinePoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,16 +15,16 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class AggregatedVirtualNetworks < AggregatedPool
|
||||
|
||||
|
||||
class AggregatedVirtualNetworks < AggregatedPool
|
||||
|
||||
def initialize
|
||||
super("ZONE_POOL")
|
||||
end
|
||||
|
||||
def factory(client)
|
||||
|
||||
def factory(client)
|
||||
OpenNebulaJSON::VirtualNetworkPoolJSON.new(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,33 +15,33 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class ApacheWritter
|
||||
def initialize(file_path)
|
||||
|
||||
class ApacheWritter
|
||||
def initialize(file_path)
|
||||
@file_path = file_path
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
htaccess = "RewriteEngine On\n"
|
||||
|
||||
|
||||
OZones::Zones.all.each{|zone|
|
||||
zone.vdcs.all.each{|vdc|
|
||||
htaccess << "RewriteRule ^#{vdc.NAME} " +
|
||||
"#{zone.ENDPOINT} [P]\n"
|
||||
"#{zone.ENDPOINT} [P]\n"
|
||||
if zone.SUNSENDPOINT != nil
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.NAME}/(.+) " +
|
||||
"#{zone.SUNSENDPOINT}/$1 [P]\n"
|
||||
"#{zone.SUNSENDPOINT}/$1 [P]\n"
|
||||
htaccess << "RewriteRule ^sunstone_#{vdc.NAME} " +
|
||||
"#{zone.SUNSENDPOINT}/ [P]\n"
|
||||
"#{zone.SUNSENDPOINT}/ [P]\n"
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
File.open(@file_path, 'w') {|f|
|
||||
File.open(@file_path, 'w') {|f|
|
||||
f.flock(File::LOCK_EX)
|
||||
f.write(htaccess)
|
||||
f.write(htaccess)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,34 +15,34 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class ProxyRules
|
||||
def initialize(type, file_path)
|
||||
|
||||
class ProxyRules
|
||||
def initialize(type, file_path)
|
||||
@type = type
|
||||
if file_path
|
||||
@file_path = file_path
|
||||
else
|
||||
else
|
||||
if !ENV["ONE_LOCATION"]
|
||||
@file_path="/var/lib/one/.htaccess"
|
||||
else
|
||||
@file_path=ENV["ONE_LOCATION"]+"/var/.htaccess"
|
||||
@file_path=ENV["ONE_LOCATION"]+"/var/.htaccess"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Let's check for file permissions
|
||||
if !File.writable?(@file_path) and
|
||||
!File.writable?(File.dirname(@file_path))
|
||||
raise "#{@file_path} is not writable"
|
||||
if !File.writable?(@file_path) and
|
||||
!File.writable?(File.dirname(@file_path))
|
||||
raise "#{@file_path} is not writable"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
case @type
|
||||
when "apache"
|
||||
apWritter = OZones::ApacheWritter.new @file_path
|
||||
apWritter.update
|
||||
when "apache"
|
||||
apWritter = OZones::ApacheWritter.new @file_path
|
||||
apWritter.update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -15,8 +15,8 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class Vdc
|
||||
|
||||
class Vdc
|
||||
include DataMapper::Resource
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
extend OpenNebulaJSON::JSONUtils
|
||||
@ -30,7 +30,7 @@ module OZones
|
||||
property :HOSTS, String
|
||||
|
||||
belongs_to :zones
|
||||
|
||||
|
||||
def self.to_hash
|
||||
zonePoolHash = Hash.new
|
||||
zonePoolHash["VDC_POOL"] = Hash.new
|
||||
@ -46,7 +46,7 @@ module OZones
|
||||
}
|
||||
return zonePoolHash
|
||||
end
|
||||
|
||||
|
||||
def to_hash
|
||||
vdc_attributes = Hash.new
|
||||
|
||||
@ -64,7 +64,7 @@ module OZones
|
||||
###########################################################################
|
||||
# This class represents a VDC able to interact with its supporting
|
||||
# OpenNebula installation through OCA. Data persistence is provided by a
|
||||
# Vdc class
|
||||
# Vdc class
|
||||
###########################################################################
|
||||
class OpenNebulaVdc
|
||||
#######################################################################
|
||||
@ -77,10 +77,10 @@ module OZones
|
||||
|
||||
#Creates an OpenNebula VDC, using its ID, vdcid and the associated zone
|
||||
def initialize(vdcid, zone = nil)
|
||||
|
||||
if vdcid != -1
|
||||
|
||||
if vdcid != -1
|
||||
@vdc = Vdc.get(vdcid)
|
||||
|
||||
|
||||
if !@vdc
|
||||
raise "VDC with id #{vdcid} not found."
|
||||
end
|
||||
@ -91,9 +91,9 @@ module OZones
|
||||
end
|
||||
|
||||
@client = OpenNebula::Client.new(
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
end
|
||||
|
||||
def to_json
|
||||
@ -108,20 +108,20 @@ module OZones
|
||||
VDC_ATTRS.each { |param|
|
||||
if !vdc_data[param]
|
||||
return OZones::Error.new("Error: Couldn't create vdc." \
|
||||
"Mandatory attribute '#{param}' is missing.")
|
||||
"Mandatory attribute '#{param}' is missing.")
|
||||
end
|
||||
}
|
||||
|
||||
#Create a vdc record
|
||||
@vdc = Vdc.new
|
||||
|
||||
|
||||
vdcpass = Digest::SHA1.hexdigest(vdc_data.delete(:VDCADMINPASS))
|
||||
@vdc.attributes = vdc_data
|
||||
|
||||
# Create a group in the zone with the VDC name
|
||||
group = OpenNebula::Group.new(OpenNebula::Group.build_xml, @client)
|
||||
rc = group.allocate(@vdc.NAME)
|
||||
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
@vdc.GROUP_ID = group.id
|
||||
@ -197,7 +197,7 @@ module OZones
|
||||
host_acls = get_host_acls(host_list)
|
||||
rc, acls_str = create_acls(host_acls)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
#Create the new acl string.
|
||||
newacls << "," << acls_str
|
||||
@ -215,7 +215,7 @@ module OZones
|
||||
return OpenNebula::Error.new(e.message)
|
||||
end
|
||||
|
||||
return @vdc.to_json
|
||||
return @vdc.to_json
|
||||
end
|
||||
|
||||
private
|
||||
@ -225,19 +225,19 @@ module OZones
|
||||
# The ID of the first host ACL
|
||||
HOST_ACL_FIRST_ID = 3
|
||||
|
||||
# This method returns an Array of ACL strings to create them
|
||||
# This method returns an Array of ACL strings to create them
|
||||
# in the target zone
|
||||
def get_acls
|
||||
rule_str = Array.new
|
||||
|
||||
# Grant permissions to the group
|
||||
rule_str << "@#{@vdc.GROUP_ID} VM+NET+IMAGE+TEMPLATE/* " \
|
||||
"CREATE+INFO_POOL_MINE"
|
||||
"CREATE+INFO_POOL_MINE"
|
||||
|
||||
# Grant permissions to the vdc admin
|
||||
rule_str << "##{@vdc.VDCADMIN_ID} USER/* CREATE"
|
||||
rule_str << "##{@vdc.VDCADMIN_ID} USER/@#{@vdc.GROUP_ID} " \
|
||||
"MANAGE+DELETE+INFO"
|
||||
"MANAGE+DELETE+INFO"
|
||||
|
||||
###############################################################
|
||||
#When more rules are added the class constant HOST_ACL_FIRST_ID
|
||||
@ -252,12 +252,12 @@ module OZones
|
||||
|
||||
if host_list == nil
|
||||
host_list = @vdc.HOSTS
|
||||
end
|
||||
end
|
||||
|
||||
# Grant permissions to use the vdc hosts
|
||||
host_list.split(',').each{|hostid|
|
||||
rule_str << "@#{@vdc.GROUP_ID} HOST/##{hostid} USE"
|
||||
}
|
||||
}
|
||||
|
||||
return rule_str
|
||||
end
|
||||
@ -276,14 +276,14 @@ module OZones
|
||||
end
|
||||
end
|
||||
|
||||
# Delete ACLs
|
||||
# Delete ACLs
|
||||
def delete_acls
|
||||
@vdc.ACLS.split(",").each{|acl|
|
||||
OpenNebula::Acl.new_with_id(acl.to_i, @client).delete
|
||||
}
|
||||
end
|
||||
|
||||
# Deletes images
|
||||
# Deletes images
|
||||
def delete_images
|
||||
ip = OpenNebula::ImagePool.new(@client)
|
||||
ip.info
|
||||
@ -293,7 +293,7 @@ module OZones
|
||||
}
|
||||
end
|
||||
|
||||
# Deletes templates
|
||||
# Deletes templates
|
||||
def delete_templates
|
||||
tp = OpenNebula::TemplatePool.new(@client)
|
||||
tp.info
|
||||
@ -303,7 +303,7 @@ module OZones
|
||||
}
|
||||
end
|
||||
|
||||
# Deletes VMs
|
||||
# Deletes VMs
|
||||
def delete_vms
|
||||
vmp = OpenNebula::VirtualMachinePool.new(@client)
|
||||
vmp.info
|
||||
@ -313,7 +313,7 @@ module OZones
|
||||
}
|
||||
end
|
||||
|
||||
# Deletes VNs
|
||||
# Deletes VNs
|
||||
def delete_vns
|
||||
vnp = OpenNebula::VirtualNetworkPool.new(@client)
|
||||
vnp.info
|
||||
@ -331,13 +331,13 @@ module OZones
|
||||
def rollback(group, user, acls, rc)
|
||||
group.delete
|
||||
user.delete if user
|
||||
|
||||
|
||||
if acls
|
||||
acls.chop
|
||||
acls.split(",").each{|acl|
|
||||
OpenNebula::Acl.new_with_id(acl.to_i, @client).delete
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return rc
|
||||
end
|
||||
@ -353,7 +353,7 @@ module OZones
|
||||
rc = acl.allocate(*OpenNebula::Acl.parse_rule(rule))
|
||||
|
||||
break if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
acls_str << acl.id.to_s << ","
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OZones
|
||||
|
||||
class Zones
|
||||
|
||||
class Zones
|
||||
include DataMapper::Resource
|
||||
include OpenNebulaJSON::JSONUtils
|
||||
extend OpenNebulaJSON::JSONUtils
|
||||
|
||||
|
||||
#######################################################################
|
||||
# Data Model for the Zone
|
||||
#######################################################################
|
||||
@ -30,9 +30,9 @@ module OZones
|
||||
property :ONEPASS, String, :required => true
|
||||
property :ENDPOINT, String, :required => true
|
||||
property :SUNSENDPOINT, String
|
||||
|
||||
|
||||
has n, :vdcs
|
||||
|
||||
|
||||
#######################################################################
|
||||
# Constants
|
||||
#######################################################################
|
||||
@ -47,13 +47,13 @@ module OZones
|
||||
zonePoolHash["ZONE_POOL"]["ZONE"] = Array.new unless self.all.empty?
|
||||
|
||||
self.all.each{|zone|
|
||||
zonePoolHash["ZONE_POOL"]["ZONE"] <<
|
||||
zone.attributes.merge({:NUMBERVDCS => zone.vdcs.all.size})
|
||||
zonePoolHash["ZONE_POOL"]["ZONE"] <<
|
||||
zone.attributes.merge({:NUMBERVDCS => zone.vdcs.all.size})
|
||||
}
|
||||
|
||||
return zonePoolHash
|
||||
end
|
||||
|
||||
|
||||
def to_hash
|
||||
zone_attributes = Hash.new
|
||||
zone_attributes["ZONE"] = attributes
|
||||
@ -74,7 +74,7 @@ module OZones
|
||||
ZONE_ATTRS.each { |param|
|
||||
if !zone_data[param]
|
||||
return OZones::Error.new("Error: Couldn't create zone. " \
|
||||
"Mandatory attribute '#{param}' is missing.")
|
||||
"Mandatory attribute '#{param}' is missing.")
|
||||
end
|
||||
}
|
||||
|
||||
@ -84,18 +84,18 @@ module OZones
|
||||
$stderr.puts zone_data
|
||||
|
||||
rc = OpenNebulaZone::check_oneadmin(zone_data[:ONENAME],
|
||||
zone_data[:ONEPASS],
|
||||
zone_data[:ENDPOINT])
|
||||
zone_data[:ONEPASS],
|
||||
zone_data[:ENDPOINT])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return OZones::Error.new("Error: Couldn't create zone. "\
|
||||
"Reason: #{rc.message}")
|
||||
"Reason: #{rc.message}")
|
||||
end
|
||||
|
||||
|
||||
# Create the zone
|
||||
begin
|
||||
zone = Zones.new
|
||||
zone = Zones.new
|
||||
zone.raise_on_save_failure = true
|
||||
|
||||
zone.attributes = zone_data
|
||||
@ -106,46 +106,46 @@ module OZones
|
||||
|
||||
return zone
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# This class represents a Zone able to interact with its supporting
|
||||
# OpenNebula installation through OCA. Data persistence is provided by a
|
||||
# Zones class
|
||||
# Zones class
|
||||
##########################################################################
|
||||
class OpenNebulaZone
|
||||
def initialize(zoneid)
|
||||
@zone = Zones.get(zoneid)
|
||||
|
||||
|
||||
if !@zone
|
||||
raise "Error: Zone with id #{zoneid} not found"
|
||||
end
|
||||
|
||||
@client = OpenNebula::Client.new(
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
"#{@zone.ONENAME}:#{@zone.ONEPASS}",
|
||||
@zone.ENDPOINT,
|
||||
false)
|
||||
end
|
||||
|
||||
|
||||
def pool_to_json(pool_kind)
|
||||
pool = case pool_kind
|
||||
when "host" then
|
||||
OpenNebulaJSON::HostPoolJSON.new(@client)
|
||||
when "image" then
|
||||
OpenNebulaJSON::ImagePoolJSON.new(@client)
|
||||
when "user" then
|
||||
OpenNebulaJSON::UserPoolJSON.new(@client)
|
||||
when "vm" then
|
||||
OpenNebulaJSON::VirtualMachinePoolJSON.new(@client)
|
||||
when "vn","vnet" then
|
||||
OpenNebulaJSON::VirtualNetworkPoolJSON.new(@client)
|
||||
when "template","vmtemplate" then
|
||||
OpenNebulaJSON::TemplatePoolJSON.new(@client)
|
||||
else
|
||||
error = OZones::Error.new("Error: Pool #{pool_kind} not " \
|
||||
"supported for zone view")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
when "host" then
|
||||
OpenNebulaJSON::HostPoolJSON.new(@client)
|
||||
when "image" then
|
||||
OpenNebulaJSON::ImagePoolJSON.new(@client)
|
||||
when "user" then
|
||||
OpenNebulaJSON::UserPoolJSON.new(@client)
|
||||
when "vm" then
|
||||
OpenNebulaJSON::VirtualMachinePoolJSON.new(@client)
|
||||
when "vn","vnet" then
|
||||
OpenNebulaJSON::VirtualNetworkPoolJSON.new(@client)
|
||||
when "template","vmtemplate" then
|
||||
OpenNebulaJSON::TemplatePoolJSON.new(@client)
|
||||
else
|
||||
error = OZones::Error.new("Error: Pool #{pool_kind} not " \
|
||||
"supported for zone view")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
pool.info
|
||||
|
||||
@ -154,23 +154,23 @@ module OZones
|
||||
|
||||
def self.all_pools_to_json(pool_kind)
|
||||
pool = case pool_kind
|
||||
when "host" then
|
||||
OZones::AggregatedHosts.new
|
||||
when "image" then
|
||||
OZones::AggregatedImages.new
|
||||
when "user" then
|
||||
OZones::AggregatedUsers.new
|
||||
when "vm" then
|
||||
OZones::AggregatedVirtualMachines.new
|
||||
when "vn","vnet" then
|
||||
OZones::AggregatedVirtualNetworks.new
|
||||
when "template","vmtemplate" then
|
||||
OZones::AggregatedTemplates.new
|
||||
else
|
||||
error = OZones::Error.new("Error: Pool #{pool_kind} not" \
|
||||
" supported for aggregated zone view")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
when "host" then
|
||||
OZones::AggregatedHosts.new
|
||||
when "image" then
|
||||
OZones::AggregatedImages.new
|
||||
when "user" then
|
||||
OZones::AggregatedUsers.new
|
||||
when "vm" then
|
||||
OZones::AggregatedVirtualMachines.new
|
||||
when "vn","vnet" then
|
||||
OZones::AggregatedVirtualNetworks.new
|
||||
when "template","vmtemplate" then
|
||||
OZones::AggregatedTemplates.new
|
||||
else
|
||||
error = OZones::Error.new("Error: Pool #{pool_kind} not" \
|
||||
" supported for aggregated zone view")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
return [200, pool.to_json]
|
||||
end
|
||||
|
@ -14,12 +14,12 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
class Auth
|
||||
|
||||
class Auth
|
||||
|
||||
include DataMapper::Resource
|
||||
|
||||
property :id, Serial
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :password, String, :required => true
|
||||
|
||||
end
|
||||
property :name, String, :required => true, :unique => true
|
||||
property :password, String, :required => true
|
||||
|
||||
end
|
||||
|
@ -35,11 +35,11 @@ class OzonesServer
|
||||
if vdc
|
||||
return [200, vdc.to_json]
|
||||
else
|
||||
return [404,
|
||||
OZones::Error.new("Error:VDC with id #{id} not found").to_json]
|
||||
return [404,
|
||||
OZones::Error.new("Error:VDC with id #{id} not found").to_json]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#Gets all Zones
|
||||
def get_zones
|
||||
return 200, OZones::Zones.to_json
|
||||
@ -52,8 +52,8 @@ class OzonesServer
|
||||
if zone
|
||||
return [200, zone.to_json]
|
||||
else
|
||||
return [404,
|
||||
OZones::Error.new("Error:Zone with id #{id} not found").to_json]
|
||||
return [404,
|
||||
OZones::Error.new("Error:Zone with id #{id} not found").to_json]
|
||||
end
|
||||
end
|
||||
|
||||
@ -81,7 +81,7 @@ class OzonesServer
|
||||
|
||||
if OpenNebula.is_error?(vdc_data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Reason: #{data.message}.").to_json]
|
||||
"Reason: #{data.message}.").to_json]
|
||||
end
|
||||
|
||||
#Get the Zone that will host the VDC. And check resouces
|
||||
@ -89,21 +89,23 @@ class OzonesServer
|
||||
force = vdc_data.delete(:FORCE)
|
||||
|
||||
if !zoneid
|
||||
return [400, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Mandatory attribute zoneid missing.").to_json]
|
||||
return [400,
|
||||
OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Mandatory attribute zoneid missing.").to_json]
|
||||
end
|
||||
|
||||
zone = OZones::Zones.get(zoneid)
|
||||
if !zone
|
||||
return [404, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Zone #{zoneid} not found.").to_json]
|
||||
"Zone #{zoneid} not found.").to_json]
|
||||
end
|
||||
|
||||
if (!force or force.upcase!="YES") and
|
||||
!host_uniqueness?(zone, vdc_data[:HOSTS])
|
||||
if (!force or force.upcase!="YES") and
|
||||
!host_uniqueness?(zone, vdc_data[:HOSTS])
|
||||
|
||||
return [403, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Hosts are not unique, use force to override").to_json]
|
||||
return [403,
|
||||
OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Hosts are not unique, use force to override").to_json]
|
||||
end
|
||||
|
||||
# Create de VDC
|
||||
@ -112,20 +114,21 @@ class OzonesServer
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return [400, OZones::Error.new("Error: Couldn't create vdc. " \
|
||||
"Reason: #{rc.message}").to_json]
|
||||
"Reason: #{rc.message}").to_json]
|
||||
end
|
||||
|
||||
#Update the zone and save the vdc
|
||||
zone.raise_on_save_failure = true
|
||||
zone.vdcs << vdc.vdc
|
||||
|
||||
begin
|
||||
begin
|
||||
zone.save
|
||||
rescue => e
|
||||
vdc.clean_bootstrap
|
||||
|
||||
return [400, OZones::Error.new("Error: Couldn't create " \
|
||||
"vdc. Zone could not be saved: #{e.message}").to_json]
|
||||
return [400,
|
||||
OZones::Error.new("Error: Couldn't create " \
|
||||
"vdc. Zone could not be saved: #{e.message}").to_json]
|
||||
end
|
||||
|
||||
pr.update # Rewrite proxy conf file
|
||||
@ -138,7 +141,7 @@ class OzonesServer
|
||||
|
||||
if OpenNebula.is_error?(data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Reason: #{data.message}.").to_json]
|
||||
"Reason: #{data.message}.").to_json]
|
||||
end
|
||||
|
||||
zone = OZones::Zones.create(data)
|
||||
@ -160,7 +163,7 @@ class OzonesServer
|
||||
|
||||
if OpenNebula.is_error?(vdc_data)
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Reason: #{data.message}.").to_json]
|
||||
"Reason: #{data.message}.").to_json]
|
||||
end
|
||||
|
||||
hosts = vdc_data.delete(:HOSTS)
|
||||
@ -169,7 +172,7 @@ class OzonesServer
|
||||
# Check parameters
|
||||
if !hosts
|
||||
return [400, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Missing HOSTS.").to_json]
|
||||
"Missing HOSTS.").to_json]
|
||||
end
|
||||
|
||||
# Check if the referenced Vdc exists
|
||||
@ -177,25 +180,26 @@ class OzonesServer
|
||||
vdc = OZones::OpenNebulaVdc.new(vdc_id)
|
||||
rescue => e
|
||||
return [404, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"#{e.message}").to_json]
|
||||
"#{e.message}").to_json]
|
||||
end
|
||||
|
||||
if (!force or force.upcase != "YES") and
|
||||
!host_uniqueness?(vdc.zone, hosts, vdc_id.to_i)
|
||||
|
||||
return [403, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Hosts are not unique, use force to override").to_json]
|
||||
if (!force or force.upcase != "YES") and
|
||||
!host_uniqueness?(vdc.zone, hosts, vdc_id.to_i)
|
||||
|
||||
return [403,
|
||||
OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
"Hosts are not unique, use force to override").to_json]
|
||||
end
|
||||
|
||||
|
||||
rc = vdc.update(hosts)
|
||||
|
||||
|
||||
if !OpenNebula.is_error?(rc)
|
||||
return [200, rc]
|
||||
else
|
||||
return [500, OZones::Error.new("Error: Couldn't update vdc. " \
|
||||
" Reason: #{rc.message}").to_json]
|
||||
" Reason: #{rc.message}").to_json]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Delete resources
|
||||
@ -206,12 +210,12 @@ class OzonesServer
|
||||
rc = vdc.destroy
|
||||
rescue => e
|
||||
return [404, OZones::Error.new("Error: Can not delete vdc. " \
|
||||
"Reason: #{e.message}").to_json]
|
||||
"Reason: #{e.message}").to_json]
|
||||
end
|
||||
|
||||
if !rc
|
||||
return [500, OZones::Error.new("Error: Couldn't delete " \
|
||||
"vdc #{id}").to_json]
|
||||
"vdc #{id}").to_json]
|
||||
else
|
||||
pr.update # Rewrite proxy conf file
|
||||
return [200, OZones.str_to_json("Vdc #{id} successfully deleted")]
|
||||
@ -224,13 +228,14 @@ class OzonesServer
|
||||
if zone
|
||||
rc = zone.destroy
|
||||
else
|
||||
return [404, OZones::Error.new("Error: Can not delete " \
|
||||
"zone. Reason: zone #{id} not found").to_json]
|
||||
return [404,
|
||||
OZones::Error.new("Error: Can not delete " \
|
||||
"zone. Reason: zone #{id} not found").to_json]
|
||||
end
|
||||
|
||||
if !rc
|
||||
return [500, OZones::Error.new("Error: Couldn't delete " \
|
||||
"zone #{id}").to_json]
|
||||
"zone #{id}").to_json]
|
||||
else
|
||||
pr.update # Rewrite proxy conf file
|
||||
return [200, OZones.str_to_json("Zone #{id} successfully deleted")]
|
||||
@ -241,11 +246,11 @@ class OzonesServer
|
||||
# Misc Helper Functions
|
||||
############################################################################
|
||||
private
|
||||
|
||||
|
||||
# Check if hosts are already include in any Vdc of the zone
|
||||
def host_uniqueness?(zone, host_list, vdc_id = -1)
|
||||
return true if host_list.empty?
|
||||
|
||||
|
||||
all_hosts = ""
|
||||
zone.vdcs.all.each{|vdc|
|
||||
if vdc.HOSTS != nil and !vdc.HOSTS.empty? and vdc.id != vdc_id
|
||||
|
@ -24,7 +24,7 @@ if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
VAR_LOCATION="/var/lib/one"
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc"
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc"
|
||||
LIB_LOCATION=ONE_LOCATION+"/lib"
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION=ONE_LOCATION+"/var"
|
||||
@ -62,7 +62,7 @@ db_url = db_type + "://" + VAR_LOCATION + "/ozones.db"
|
||||
##############################################################################
|
||||
# DB bootstrapping
|
||||
##############################################################################
|
||||
if config[:dbdebug]
|
||||
if config[:dbdebug]
|
||||
DataMapper::Logger.new($stdout, :debug)
|
||||
end
|
||||
|
||||
@ -76,22 +76,22 @@ DataMapper.auto_upgrade!
|
||||
|
||||
if Auth.all.size == 0
|
||||
if ENV['OZONES_AUTH'] && File.exist?(ENV['OZONES_AUTH'])
|
||||
credentials = IO.read(ENV['OZONES_AUTH']).strip.split(':')
|
||||
credentials = IO.read(ENV['OZONES_AUTH']).strip.split(':')
|
||||
|
||||
if credentials.length < 2
|
||||
warn "Authorization data malformed"
|
||||
exit -1
|
||||
end
|
||||
credentials[1] = Digest::SHA1.hexdigest(credentials[1])
|
||||
@auth=Auth.create({:name => credentials[0],
|
||||
:password => credentials[1]})
|
||||
@auth.save
|
||||
if credentials.length < 2
|
||||
warn "Authorization data malformed"
|
||||
exit -1
|
||||
end
|
||||
credentials[1] = Digest::SHA1.hexdigest(credentials[1])
|
||||
@auth=Auth.create({:name => credentials[0],
|
||||
:password => credentials[1]})
|
||||
@auth.save
|
||||
else
|
||||
warn "oZones admin credentials not set, missing OZONES_AUTH file."
|
||||
exit -1
|
||||
end
|
||||
else
|
||||
@auth=Auth.all.first
|
||||
@auth=Auth.all.first
|
||||
end
|
||||
|
||||
ADMIN_NAME = @auth.name
|
||||
@ -101,7 +101,7 @@ begin
|
||||
OZones::ProxyRules.new("apache",config[:htaccess])
|
||||
rescue Exception => e
|
||||
warn e.message
|
||||
exit -1
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
@ -122,12 +122,12 @@ helpers do
|
||||
if session[:ip] && session[:ip]==request.ip
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
auth = Rack::Auth::Basic::Request.new(request.env)
|
||||
if auth.provided? && auth.basic? && auth.credentials
|
||||
user = auth.credentials[0]
|
||||
sha1_pass = Digest::SHA1.hexdigest(auth.credentials[1])
|
||||
|
||||
|
||||
if user == ADMIN_NAME && sha1_pass == ADMIN_PASS
|
||||
return true
|
||||
end
|
||||
@ -140,7 +140,7 @@ helpers do
|
||||
if auth.provided? && auth.basic? && auth.credentials
|
||||
user = auth.credentials[0]
|
||||
sha1_pass = Digest::SHA1.hexdigest(auth.credentials[1])
|
||||
|
||||
|
||||
if user == ADMIN_NAME && sha1_pass == ADMIN_PASS
|
||||
session[:user] = user
|
||||
session[:password] = sha1_pass
|
||||
@ -170,8 +170,8 @@ end
|
||||
before do
|
||||
unless request.path=='/login' || request.path=='/'
|
||||
halt 401 unless authorized?
|
||||
|
||||
@OzonesServer = OzonesServer.new
|
||||
|
||||
@OzonesServer = OzonesServer.new
|
||||
@pr = OZones::ProxyRules.new("apache",config[:htaccess])
|
||||
end
|
||||
end
|
||||
@ -281,5 +281,3 @@ end
|
||||
delete '/zone/:id' do
|
||||
@OzonesServer.delete_zone(params[:id], @pr)
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user