1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-28 17:57:22 +03:00

Feature #2562: New Zone pool in ruby oca and cli

This commit is contained in:
Carlos Martín 2013-12-12 19:10:12 +01:00
parent f308bdeb06
commit 7db13c428a
7 changed files with 350 additions and 5 deletions

View File

@ -686,6 +686,7 @@ BIN_FILES="src/nebula/oned \
src/cli/oneacl \
src/cli/onedatastore \
src/cli/onecluster \
src/cli/onezone \
src/cli/oneflow \
src/cli/oneflow-template \
src/onedb/onedb \
@ -1263,6 +1264,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/acl_pool.rb \
src/oca/ruby/opennebula/template.rb \
src/oca/ruby/opennebula/user_pool.rb \
src/oca/ruby/opennebula/user.rb \
src/oca/ruby/opennebula/zone_pool.rb \
src/oca/ruby/opennebula/zone.rb \
src/oca/ruby/opennebula/virtual_machine_pool.rb \
src/oca/ruby/opennebula/virtual_machine.rb \
src/oca/ruby/opennebula/virtual_network_pool.rb \
@ -1458,6 +1461,7 @@ ONE_CLI_LIB_FILES="src/cli/one_helper/onegroup_helper.rb \
src/cli/one_helper/oneacl_helper.rb \
src/cli/one_helper/onedatastore_helper.rb \
src/cli/one_helper/onecluster_helper.rb \
src/cli/one_helper/onezone_helper.rb \
src/cli/one_helper/oneacct_helper.rb"
CLI_BIN_FILES="src/cli/onevm \
@ -1470,6 +1474,7 @@ CLI_BIN_FILES="src/cli/onevm \
src/cli/oneacl \
src/cli/onedatastore \
src/cli/onecluster \
src/cli/onezone \
src/cli/oneflow \
src/cli/oneflow-template \
src/cli/oneacct"
@ -1484,6 +1489,7 @@ CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
src/cli/etc/oneacl.yaml \
src/cli/etc/onedatastore.yaml \
src/cli/etc/onecluster.yaml \
src/cli/etc/onezone.yaml \
src/cli/etc/oneacct.yaml"
ETC_CLIENT_FILES="src/cli/etc/group.default"
@ -1966,8 +1972,9 @@ OZONES_LIB_CLIENT_CLI_HELPER_FILES="\
src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb \
src/ozones/Client/lib/cli/ozones_helper/zones_helper.rb"
OZONES_BIN_CLIENT_FILES="src/ozones/Client/bin/onevdc \
src/ozones/Client/bin/onezone"
# TODO
#OZONES_BIN_CLIENT_FILES="src/ozones/Client/bin/onevdc \
# src/ozones/Client/bin/onezone"
OZONES_RUBY_LIB_FILES="src/oca/ruby/OpenNebula.rb"
@ -2017,6 +2024,7 @@ MAN_FILES="share/man/oneauth.1.gz \
share/man/onedb.1.gz \
share/man/onedatastore.1.gz \
share/man/onecluster.1.gz \
share/man/onezone.1.gz \
share/man/oneflow.1.gz \
share/man/oneflow-template.1.gz \
share/man/econe-allocate-address.1.gz \
@ -2043,9 +2051,7 @@ MAN_FILES="share/man/oneauth.1.gz \
share/man/econe-upload.1.gz \
share/man/occi-compute.1.gz \
share/man/occi-network.1.gz \
share/man/occi-storage.1.gz \
share/man/onezone.1.gz \
share/man/onevdc.1.gz"
share/man/occi-storage.1.gz"
#-----------------------------------------------------------------------------
# Ruby VENDOR files

13
src/cli/etc/onezone.yaml Normal file
View File

@ -0,0 +1,13 @@
---
:ID:
:desc: ONE identifier for the Zone
:size: 5
:NAME:
:desc: Name of the Zone
:size: 25
:left: true
:default:
- :ID
- :NAME

View File

