Feature #1112: Clusters are coming back into fashion this season

This commit is contained in:
Carlos Martín committed 2012-02-24 15:58:51 +01:00
1 parent f4743b6077
commit 4e2b33fa23
26 files changed
+1312 -8

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
---
:ID:
:desc: ONE identifier for the Cluster
:size: 4
:NAME:
:desc: Name of the Cluster
:size: 15
:left: true
:default:
- :ID
- :NAME
+76
View File
@@ -0,0 +1,76 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, 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 'one_helper'
class OneClusterHelper < OpenNebulaHelper::OneHelper
def self.rname
"CLUSTER"
end
def self.conf_file
"onecluster.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 Cluster", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Cluster", :left, :size=>15 do |d|
d["NAME"]
end
default :ID, :NAME
end
table
end
private
def factory(id=nil)
if id
OpenNebula::Cluster.new_with_id(id, @client)
else
xml=OpenNebula::Cluster.build_xml
OpenNebula::Cluster.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::ClusterPool.new(@client)
end
def format_resource(cluster)
str="%-15s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
puts str % ["ID", cluster.id.to_s]
puts str % ["NAME", cluster.name]
puts
CLIHelper.print_header(str_h1 % "HOSTS", false)
CLIHelper.print_header("%-15s" % ["ID"])
cluster.host_ids.each do |id|
puts "%-15s" % [id]
end
end
end
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, 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. #
#--------------------------------------------------------------------------- #
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/onecluster_helper'
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onecluster` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
helper = OneClusterHelper.new
########################################################################
# Global Options
########################################################################
set :option, CommandParser::OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options << OpenNebulaHelper::NUMERIC
########################################################################
# Formatters for arguments
########################################################################
set :format, :clusterid, OneClusterHelper.to_id_desc do |arg|
helper.to_id(arg)
end
set :format, :clusterid_list, OneClusterHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
########################################################################
# Commands
########################################################################
create_desc = <<-EOT.unindent
Creates a new Cluster
EOT
command :create, create_desc, :name do
helper.create_resource(options) do |cluster|
cluster.allocate(args[0])
end
end
delete_desc = <<-EOT.unindent
Deletes the given Cluster
EOT
command :delete, delete_desc, [:range, :clusterid_list] do
helper.perform_actions(args[0],options,"deleted") do |obj|
obj.delete
end
end
list_desc = <<-EOT.unindent
Lists Clusters 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 Cluster
EOT
command :show, show_desc,[:clusterid, nil], :options=>OpenNebulaHelper::XML do
cluster = args[0] || OpenNebula::Cluster::SELF
helper.show_resource(cluster,options)
end
end