Class: OneZoneHelper
Constant Summary
collapse
- SERVER_NAME =
{
:name => "server_name",
:short => "-n server_name",
:large => "--name",
:format => String,
:description => "Zone server name"
}
- SERVER_ENDPOINT =
{
:name => "server_rpc",
:short => "-r rpc endpoint",
:large => "--rpc",
:format => String,
:description => "Zone server RPC endpoint"
}
Instance Attribute Summary
#client
Class Method Summary
collapse
Instance Method Summary
collapse
#check_orphan, client, #create_resource, #filterflag_to_i, filterflag_to_i_desc, get_client, get_password, #group_name, #initialize, #list_pool, #list_pool_format, #list_pool_table, #list_pool_top, #list_pool_xml, #list_to_id, list_to_id_desc, name_to_id, #perform_action, #perform_actions, #print_page, #retrieve_resource, #set_client, set_endpoint, set_password, set_user, #start_pager, #stop_pager, table_conf, #to_id, to_id_desc, #user_name
Class Method Details
.conf_file ⇒ Object
498
499
500
|
# File 'lib/one_helper/onezone_helper.rb', line 498
def self.conf_file
"onezone.yaml"
end
|
.rname ⇒ Object
494
495
496
|
# File 'lib/one_helper/onezone_helper.rb', line 494
def self.rname
"ZONE"
end
|
.state_to_str(id) ⇒ Object
502
503
504
505
506
507
|
# File 'lib/one_helper/onezone_helper.rb', line 502
def self.state_to_str(id)
id = id.to_i
state_str = Zone::ZONE_STATES[id]
Zone::SHORT_ZONE_STATES[state_str]
end
|
Instance Method Details
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
# File 'lib/one_helper/onezone_helper.rb', line 509
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :CURRENT, "Active Zone", :size=>1 do |d|
"*" if helper.client.one_endpoint.strip ==
d["TEMPLATE"]['ENDPOINT'].strip
end
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
column :ENDPOINT, "Endpoint of the Zone", :left, :size=>45 do |d|
d["TEMPLATE"]['ENDPOINT']
end
column :FED_INDEX, "Federation index", :left, :size=>10 do |d|
helper.get_fed_index(d["TEMPLATE"]['ENDPOINT'])
end
column :STAT, 'Zone status', :left, :size => 6 do |d|
OneZoneHelper.state_to_str(d['STATE'])
end
default :CURRENT, :ID, :NAME, :ENDPOINT, :FED_INDEX, :STAT
end
table
end
|
#get_fed_index(endpoint) ⇒ Object
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
# File 'lib/one_helper/onezone_helper.rb', line 544
def get_fed_index(endpoint)
client = OpenNebula::Client.new(nil, endpoint, :timeout => 5)
xml = client.call('zone.raftstatus')
return '-' if OpenNebula.is_error?(xml)
xml = Nokogiri::XML(xml)
if xml.xpath('RAFT/FEDLOG_INDEX')
xml.xpath('RAFT/FEDLOG_INDEX').text
else
'-'
end
end
|
#set_zone(zone_id, temporary_zone) ⇒ Object
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
# File 'lib/one_helper/onezone_helper.rb', line 559
def set_zone(zone_id, temporary_zone)
zone = factory(zone_id)
rc = zone.info
if OpenNebula.is_error?(rc)
return -1, rc.message
end
if !zone['TEMPLATE/ENDPOINT']
return -1, "No Endpoint defined for Zone #{zone_id}"
end
if temporary_zone
puts "Type: export ONE_XMLRPC=#{zone['TEMPLATE/ENDPOINT']}"
else
File.open(ENV['HOME']+"/.one/one_endpoint", 'w'){|f|
f.puts zone['TEMPLATE/ENDPOINT']
}
puts "Endpoint changed to \"#{zone['TEMPLATE/ENDPOINT']}\" in " <<
"#{ENV['HOME']}/.one/one_endpoint"
end
return 0 unless zone['TEMPLATE/ONEFLOW_ENDPOINT']
if temporary_zone
puts "Type: export ONEFLOW_URL=#{zone['TEMPLATE/ONEFLOW_ENDPOINT']}"
else
File.open(ENV['HOME'] + '/.one/oneflow_endpoint', 'w') do |f|
f.puts zone['TEMPLATE/ONEFLOW_ENDPOINT']
end
puts 'OneFlow Endpoint changed to ' \
"\"#{zone['TEMPLATE/ONEFLOW_ENDPOINT']}\" in " <<
"#{ENV['HOME']}/.one/oneflow_endpoint"
end
0
end
|
#show_resource(id, options) ⇒ Object
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
# File 'lib/one_helper/onezone_helper.rb', line 469
def show_resource(id, options)
resource = retrieve_resource(id)
rc = resource.info_extended
return -1, rc.message if OpenNebula.is_error?(rc)
if options[:xml]
return 0, resource.to_xml(true)
elsif options[:json]
if options[:body]
return 0, check_resource_xsd(resource)
else
return 0, ::JSON.pretty_generate(
check_resource_xsd(resource)
)
end
elsif options[:yaml]
return 0, check_resource_xsd(resource).to_yaml(:indent => 4)
else
format_resource(resource, options)
return 0
end
end
|