@ -0,0 +1,74 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, 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 'one_helper'
class OneZoneHelper < OpenNebulaHelper::OneHelper
def self.rname
"ZONE"
end
def self.conf_file
"onezone.yaml"
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Zone", :size=>5 do |d|
d["ID"]
end
column :NAME, "Name of the Zone", :left, :size=>25 do |d|
d["NAME"]
end
default :ID, :NAME
end
table
end
private
def factory(id=nil)
if id
OpenNebula::Zone.new_with_id(id, @client)
else
xml=OpenNebula::Zone.build_xml
OpenNebula::Zone.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::ZonePool.new(@client)
end
def format_resource(zone, options = {})
str="%-18s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(str_h1 % "ZONE #{zone['ID']} INFORMATION")
puts str % ["ID", zone.id.to_s]
puts str % ["NAME", zone.name]
puts
CLIHelper.print_header(str_h1 % "ZONE TEMPLATE", false)
puts zone.template_str
end
end

109
src/cli/onezone Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, 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. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'one_helper/onezone_helper'
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onezone` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
helper = OneZoneHelper.new
before_proc do
helper.set_client(options)
end
########################################################################
# Global Options
########################################################################
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
########################################################################
# Formatters for arguments
########################################################################
set :format, :zoneid, OneZoneHelper.to_id_desc do |arg|
helper.to_id(arg)
end
set :format, :zoneid_list, OneZoneHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
########################################################################
# Commands
########################################################################
create_desc = <<-EOT.unindent
Creates a new Zone
EOT
command :create, create_desc, :file do
helper.create_resource(options) do |zone|
begin
template = File.read(args[0])
zone.allocate(template)
rescue => e
STDERR.puts e.message
exit -1
end
end
end
delete_desc = <<-EOT.unindent
Deletes the given Zone
EOT
command :delete, delete_desc, [:range, :zoneid_list] do
helper.perform_actions(args[0],options,"deleted") do |obj|
obj.delete
end
end
list_desc = <<-EOT.unindent
Lists Zones in the pool
EOT
command :list, list_desc, :options=>list_options do
helper.list_pool(options)
end
show_desc = <<-EOT.unindent
Shows information for the given Zone
EOT
command :show, show_desc,:zoneid, :options=>OpenNebulaHelper::XML do
helper.show_resource(args[0],options)
end
end

View File

@ -49,6 +49,8 @@ require 'opennebula/cluster'
require 'opennebula/cluster_pool'
require 'opennebula/document'
require 'opennebula/document_pool'
require 'opennebula/zone'
require 'opennebula/zone_pool'
require 'opennebula/system'
module OpenNebula

View File

@ -0,0 +1,83 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, 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 'opennebula/pool_element'
module OpenNebula
class Zone < PoolElement
#######################################################################
# Constants and Class Methods
#######################################################################
ZONE_METHODS = {
:info => "zone.info",
:allocate => "zone.allocate",
:delete => "zone.delete"
}
# Creates a Zone description with just its identifier
# this method should be used to create plain Zone objects.
# @param id [Integer] the id of the Zone
#
# Example:
# zone = Zone.new(Zone.build_xml(3),rpc_client)
#
def Zone.build_xml(pe_id=nil)
if pe_id
zone_xml = "<ZONE><ID>#{pe_id}</ID></ZONE>"
else
zone_xml = "<ZONE></ZONE>"
end
XMLElement.build_xml(zone_xml,'ZONE')
end
# Class constructor
def initialize(xml, client)
super(xml,client)
end
#######################################################################
# XML-RPC Methods for the Zone Object
#######################################################################
# Retrieves the information of the given Zone.
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def info()
super(ZONE_METHODS[:info], 'ZONE')
end
alias_method :info!, :info
# Allocates a new Zone in OpenNebula
#
# @param description [String] The template of the Zone.
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def allocate(description)
super(ZONE_METHODS[:allocate], description)
end
# Deletes the Zone
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def delete()
super(ZONE_METHODS[:delete])
end
end
end

View File

@ -0,0 +1,58 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, 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 'opennebula/pool'
module OpenNebula
class ZonePool < Pool
#######################################################################
# Constants and Class attribute accessors
#######################################################################
ZONE_POOL_METHODS = {
:info => "zonepool.info"
}
#######################################################################
# Class constructor & Pool Methods
#######################################################################
# @param client [OpenNebula::Client] XML-RPC connection
def initialize(client)
super('ZONE_POOL','ZONE',client)
end
# Factory method to create Zone objects
# @return [Zone] new Zone object
def factory(element_xml)
OpenNebula::Zone.new(element_xml,@client)
end
#######################################################################
# XML-RPC Methods for the Zone Object
#######################################################################
# Retrieves all the ZONEs in the pool.
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def info()
super(ZONE_POOL_METHODS[:info])
end
alias_method :info!, :info
end
end