compact_server(id,options = {})
click to toggle source
def compact_server(id,options = {})
vzctl("compact",{:ctid => id}.merge(options))
end
convert_server(id,options = {})
click to toggle source
def convert_server(id,options = {})
vzctl("convert",{:ctid => id}.merge(options))
end
create_server(options = {})
click to toggle source
def create_server(options = {})
vzctl("create",options)
end
destroy_server(id, options = {})
click to toggle source
def destroy_server(id, options = {})
vzctl("destroy",{:ctid => id}.merge(options))
end
exec2_server(id,args)
click to toggle source
def exec2_server(id,args)
vzctl("exec2",{:ctid => id},args)
end
exec_server(id,args = [])
click to toggle source
def exec_server(id,args = [])
vzctl("exec",{:ctid => id},args)
end
expand_commands(commands, params, args)
click to toggle source
def expand_commands(commands, params, args)
params.keys.each do |k|
if (params[k]) && (k.to_s != 'ctid')
if params[k].is_a?(Array)
params[k].each do |p|
commands << "--#{k}"
commands << "\"#{p}\""
end
else
commands << "--#{k}"
commands << "\"#{params[k]}\"" unless !!params[k] == params[k]
end
end
end
args.each do |a|
commands << a
end
commands.delete("")
full_command = "#{commands.join(' ')}"
if @openvz_connect_command.nil?
prefixed_command = "#{full_command}"
else
prefixed_command = @openvz_connect_command.sub('@command@',"#{full_command}")
end
return prefixed_command
end
get_server_details(id)
click to toggle source
def get_server_details(id)
vzlist({:ctid => id}).first
end
list_servers(options = {})
click to toggle source
def list_servers(options = {})
vzlist({})
end
mount_server(id, options = {})
click to toggle source
def mount_server(id, options = {})
vzctl("mount",{:ctid => id}.merge(options))
end
quotainit_server(id, options = {})
click to toggle source
def quotainit_server(id, options = {})
vzctl("quotainit",{:ctid => id}.merge(options))
end
quotaon_server(id, options = {})
click to toggle source
def quotaon_server(id, options = {})
vzctl("quotaon",{:ctid => id}.merge(options))
end
quotaooff_server(id, options = {})
click to toggle source
def quotaooff_server(id, options = {})
vzctl("quotaoff",{:ctid => id}.merge(options))
end
reload()
click to toggle source
restart_server(id, options = {})
click to toggle source
def restart_server(id, options = {})
vzctl("restart",{:ctid => id}.merge(options))
end
resume_server(id, options = {})
click to toggle source
def resume_server(id, options = {})
vzctl("resume",{:ctid => id}.merge(options))
end
runscript_server(id,args = [])
click to toggle source
def runscript_server(id,args = [])
vzctl("runscript",{:ctid => id},args)
end
set_server(id,options = {})
click to toggle source
def set_server(id,options = {})
vzctl("set",{:ctid => id}.merge(options))
end
snapshot_delete_server(id,options = {})
click to toggle source
def snapshot_delete_server(id,options = {})
vzctl("snapshot-delete",{:ctid => id}.merge(options))
end
snapshot_list_server(id,options = {})
click to toggle source
def snapshot_list_server(id,options = {})
vzctl("snapshot-list",{:ctid => id}.merge(options))
end
snapshot_mount_server(id,options = {})
click to toggle source
def snapshot_mount_server(id,options = {})
vzctl("snapshot-mount",{:ctid => id}.merge(options))
end
snapshot_server(id,options = {})
click to toggle source
def snapshot_server(id,options = {})
vzctl("snapshot",{:ctid => id}.merge(options))
end
snapshot_switch_server(id,options = {})
click to toggle source
def snapshot_switch_server(id,options = {})
vzctl("snapshot-switch",{:ctid => id}.merge(options))
end
snapshot_umount_server(id,options = {})
click to toggle source
def snapshot_umount_server(id,options = {})
vzctl("snapshot-umount",{:ctid => id}.merge(options))
end
start_server(id,options={})
click to toggle source
def start_server(id,options={})
vzctl("start",{:ctid => id}.merge(options))
end
status_server(id, options = {})
click to toggle source
def status_server(id, options = {})
vzctl("status",{:ctid => id}.merge(options))
end
stop_server(id, options = {})
click to toggle source
def stop_server(id, options = {})
vzctl("stop",{:ctid => id}.merge(options))
end
suspend_server(id, options = {})
click to toggle source
def suspend_server(id, options = {})
vzctl("suspend",{:ctid => id}.merge(options))
end
umount_server(id, options = {})
click to toggle source
def umount_server(id, options = {})
vzctl("umount",{:ctid => id}.merge(options))
end
vzctl(command, params,args = [])
click to toggle source
def vzctl(command, params,args = [])
commands = [ 'vzctl', command, params['ctid'], params[:ctid] ]
prefixed_command = expand_commands(commands, params, args)
result = %x#{prefixed_command}`
exitcode = $?.to_i
arg_commands = [ 'exec', 'exec2', 'runscript' ]
if (arg_commands.include?(command))
return { :output => result , :exitcode => exitcode }
else
raise Fog::Errors::Error.new result unless exitcode == 0
return result
end
end
vzlist(params,args = [])
click to toggle source
def vzlist(params,args = [])
commands = [ 'vzlist', '-a', '-j' , params['ctid'], params[:ctid] ]
prefixed_command = expand_commands(commands, params, args)
require 'open3'
result = ""
error = ""
puts prefixed_command
Open3.popen3("#{prefixed_command}") { |i,o,e,t|
result = result + o.read
error = error + e.read
}
if (error.length != 0)
if(error.include?("not found"))
return []
else
raise Fog::Errors::Error.new error
end
else
return Fog::JSON.decode(result)
end
end