Class: Fog::Compute::Openvz::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Openvz::Real
- Defined in:
- lib/fog/openvz/compute.rb,
lib/fog/openvz/requests/compute/set_server.rb,
lib/fog/openvz/requests/compute/exec_server.rb,
lib/fog/openvz/requests/compute/stop_server.rb,
lib/fog/openvz/requests/compute/exec2_server.rb,
lib/fog/openvz/requests/compute/list_servers.rb,
lib/fog/openvz/requests/compute/mount_server.rb,
lib/fog/openvz/requests/compute/start_server.rb,
lib/fog/openvz/requests/compute/create_server.rb,
lib/fog/openvz/requests/compute/resume_server.rb,
lib/fog/openvz/requests/compute/status_server.rb,
lib/fog/openvz/requests/compute/umount_server.rb,
lib/fog/openvz/requests/compute/compact_server.rb,
lib/fog/openvz/requests/compute/convert_server.rb,
lib/fog/openvz/requests/compute/destroy_server.rb,
lib/fog/openvz/requests/compute/quotaon_server.rb,
lib/fog/openvz/requests/compute/restart_server.rb,
lib/fog/openvz/requests/compute/suspend_server.rb,
lib/fog/openvz/requests/compute/quotaoff_server.rb,
lib/fog/openvz/requests/compute/snapshot_server.rb,
lib/fog/openvz/requests/compute/quotainit_server.rb,
lib/fog/openvz/requests/compute/runscript_server.rb,
lib/fog/openvz/requests/compute/get_server_details.rb,
lib/fog/openvz/requests/compute/snapshot_list_server.rb,
lib/fog/openvz/requests/compute/snapshot_mount_server.rb,
lib/fog/openvz/requests/compute/snapshot_delete_server.rb,
lib/fog/openvz/requests/compute/snapshot_switch_server.rb,
lib/fog/openvz/requests/compute/snapshot_umount_server.rb
Instance Method Summary collapse
- #compact_server(id, options = {}) ⇒ Object
- #convert_server(id, options = {}) ⇒ Object
- #create_server(options = {}) ⇒ Object
- #destroy_server(id, options = {}) ⇒ Object
- #exec2_server(id, args) ⇒ Object
- #exec_server(id, args = []) ⇒ Object
- #expand_commands(commands, params, args) ⇒ Object
- #get_server_details(id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_servers(options = {}) ⇒ Object
- #mount_server(id, options = {}) ⇒ Object
- #quotainit_server(id, options = {}) ⇒ Object
- #quotaon_server(id, options = {}) ⇒ Object
- #quotaooff_server(id, options = {}) ⇒ Object
- #reload ⇒ Object
- #restart_server(id, options = {}) ⇒ Object
- #resume_server(id, options = {}) ⇒ Object
- #runscript_server(id, args = []) ⇒ Object
- #set_server(id, options = {}) ⇒ Object
- #snapshot_delete_server(id, options = {}) ⇒ Object
- #snapshot_list_server(id, options = {}) ⇒ Object
- #snapshot_mount_server(id, options = {}) ⇒ Object
- #snapshot_server(id, options = {}) ⇒ Object
- #snapshot_switch_server(id, options = {}) ⇒ Object
- #snapshot_umount_server(id, options = {}) ⇒ Object
- #start_server(id, options = {}) ⇒ Object
- #status_server(id, options = {}) ⇒ Object
- #stop_server(id, options = {}) ⇒ Object
- #suspend_server(id, options = {}) ⇒ Object
- #umount_server(id, options = {}) ⇒ Object
- #vzctl(command, params, args = []) ⇒ Object
- #vzlist(params, args = []) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
69 70 71 |
# File 'lib/fog/openvz/compute.rb', line 69 def initialize(={}) @openvz_connect_command = [:openvz_connect_command] end |
Instance Method Details
#compact_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/compact_server.rb', line 5 def compact_server(id, = {}) vzctl("compact",{:ctid => id}.merge()) end |
#convert_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/convert_server.rb', line 5 def convert_server(id, = {}) vzctl("convert",{:ctid => id}.merge()) end |
#create_server(options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/create_server.rb', line 5 def create_server( = {}) vzctl("create",) end |
#destroy_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/destroy_server.rb', line 5 def destroy_server(id, = {}) vzctl("destroy",{:ctid => id}.merge()) end |
#exec2_server(id, args) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/exec2_server.rb', line 5 def exec2_server(id,args) vzctl("exec2",{:ctid => id},args) end |
#exec_server(id, args = []) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/exec_server.rb', line 5 def exec_server(id,args = []) vzctl("exec",{:ctid => id},args) end |
#expand_commands(commands, params, args) ⇒ Object
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 |
# File 'lib/fog/openvz/compute.rb', line 77 def (commands, params, args) # For all params unless the ctid # pass it to the command params.keys.each do |k| if (params[k]) && (k.to_s != 'ctid') if params[k].is_a?(Array) # For arrays we pass the params and key multiple times params[k].each do |p| commands << "--#{k}" commands << "\"#{p}\"" end else commands << "--#{k}" # For booleans only pass the options # We put the values of params between doublequotes commands << "\"#{params[k]}\"" unless !!params[k] == params[k] end end end # These commands will be passed directly args.each do |a| commands << a end # Delete empty commands commands.delete("") # Now build the full command full_command = "#{commands.join(' ')}" # If we have a connect command , expand it 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) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/get_server_details.rb', line 5 def get_server_details(id) vzlist({:ctid => id}).first end |
#list_servers(options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/list_servers.rb', line 5 def list_servers( = {}) vzlist({}) end |
#mount_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/mount_server.rb', line 5 def mount_server(id, = {}) vzctl("mount",{:ctid => id}.merge()) end |
#quotainit_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/quotainit_server.rb', line 5 def quotainit_server(id, = {}) vzctl("quotainit",{:ctid => id}.merge()) end |
#quotaon_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/quotaon_server.rb', line 5 def quotaon_server(id, = {}) vzctl("quotaon",{:ctid => id}.merge()) end |
#quotaooff_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/quotaoff_server.rb', line 5 def quotaooff_server(id, = {}) vzctl("quotaoff",{:ctid => id}.merge()) end |
#reload ⇒ Object
73 74 75 |
# File 'lib/fog/openvz/compute.rb', line 73 def reload #@connection.reset end |
#restart_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/restart_server.rb', line 5 def restart_server(id, = {}) vzctl("restart",{:ctid => id}.merge()) end |
#resume_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/resume_server.rb', line 5 def resume_server(id, = {}) vzctl("resume",{:ctid => id}.merge()) end |
#runscript_server(id, args = []) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/runscript_server.rb', line 5 def runscript_server(id,args = []) vzctl("runscript",{:ctid => id},args) end |
#set_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/set_server.rb', line 5 def set_server(id, = {}) vzctl("set",{:ctid => id}.merge()) end |
#snapshot_delete_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_delete_server.rb', line 5 def snapshot_delete_server(id, = {}) vzctl("snapshot-delete",{:ctid => id}.merge()) end |
#snapshot_list_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_list_server.rb', line 5 def snapshot_list_server(id, = {}) vzctl("snapshot-list",{:ctid => id}.merge()) end |
#snapshot_mount_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_mount_server.rb', line 5 def snapshot_mount_server(id, = {}) vzctl("snapshot-mount",{:ctid => id}.merge()) end |
#snapshot_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_server.rb', line 5 def snapshot_server(id, = {}) vzctl("snapshot",{:ctid => id}.merge()) end |
#snapshot_switch_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_switch_server.rb', line 5 def snapshot_switch_server(id, = {}) vzctl("snapshot-switch",{:ctid => id}.merge()) end |
#snapshot_umount_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/snapshot_umount_server.rb', line 5 def snapshot_umount_server(id, = {}) vzctl("snapshot-umount",{:ctid => id}.merge()) end |
#start_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/start_server.rb', line 5 def start_server(id,={}) vzctl("start",{:ctid => id}.merge()) end |
#status_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/status_server.rb', line 5 def status_server(id, = {}) vzctl("status",{:ctid => id}.merge()) end |
#stop_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/stop_server.rb', line 5 def stop_server(id, = {}) vzctl("stop",{:ctid => id}.merge()) end |
#suspend_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/suspend_server.rb', line 5 def suspend_server(id, = {}) vzctl("suspend",{:ctid => id}.merge()) end |
#umount_server(id, options = {}) ⇒ Object
5 6 7 |
# File 'lib/fog/openvz/requests/compute/umount_server.rb', line 5 def umount_server(id, = {}) vzctl("umount",{:ctid => id}.merge()) end |
#vzctl(command, params, args = []) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fog/openvz/compute.rb', line 119 def vzctl(command, params,args = []) commands = [ 'vzctl', command, params['ctid'], params[:ctid] ] prefixed_command = (commands, params, args) result = `#{prefixed_command}` exitcode = $?.to_i # Tofix - we use backticks to get the exitcode # But backticks output stderr 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 = []) ⇒ Object
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 |
# File 'lib/fog/openvz/compute.rb', line 137 def vzlist(params,args = []) commands = [ 'vzlist', '-a', '-j' , params['ctid'], params[:ctid] ] prefixed_command = (commands, params, args) # We do some wier stuff here: # - a simple backtick doesn't capture stderr # - popen4 would solve it but would require another external gem dependency # - popen3 doesn't capture exitcode (on ruby 1.8) but is a standard call # - so we resort to checking the stderr instead 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 |