mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
Feature #1223: Add OCA and CLI for onevm attach and onevm detach
This commit is contained in:
parent
6e44c6ebf3
commit
e2927e871a
src
@ -405,6 +405,10 @@ EOT
|
||||
arg.instance_of?(String) ? [0,arg] : [-1]
|
||||
end
|
||||
|
||||
def format_int(arg)
|
||||
arg.match(/^\d+$/) ? [0,arg] : [-1]
|
||||
end
|
||||
|
||||
def format_file(arg)
|
||||
File.file?(arg) ? [0,arg] : [-1]
|
||||
end
|
||||
|
@ -25,6 +25,24 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
:description => "Instance multiple VMs"
|
||||
}
|
||||
|
||||
IMAGE = {
|
||||
:name => "image",
|
||||
:short => "-i id|name",
|
||||
:large => "--image id|name" ,
|
||||
:description => "Selects the image",
|
||||
:format => String,
|
||||
:proc => lambda { |o, options|
|
||||
rc, imid = OpenNebulaHelper.rname_to_id(o, "IMAGE")
|
||||
if rc == 0
|
||||
options[:image] = imid
|
||||
else
|
||||
puts imid
|
||||
puts "option image: Parsing error"
|
||||
exit -1
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
def self.rname
|
||||
"VM"
|
||||
end
|
||||
|
@ -77,6 +77,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
set :format, :diskid, "Integer" do |arg|
|
||||
format_int(arg)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Commands
|
||||
########################################################################
|
||||
@ -206,7 +210,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
vm.reset
|
||||
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
|
||||
@ -334,6 +338,49 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
attachdisk_desc = <<-EOT.unindent
|
||||
Attaches a disk to a running VM
|
||||
|
||||
States: RUNNING
|
||||
EOT
|
||||
|
||||
command :attachdisk, attachdisk_desc, :vmid, [:file, nil], :options => OneVMHelper::IMAGE do
|
||||
|
||||
template_file = args[1]
|
||||
|
||||
if template_file.nil? and options[:image].nil?
|
||||
STDERR.puts "Provide a template file or an image:"
|
||||
STDERR.puts "\t<template_file>"
|
||||
STDERR.puts "\t--image <image>"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if template_file.nil?
|
||||
image_id = options[:image]
|
||||
template = "DISK = [ IMAGE_ID = #{image_id} ]"
|
||||
else
|
||||
template = File.read(template_file)
|
||||
end
|
||||
|
||||
helper.perform_action(args[0],options,"Attach disk") do |vm|
|
||||
vm.attachdisk(template)
|
||||
end
|
||||
end
|
||||
|
||||
detachdisk_desc = <<-EOT.unindent
|
||||
Detaches a disk from a running VM
|
||||
|
||||
States: RUNNING
|
||||
EOT
|
||||
|
||||
command :detachdisk, detachdisk_desc, :vmid, :diskid do
|
||||
diskid = args[1].to_i
|
||||
|
||||
helper.perform_action(args[0],options,"Detach disk") do |vm|
|
||||
vm.detachdisk(diskid)
|
||||
end
|
||||
end
|
||||
|
||||
chgrp_desc = <<-EOT.unindent
|
||||
Changes the VM group
|
||||
EOT
|
||||
@ -367,7 +414,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
resched_desc = <<-EOT.unindent
|
||||
Sets the rescheduling flag for the VM.
|
||||
Sets the rescheduling flag for the VM.
|
||||
|
||||
States: RUNNING
|
||||
EOT
|
||||
@ -379,7 +426,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
unresched_desc = <<-EOT.unindent
|
||||
Clears the rescheduling flag for the VM.
|
||||
Clears the rescheduling flag for the VM.
|
||||
|
||||
States: RUNNING
|
||||
EOT
|
||||
|
@ -33,7 +33,9 @@ module OpenNebula
|
||||
:savedisk => "vm.savedisk",
|
||||
:chown => "vm.chown",
|
||||
:chmod => "vm.chmod",
|
||||
:monitoring => "vm.monitoring"
|
||||
:monitoring => "vm.monitoring",
|
||||
:attach => "vm.attach",
|
||||
:detach => "vm.detach"
|
||||
}
|
||||
|
||||
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
|
||||
@ -154,7 +156,7 @@ module OpenNebula
|
||||
def reset
|
||||
action('reset')
|
||||
end
|
||||
|
||||
|
||||
# Cancels a running VM
|
||||
def cancel
|
||||
action('cancel')
|
||||
@ -185,6 +187,26 @@ module OpenNebula
|
||||
action('resume')
|
||||
end
|
||||
|
||||
# Attaches a disk to a running VM
|
||||
def attachdisk(disk)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(VM_METHODS[:attach], @pe_id, disk)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
# Detaches a disk from a running VM
|
||||
def detachdisk(disk)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(VM_METHODS[:detach], @pe_id, disk)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
# Deletes a VM from the pool
|
||||
def finalize
|
||||
action('finalize')
|
||||
@ -291,7 +313,7 @@ module OpenNebula
|
||||
# @example
|
||||
# vm.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
|
||||
#
|
||||
# { "NET_TX" =>
|
||||
# { "NET_TX" =>
|
||||
# [["1337264510", "210"],
|
||||
# ["1337264553", "220"],
|
||||
# ["1337264584", "230"]],
|
||||
|
Loading…
x
Reference in New Issue
Block a user