# Description The openvz provider implements a simple mapping between openvz commands and fog # Usage ## Establish a connection openvz = ::Fog::Compute.new( {:provider => 'openvz'}) Additional option is **:openvz_connect_command**: It allows you to specify connect command to connect to the openvz server, if it's not localhost. - This is specified as a string where the '@command@' placeholder will be replaced when the commands are executed - The @command@ will contain double quotes, therefore make sure you use single quotes only inside the placeholder To connect to a remote ssh server myopenvzserver and sudo excute the command openvz = ::Fog::Compute.new( { :provider => 'openvz', :openvz_connect_command => "ssh myopenvzserver 'sudo @command'" }) ## List servers openvz = ::Fog::Compute.new( {:provider => 'openvz'}) servers = openvz.servers.all servers.each do |s| puts c.ctid end ## Server Unique id Servers have the ctid as identity. ## Get a specific server openvz = ::Fog::Compute.new( {:provider => 'openvz'}) server = openvz.servers.get(104) ## Server lifecycle openvz = ::Fog::Compute.new( {:provider => 'openvz'}) # Create a server server = openvz.servers.create( :ctid => '104', :ostemplate => 'ubuntu-12.04-x86_64', :diskspace => 1024*1024 #in kbyte ) server.reload # Start a server unless server.status == 'running' server.start end server.set({ :nameserver => '8.8.8.8', :ipadd => '192.168.8.10', :ram => '380M', :hostname => 'wonderfullserver', :name => 'chef', :description => 'wonderfullserver', :save => true }) # Reboot a server server.reboot sleep 3 # Get the ipaddress puts "ipaddress: #{server.public_ip_address}" server.wait_for { status == 'running' } # Stop the server server.stop # Destroy the server server.destroy ## Models Both compute::server and computer::servers (collections) have been implemented Note: - server.save can only be called upon creation, use the server.set command to change the settings - server.public_ip_address will only return the first ip address - TODO: snapshots could be implemented as a collection - server.state has the standard openvz states. - server.ready? assumes server.status == 'running' ## Requests ### Passing parameters The server request are in essence a passthrough to __vzctl__. Just provide the options as a hash in key,value pairs. If it's just a switch (like --save), use a key and a boolean(true). The following command in plain cli-vzctl: vzctl set 104 --nameserver 8.8.8.8 --ipadd 192.168.8.10 --ram '380M' Would be in fog-speak: server = openvz.servers.get(104) server.set({ :nameserver => '8.8.8.8', :ipadd => '192.168.8.10', :ram => '380M', :save => true }) To specify multiple values for the same option pass an array server.set({ :nameserver => ['8.8.8.8','7.7.7.7'], :ipadd => ['192.168.8.10','192.168.4.10'], :ram => '380M', :save => true }) ### Passing arguments both exec, exec2 and runscript take no parameters just arguments server = openvz.servers.get(104) uname_output = server.exec("uname -a") ### Not implemented From all the options to vzctl (see below) the following commands have **NOT** been implemented: - console : as it requires direct input ## VZCTL commands the current version of the fog openvz driver is based on the following vzctl syntax vzctl version 4.3 Copyright (C) 2000-2012, Parallels, Inc. This program may be distributed under the terms of the GNU GPL License. Usage: vzctl [options] [parameters] vzctl create [--ostemplate ] [--config ] [--layout ploop|simfs] [--hostname ] [--name ] [--ipadd ] [--diskspace ] [--private ] [--root ] [--local_uid ] [--local_gid ] vzctl start [--force] [--wait] vzctl destroy | mount | umount | stop | restart | status vzctl convert [--layout ploop[:mode]] [--diskspace ] vzctl compact vzctl snapshot [--id ] [--name ] [--description ] [--skip-suspend] vzctl snapshot-switch | snapshot-delete --id vzctl snapshot-mount --id --target vzctl snapshot-umount --id vzctl snapshot-list [-H] [-o field[,field...]] [--id ] vzctl quotaon | quotaoff | quotainit vzctl console [ttyno] vzctl enter [--exec [arg ...]] vzctl exec | exec2 [arg ...] vzctl runscript