#!/usr/bin/ruby # Ruby script that connects to a VMware vRO server and kicks off a snapshot # on a pre-defined vSphere VM. Could easily be extended to take an argument # to get the VM. # # Written by Chris Adams, @virtualchris813 # Written on 14 May 2016 # require 'rest-client' require 'openssl' require 'date' username = "vcoadmin" password = "vcoadmin" id = "BD80808080808080808080808080808053C180800122528313869552e41805bb1" vm = "vm-43" vcenter = "vcenter6.linuxchris.labnet" server = "vro.linuxchris.labnet" port = "8281" apiuri = "/vco/api" @debug = false def buildUrl(username, password, server, port, apiuri, id) # URL used to connect to the v(C)RO server @url = "https://#{username}:#{password}@#{server}:#{port}#{apiuri}/workflows/#{id}/executions/" puts "#{@url}" if @debug end def buildXml(vm, vcenter) # Get current date/time so we can use it in the snapshot name date = DateTime.now() d = date.strftime("%Y%m%d-%H%M%S") # Create the XML used to define the snapshot @message = %Q( snap_from_api_#{d} false false ) puts "Message is: #{@message}" if @debug end buildUrl(username, password, server, port, apiuri, id) buildXml(vm, vcenter) client = RestClient::Resource.new(@url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :accept => 'application/xml', :content_type => 'application/xml') result = client.post "#{@message}", :content_type => 'application/xml'