/usr/bin/onevm is in opennebula-tools 4.12.3+dfsg-3.1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 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 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 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 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | #!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, 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/onevm_helper'
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onevm` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
helper = OneVMHelper.new
before_proc do
helper.set_client(options)
end
TYPE={
:name => "type",
:short => "-t type",
:large => "--type type",
:format => String,
:description => "Type of the new Image"
}
TARGET={
:name => "target",
:short => "-t target",
:large => "--target target",
:format => String,
:description => "Device where the image will be attached"
}
IP={
:name => "ip",
:short => "-i ip",
:large => "--ip ip",
:format => String,
:description => "IP address for the new NIC"
}
CACHE={
:name => "cache",
:large => "--cache cache_mode",
:format => String,
:description => "Hypervisor cache mode: default, none, writethrough,"<<
" writeback, directsync or unsafe. (Only KVM driver)"
}
ENFORCE={
:name => "enforce",
:short => "-e",
:large => "--enforce",
:description => "Enforce that the host capacity is not exceeded"
}
SUCCESS={
:name => "success",
:large => "--success",
:description => "Recover a VM by succeeding the pending action"
}
FAILURE={
:name => "failure",
:large => "--failure",
:description => "Recover a VM by failing the pending action"
}
CLONETEMPLATE={
:name => "clonetemplate",
:short => "-c",
:large => "--clonetemplate",
:description => "Clone original VM Template and replace disk with saved one"
}
########################################################################
# Global Options
########################################################################
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
########################################################################
# Formatters for arguments
########################################################################
set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg|
OpenNebulaHelper.rname_to_id(arg, "HOST")
end
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
OpenNebulaHelper.rname_to_id(arg, "GROUP")
end
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
OpenNebulaHelper.rname_to_id(arg, "USER")
end
set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
end
set :format, :vmid, OneVMHelper.to_id_desc do |arg|
helper.to_id(arg)
end
set :format, :vmid_list, OneVMHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
set :format, :filterflag, OneVMHelper.filterflag_to_i_desc do |arg|
helper.filterflag_to_i(arg)
end
set :format, :diskid, "Integer" do |arg|
format_int(arg)
end
########################################################################
# Commands
########################################################################
create_desc = <<-EOT.unindent
Creates a new VM from the given description instead of using a
previously defined template (see 'onetemplate create' and
'onetemplate instantiate').
Examples:
- using a template description file:
onevm create vm_description.tmpl
- new VM named "arch vm" with a disk and a nic
onevm create --name "arch vm" --memory 128 --cpu 1 --disk arch \\
--network private_lan
- a vm with two disks
onevm create --name "test vm" --memory 128 --cpu 1 --disk arch,data
EOT
command :create, create_desc, [:file, nil], :options =>
[OneVMHelper::MULTIPLE, OneVMHelper::HOLD]+
OpenNebulaHelper::TEMPLATE_OPTIONS_VM do
number = options[:multiple] || 1
exit_code = nil
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
STDERR.puts "You can not use both template file and template"<<
" creation options."
next -1
end
begin
if args[0]
template=File.read(args[0])
else
res = OpenNebulaHelper.create_template(options)
if res.first != 0
STDERR.puts res.last
next -1
end
template = res.last
end
rescue Exception => e
STDERR.puts "Error reading template."
next -1
end
if options[:dry]
puts template
exit 0
end
on_hold = options[:hold] != nil
number.times do
exit_code = helper.create_resource(options) do |vm|
error = vm.allocate(template, on_hold)
end
break if exit_code == -1
end
exit_code
end
update_desc = <<-EOT.unindent
Update the user template contents. If a path is not provided the
editor will be launched to modify the current content.
EOT
command :update, update_desc, :vmid, [:file, nil],
:options=>OpenNebulaHelper::APPEND do
helper.perform_action(args[0],options,"modified") do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1], 'USER_TEMPLATE')
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1], 'USER_TEMPLATE')
end
obj.update(str, options[:append])
end
end
delete_desc = <<-EOT.unindent
Deletes the given VM. Using --recreate resubmits the VM.
Resubmits the VM to PENDING state. This is intended for VMs stuck in a
transient state. To re-deploy a fresh copy of the same VM, create a
Template and instantiate it, see 'onetemplate instantiate'
States: ANY
EOT
command :delete, delete_desc, [:range, :vmid_list],
:options => [OneVMHelper::SCHEDULE, OneVMHelper::RECREATE] do
command_name="delete"
command_name<<"-recreate" if options[:recreate]
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, command_name)
else
helper.perform_actions(args[0],options,"deleted") do |vm|
vm.delete(options[:recreate]==true)
end
end
end
hold_desc = <<-EOT.unindent
Sets the given VM on hold. A VM on hold is not scheduled until it is
released. It can be, however, deployed manually; see 'onevm deploy'
States: PENDING
EOT
command :hold, hold_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"put on hold") do |vm|
vm.hold
end
end
end
release_desc = <<-EOT.unindent
Releases a VM on hold. See 'onevm hold'
States: HOLD
EOT
command :release, release_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"released") do |vm|
vm.release
end
end
end
disk_snapshot_desc = <<-EOT.unindent
Sets the specified VM disk to be saved in a new Image. The Image is
created immediately, but the contents are saved only if the VM is
shut down gracefully (i.e., using 'onevm shutdown' and not
'onevm delete')
If '--live' is specified, the Image will be saved immediately.
States: ANY
EOT
command :"disk-snapshot", disk_snapshot_desc, :vmid, :diskid, :img_name,
:options=>[TYPE, OneVMHelper::LIVE, CLONETEMPLATE] do
disk_id = args[1].to_i
image_name = args[2]
image_type = options[:type] || ""
verbose = "disk #{disk_id} prepared to be saved in " <<
"the image #{image_name}"
helper.perform_action(args[0],options,verbose) do |vm|
res = vm.disk_snapshot(disk_id, image_name, image_type,
options[:live]==true, options[:clonetemplate]==true)
if !OpenNebula.is_error?(res)
puts "Image ID: #{res}"
end
res
end
end
shutdown_desc = <<-EOT.unindent
Shuts down the given VM. The VM life cycle will end.
With --hard it unplugs the VM.
States: RUNNING, UNKNOWN (with --hard)
EOT
command :shutdown, shutdown_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
command_name='shutdown'
command_name<<'-hard' if options[:hard]
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, command_name)
else
helper.perform_actions(args[0],options,"shutting down") do |vm|
vm.shutdown(options[:hard]==true)
end
end
end
undeploy_desc = <<-EOT.unindent
Shuts down the given VM. The VM is saved in the system Datastore.
With --hard it unplugs the VM.
States: RUNNING
EOT
command :undeploy, undeploy_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
command_name='undeploy'
command_name<<'-hard' if options[:hard]
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, command_name)
else
helper.perform_actions(args[0],options,"shutting down") do |vm|
vm.undeploy(options[:hard]==true)
end
end
end
poweroff_desc = <<-EOT.unindent
Powers off the given VM. The VM will remain in the poweroff state, and
can be powered on with the 'onevm resume' command.
States: RUNNING
EOT
command :poweroff, poweroff_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
command_name='poweroff'
command_name<<'-hard' if options[:hard]
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"shutting down") do |vm|
vm.poweroff(options[:hard]==true)
end
end
end
reboot_desc = <<-EOT.unindent
Reboots the given VM, this is equivalent to execute the reboot command
from the VM console.
The VM will be ungracefully rebooted if --hard is used.
States: RUNNING
EOT
command :reboot, reboot_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE, OneVMHelper::HARD] do
command_name='reboot'
command_name<<'-hard' if options[:hard]
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, command_name)
else
helper.perform_actions(args[0],options,"rebooting") do |vm|
vm.reboot(options[:hard])
end
end
end
deploy_desc = <<-EOT.unindent
Deploys the given VM in the specified Host. This command forces the
deployment, in a standard installation the Scheduler is in charge
of this decision
States: PENDING
EOT
command :deploy, deploy_desc, [:range,:vmid_list], :hostid, [:datastoreid,nil],
:options=>[ENFORCE] do
host_id = args[1]
verbose = "deploying in host #{host_id}"
enforce = options[:enforce].nil? ? false : options[:enforce]
ds_id = args[2].nil? ? -1 : args[2]
helper.perform_actions(args[0],options,verbose) do |vm|
vm.deploy(host_id, enforce, ds_id)
end
end
migrate_desc = <<-EOT.unindent
Migrates the given running VM to another Host. If used with --live
parameter the miration is done without downtime.
States: RUNNING
EOT
command :migrate, migrate_desc, [:range,:vmid_list], :hostid,
:options=>[ENFORCE, OneVMHelper::LIVE] do
host_id = args[1]
verbose = "migrating to #{host_id}"
helper.perform_actions(args[0],options,verbose) do |vm|
vm.migrate( host_id,
options[:live]==true,
options[:enforce]==true)
end
end
boot_desc = <<-EOT.unindent
Boots the given VM.
States: UNKNOWN, BOOT
EOT
command :boot, boot_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"booting") do |vm|
vm.boot
end
end
end
stop_desc = <<-EOT.unindent
Stops a running VM. The VM state is saved and transferred back to the
front-end along with the disk files
States: RUNNING
EOT
command :stop, stop_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"stopping") do |vm|
vm.stop
end
end
end
suspend_desc = <<-EOT.unindent
Saves a running VM. It is the same as 'onevm stop', but the files
are left in the remote machine to later restart the VM there
(i.e. the resources are not freed and there is no need to
re-schedule the VM).
States: RUNNING
EOT
command :suspend, suspend_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"suspending") do |vm|
vm.suspend
end
end
end
resume_desc = <<-EOT.unindent
Resumes the execution of the a saved VM
States: STOPPED, SUSPENDED, UNDEPLOYED, POWEROFF
EOT
command :resume, resume_desc, [:range,:vmid_list],
:options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"resuming") do |vm|
vm.resume
end
end
end
recover_desc = <<-EOT.unindent
Recovers a stuck VM that is waiting for a driver operation. The recovery
may be done by failing or succeeding the pending operation. YOU NEED
TO MANUALLY CHECK THE VM STATUS ON THE HOST, to decide if the operation
was successful or not.
Example: A VM is stuck in "migrate" because of a hardware failure. You
need to check if the VM is running in the new host or not to recover
the vm with --success or --failure, respectively.
States: Any ACTIVE state.
EOT
command :recover, recover_desc, [:range,:vmid_list],
:options => [SUCCESS, FAILURE] do
if !options[:success].nil?
result = true
elsif !options[:failure].nil?
result = false
else
STDERR.puts "Need to specify the result of the pending action."
STDERR.puts "\t--success recover the VM by succeeding the missing action."
STDERR.puts "\t--failure recover the VM by failing the missing action."
exit -1
end
helper.perform_actions(args[0], options, "recovering") do |vm|
vm.recover(result)
end
end
disk_attach_desc = <<-EOT.unindent
Attaches a disk to a running VM. When using --file add only one
DISK instance.
States: RUNNING
EOT
command :"disk-attach", disk_attach_desc, :vmid,
:options => [OneVMHelper::FILE, OneVMHelper::IMAGE,
TARGET, CACHE] do
if options[:file].nil? and options[:image].nil?
STDERR.puts "Provide a template file or an image:"
STDERR.puts "\t--file <file>"
STDERR.puts "\t--image <image>"
exit -1
end
if options[:file]
template = File.read(options[:file])
else
image_id = options[:image]
target = options[:target]
if target
template =
"DISK = [ IMAGE_ID = #{image_id}, TARGET = #{target}"
else
template =
"DISK = [ IMAGE_ID = #{image_id}, DEV_PREFIX = sd"
end
if options[:cache]
template<<", CACHE = \"#{options[:cache]}\""
end
template << " ]"
end
helper.perform_action(args[0],options,"Attach disk") do |vm|
vm.disk_attach(template)
end
end
disk_detach_desc = <<-EOT.unindent
Detaches a disk from a running VM
States: RUNNING
EOT
command :"disk-detach", disk_detach_desc, :vmid, :diskid do
diskid = args[1].to_i
helper.perform_action(args[0],options,"Detach disk") do |vm|
vm.disk_detach(diskid)
end
end
nic_attach_desc = <<-EOT.unindent
Attaches a NIC to a running VM. When using --file add only one
NIC instance.
States: RUNNING
EOT
command :"nic-attach", nic_attach_desc, :vmid,
:options => [OneVMHelper::FILE, OneVMHelper::NETWORK, IP] do
if options[:file].nil? and options[:network].nil?
STDERR.puts "Provide a template file or a network:"
STDERR.puts "\t--file <file>"
STDERR.puts "\t--network <network>"
exit -1
end
if options[:file]
template = File.read(options[:file])
else
network_id = options[:network]
ip = options[:ip]
if ip
template = "NIC = [ NETWORK_ID = #{network_id}, IP = #{ip} ]"
else
template = "NIC = [ NETWORK_ID = #{network_id} ]"
end
end
helper.perform_action(args[0],options,"Attach NIC") do |vm|
vm.nic_attach(template)
end
end
nic_detach_desc = <<-EOT.unindent
Detaches a NIC from a running VM
States: RUNNING
EOT
command :"nic-detach", nic_detach_desc, :vmid, :nicid do
nicid = args[1].to_i
helper.perform_action(args[0],options,"Detach NIC") do |vm|
vm.nic_detach(nicid)
end
end
chgrp_desc = <<-EOT.unindent
Changes the VM group
EOT
command :chgrp, chgrp_desc,[:range, :vmid_list], :groupid do
helper.perform_actions(args[0],options,"Group changed") do |vm|
vm.chown(-1, args[1].to_i)
end
end
chown_desc = <<-EOT.unindent
Changes the VM owner and group
EOT
command :chown, chown_desc, [:range, :vmid_list], :userid,
[:groupid,nil] do
gid = args[2].nil? ? -1 : args[2].to_i
helper.perform_actions(args[0],options,"Owner/Group changed") do |vm|
vm.chown(args[1].to_i, gid)
end
end
chmod_desc = <<-EOT.unindent
Changes the VM permissions
EOT
command :chmod, chmod_desc, [:range, :vmid_list], :octet do
helper.perform_actions(args[0],options, "Permissions changed") do |vm|
vm.chmod_octet(args[1])
end
end
resched_desc = <<-EOT.unindent
Sets the rescheduling flag for the VM.
States: RUNNING
EOT
command :resched, resched_desc, [:range,:vmid_list] do
helper.perform_actions(args[0],options,"Setting resched flag") do |vm|
vm.resched
end
end
unresched_desc = <<-EOT.unindent
Clears the rescheduling flag for the VM.
States: RUNNING
EOT
command :unresched, unresched_desc, [:range,:vmid_list] do
helper.perform_actions(args[0],options,"Clearing resched flag") do |vm|
vm.unresched
end
end
rename_desc = <<-EOT.unindent
Renames the VM
EOT
command :rename, rename_desc, :vmid, :name do
helper.perform_action(args[0],options,"renamed") do |o|
o.rename(args[1])
end
end
# TODO: Write a more complete description:
# what is a snapshot (system snapshot)
# how to revert to a snapshot
snapshot_create_desc = <<-EOT.unindent
Creates a new VM snapshot
EOT
command :"snapshot-create", snapshot_create_desc, [:range,:vmid_list],
[:name, nil], :options => [OneVMHelper::SCHEDULE] do
if (!options[:schedule].nil?)
helper.schedule_actions(args[0], options, @comm_name)
else
helper.perform_actions(args[0],options,"snapshot created") do |o|
o.snapshot_create(args[1])
end
end
end
# TODO: Write a more complete description:
snapshot_revert_desc = <<-EOT.unindent
Reverts a VM to a saved snapshot
EOT
command :"snapshot-revert", snapshot_revert_desc, :vmid, :snapshot_id do
helper.perform_action(args[0],options,"snapshot reverted") do |o|
o.snapshot_revert(args[1].to_i)
end
end
# TODO: Write a more complete description:
snapshot_delete_desc = <<-EOT.unindent
Delets a snapshot of a VM
EOT
command :"snapshot-delete", snapshot_delete_desc, :vmid, :snapshot_id do
helper.perform_action(args[0],options,"snapshot deleted") do |o|
o.snapshot_delete(args[1].to_i)
end
end
list_desc = <<-EOT.unindent
Lists VMs in the pool
EOT
command :list, list_desc, [:filterflag, nil],
:options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
[OpenNebulaHelper::DESCRIBE] do
helper.list_pool(options, false, args[0])
end
show_desc = <<-EOT.unindent
Shows information for the given VM
EOT
command :show, show_desc, :vmid,
:options=>[OpenNebulaHelper::XML, OneVMHelper::ALL_TEMPLATE] do
helper.show_resource(args[0],options)
end
top_desc = <<-EOT.unindent
Lists Images continuously
EOT
command :top, top_desc, [:filterflag, nil],
:options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
helper.list_pool(options, true, args[0])
end
resize_desc = <<-EOT.unindent
Resizes the capacity of a Virtual Machine (offline, the VM cannot be
RUNNING)
EOT
command :resize, resize_desc, :vmid, :options =>
OpenNebulaHelper::CAPACITY_OPTIONS_VM + [ENFORCE, OneVMHelper::FILE] do
if options[:file]
template = File.read(options[:file])
else
template = ""
if !options[:cpu].nil?
template << "CPU = #{options[:cpu]}\n"
end
if !options[:vcpu].nil?
template << "VCPU = #{options[:vcpu]}\n"
end
if !options[:memory].nil?
template << "MEMORY = #{options[:memory]}\n"
end
end
enforce = options[:enforce] || false
helper.perform_action(args[0], options, "Resizing VM") do |vm|
vm.resize(template, enforce)
end
end
# Deprecated commands
deprecated_command(:attachdisk, 'disk-attach')
deprecated_command(:detachdisk, 'disk-detach')
deprecated_command(:saveas, 'disk-snapshot')
deprecated_command(:livemigrate, 'migrate --live')
deprecated_command(:cancel, 'shutdown --hard')
deprecated_command(:reset, 'reboot --hard')
deprecated_command(:restart, 'boot')
deprecated_command(:resubmit, 'delete --recreate')
end
|