mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
Deleting vmi directory
git-svn-id: http://svn.opennebula.org/one/trunk@782 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
d6600e2495
commit
fc85c54245
@ -1,6 +0,0 @@
|
||||
require 'lib/VirtualMachineVMI'
|
||||
require 'lib/VirtualMachinePoolVMI'
|
||||
require 'lib/VirtualNetworkVMI'
|
||||
require 'lib/VirtualNetworkPoolVMI'
|
||||
|
||||
require 'lib/VMIConfiguration'
|
@ -1,441 +0,0 @@
|
||||
################################################
|
||||
# Find out where the needed ruby libraries are
|
||||
################################################
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
################################################
|
||||
# Required libraries
|
||||
################################################
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'time'
|
||||
require 'pp'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'VMI'
|
||||
|
||||
|
||||
include OpenNebula
|
||||
|
||||
CONFIG=VMIConfiguration.new(CONF_LOCATION+'/vmi-server.conf')
|
||||
AUTH="#{CONFIG[:user]}:#{CONFIG[:password]}"
|
||||
ONE_RM_DATABASE=CONFIG[:database]
|
||||
|
||||
# Load Repository Manager here to use ONE_RM_DATABASE from the configuration file
|
||||
require 'repo_manager'
|
||||
Image.image_dir=CONFIG[:image_dir]
|
||||
|
||||
INSTANCE_TYPES=Hash.new
|
||||
|
||||
puts "######################################"
|
||||
puts " VMI Server configuration "
|
||||
puts "######################################"
|
||||
puts "---------8<---------------------"
|
||||
pp CONFIG
|
||||
puts "------>8------------------------"
|
||||
|
||||
if CONFIG[:vm_type].kind_of?(Array)
|
||||
# Multiple instance types
|
||||
CONFIG[:vm_type].each {|type|
|
||||
INSTANCE_TYPES[type['NAME']]=type
|
||||
}
|
||||
else
|
||||
# When only one instance type is defined
|
||||
INSTANCE_TYPES[CONFIG[:vm_type]['NAME']]=CONFIG[:vm_type]
|
||||
end
|
||||
|
||||
puts "######################################"
|
||||
puts " VMI Available Instances Types "
|
||||
puts "######################################"
|
||||
puts "---------8<---------------------"
|
||||
pp INSTANCE_TYPES
|
||||
puts "------>8------------------------"
|
||||
|
||||
set :host, CONFIG[:server]
|
||||
set :port, CONFIG[:port]
|
||||
|
||||
# Start repository manager
|
||||
$repoman=RepoManager.new
|
||||
|
||||
################################################
|
||||
# Client builders for ONE communication
|
||||
################################################
|
||||
|
||||
def get_one_client
|
||||
Client.new(AUTH)
|
||||
end
|
||||
|
||||
def get_one_client_user(user_name)
|
||||
user=get_user(user_name)
|
||||
|
||||
|
||||
auth="#{user[:name]}:#{user[:password]}"
|
||||
|
||||
client=Client.new("dummy:dummy")
|
||||
client.one_auth=auth
|
||||
client
|
||||
end
|
||||
|
||||
def get_user(name)
|
||||
user=nil
|
||||
|
||||
user_pool=UserPool.new(get_one_client)
|
||||
user_pool.info
|
||||
user_pool.each{|u|
|
||||
if u.name==name
|
||||
user=Hash.new
|
||||
user[:id]=u.id
|
||||
user[:name]=u.name
|
||||
user[:password]=u[:password]
|
||||
end
|
||||
}
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Helpers to manage authentication & authorization
|
||||
###################################################
|
||||
|
||||
|
||||
helpers do
|
||||
|
||||
def protected!
|
||||
response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") and \
|
||||
throw(:halt, [401, "Not authorized\n"]) and \
|
||||
return unless authorized?
|
||||
end
|
||||
|
||||
def authorized?
|
||||
|
||||
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
||||
|
||||
if !(@auth.provided? && @auth.basic? && @auth.credentials)
|
||||
return false
|
||||
end
|
||||
|
||||
user = get_user(@auth.credentials.first)
|
||||
|
||||
if user
|
||||
if user[:password] == @auth.credentials[1]
|
||||
return true
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Helper functions
|
||||
###################################################
|
||||
|
||||
|
||||
def submit_vm(params)
|
||||
|
||||
if params['vmixml']
|
||||
@vm_info=Crack::XML.parse(params['vmixml'])
|
||||
else
|
||||
halt 400, "VMI XML representation of VM not present"
|
||||
end
|
||||
|
||||
@vm_info=@vm_info['VM']
|
||||
|
||||
if @vm_info['DISKS'].class==Array
|
||||
disks=@vm_info['DISKS']
|
||||
else
|
||||
disks=[@vm_info['DISKS']]
|
||||
end
|
||||
|
||||
disks.each{|disk|
|
||||
next if disk['DISK']==nil
|
||||
image=$repoman.get(disk['DISK']['image'])
|
||||
disk['DISK']['source']=image.path
|
||||
}
|
||||
|
||||
@vm_info['DISKS']=disks[0]
|
||||
|
||||
|
||||
if @vm_info['NICS']['NIC'].class==Array
|
||||
nics=@vm_info['NICS']['NIC']
|
||||
else
|
||||
nics=[@vm_info['NICS']['NIC']]
|
||||
end
|
||||
|
||||
nics.each{|nic|
|
||||
vn=VirtualNetwork.new(VirtualNetwork.build_xml(nic['network']), get_one_client)
|
||||
vn.info
|
||||
vn_xml=Crack::XML.parse(vn.to_xml)
|
||||
nic['network_id']=nic['network']
|
||||
nic['network']=vn_xml['VNET']['NAME'].strip
|
||||
}
|
||||
|
||||
@vm_info['NICS']['NIC']=nics
|
||||
|
||||
instance_type_name=params['InstanceType']
|
||||
instance_type=INSTANCE_TYPES[instance_type_name]
|
||||
|
||||
halt 400, "Bad instance type" if !instance_type
|
||||
|
||||
@vm_info[:instance_type]=instance_type_name
|
||||
|
||||
template=ERB.new(File.read(
|
||||
TEMPLATES_LOCATION+"/#{instance_type['TEMPLATE']}"))
|
||||
template_text=template.result(binding)
|
||||
|
||||
vm=VirtualMachineVMI.new(
|
||||
VirtualMachine.build_xml, get_one_client_user(@auth.credentials[0]))
|
||||
response=vm.allocate(template_text)
|
||||
|
||||
if OpenNebula.is_error?(response)
|
||||
status 400
|
||||
response.to_str
|
||||
else
|
||||
vm.info
|
||||
vm.to_vmi
|
||||
end
|
||||
end
|
||||
|
||||
def change_state(params)
|
||||
if params['vmixml']
|
||||
vm_info=Crack::XML.parse(params['vmixml'])
|
||||
else
|
||||
halt 400, "VMI XML representation of VM not present"
|
||||
end
|
||||
|
||||
vm=VirtualMachineVMI.new(
|
||||
VirtualMachine.build_xml(params[:id]), get_one_client_user(@auth.credentials[0]))
|
||||
|
||||
halt 400, "State not defined in the VMI XML, cannot change state" if !vm_info['VM']['STATE']
|
||||
|
||||
case vm_info['VM']['STATE']
|
||||
when "stopped"
|
||||
rc = vm.stop
|
||||
when "suspended"
|
||||
rc = vm.suspend
|
||||
when "resume"
|
||||
rc = vm.resume
|
||||
when "cancel"
|
||||
rc = vm.cancel
|
||||
when "done"
|
||||
rc = vm.finalize
|
||||
else
|
||||
halt 400, "Invalid state"
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
status 400
|
||||
response.to_str
|
||||
else
|
||||
status 202
|
||||
response_text = "Changing state of VM " + params[:id] + " to " + vm_info['VM']['STATE']
|
||||
end
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Pool Resources methods
|
||||
###################################################
|
||||
|
||||
post '/vms' do
|
||||
# Auth check
|
||||
protected!
|
||||
|
||||
submit_vm(params)
|
||||
end
|
||||
|
||||
get '/vms' do
|
||||
# Auth check
|
||||
protected!
|
||||
# Info retrieval
|
||||
vmpool = VirtualMachinePoolVMI.new(get_one_client)
|
||||
vmpool.info
|
||||
# VMI conversion
|
||||
begin
|
||||
vmpool.to_vmi(CONFIG[:server])
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
end
|
||||
|
||||
post '/networks' do
|
||||
# Auth check
|
||||
protected!
|
||||
# Info retrieval from post params
|
||||
if params['vmixml']
|
||||
network_info=Crack::XML.parse(params['vmixml'])
|
||||
else
|
||||
halt 400, "VMI XML representation of Virtual Network not present in the request"
|
||||
end
|
||||
# Allocate the VirtualNetwork
|
||||
network = VirtualNetworkVMI.new(
|
||||
VirtualNetwork.build_xml,
|
||||
get_one_client_user(@auth.credentials[0]))
|
||||
|
||||
vntemplate = network.to_one_template(network_info['NETWORK'],CONFIG[:bridge])
|
||||
rc = network.allocate(vntemplate)
|
||||
|
||||
# Return status 201 XML if correct, status 500 otherwise
|
||||
if rc
|
||||
halt 500, "Error creating the Virtual Network: " + rc
|
||||
else
|
||||
network.info
|
||||
status 201
|
||||
network.to_vmi
|
||||
end
|
||||
end
|
||||
|
||||
get '/networks' do
|
||||
# Auth check
|
||||
protected!
|
||||
# Info retrieval
|
||||
network_pool = VirtualNetworkPoolVMI.new(get_one_client)
|
||||
network_pool.info
|
||||
# VMI conversion
|
||||
begin
|
||||
network_pool.to_vmi(CONFIG[:server])
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
end
|
||||
|
||||
post '/images' do
|
||||
# Auth check
|
||||
protected!
|
||||
# Info retrieval from post params
|
||||
if params['vmixml']
|
||||
image_info=Crack::XML.parse(params['vmixml'])
|
||||
else
|
||||
halt 400, "VMI XML representation of Image not present in the request"
|
||||
end
|
||||
|
||||
if params['file']
|
||||
file=params["file"]
|
||||
else
|
||||
halt 400, "File not present in the request"
|
||||
end
|
||||
|
||||
user = get_user(@auth.credentials[0])
|
||||
|
||||
# tmpfile where the file is stored
|
||||
f_tmp=file[:tempfile]
|
||||
img=$repoman.add(user[:id], f_tmp.path)
|
||||
f_tmp.unlink
|
||||
|
||||
img.get_image_info
|
||||
img.change_metadata(:name=>image_info['IMAGE']['NAME'])
|
||||
img.change_metadata(:description=>image_info['IMAGE']['URL'])
|
||||
|
||||
xml_response = "<IMAGE><ID>" + img.uuid + "</ID>" +
|
||||
"<NAME>" + image_info['IMAGE']['NAME'] + "</NAME>" +
|
||||
"<SIZE>" + ((img.size/1024)/1024).to_s + "</SIZE>" +
|
||||
"<URL>" + image_info['IMAGE']['URL'] + "<URL>" +
|
||||
"</IMAGE>"
|
||||
|
||||
status 201
|
||||
xml_response
|
||||
end
|
||||
|
||||
get '/images' do
|
||||
# Auth check
|
||||
protected!
|
||||
# Retrieve images owned by this user
|
||||
user = get_user(@auth.credentials[0])
|
||||
images=Image.filter(:owner => user[:id])
|
||||
|
||||
image_pool = "<IMAGES>"
|
||||
for image in images do
|
||||
image_pool += "<IMAGE id=\"#{image[:uuid]}\" href=\"http://#{CONFIG[:server]}/images/#{image[:uuid]}\">"
|
||||
end
|
||||
image_pool += "<IMAGES>"
|
||||
image_pool
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Entity Resources Methods
|
||||
###################################################
|
||||
|
||||
get '/vms/:id' do
|
||||
protected!
|
||||
vm = VirtualMachineVMI.new(VirtualMachine.build_xml(params[:id]),get_one_client_user(@auth.credentials[0]))
|
||||
vm.info
|
||||
begin
|
||||
vm.to_vmi()
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
end
|
||||
|
||||
delete '/vms/:id' do
|
||||
protected!
|
||||
vm = VirtualMachineVMI.new(VirtualMachine.build_xml(params[:id]),get_one_client_user(@auth.credentials[0]))
|
||||
vm.finalize
|
||||
"The Virtual Machine has been successfully deleted"
|
||||
end
|
||||
|
||||
post '/vms/:id' do
|
||||
protected!
|
||||
|
||||
change_state(params)
|
||||
end
|
||||
|
||||
get '/networks/:id' do
|
||||
protected!
|
||||
vn = VirtualNetworkVMI.new(VirtualNetwork.build_xml(params[:id]),get_one_client_user(@auth.credentials[0]))
|
||||
vn.info
|
||||
begin
|
||||
vn.to_vmi()
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
end
|
||||
|
||||
delete '/networks/:id' do
|
||||
protected!
|
||||
vn = VirtualNetworkVMI.new(VirtualNetwork.build_xml(params[:id]),get_one_client_user(@auth.credentials[0]))
|
||||
vn.delete
|
||||
"The Virtual Network has been successfully deleted"
|
||||
end
|
||||
|
||||
get '/images/:id' do
|
||||
protected!
|
||||
image=$repoman.get(params[:id])
|
||||
|
||||
image.get_image_info
|
||||
|
||||
if image
|
||||
xml_response = "<IMAGE><ID>" + image.uuid + "</ID>" +
|
||||
"<NAME>" + image.name + "</NAME>" +
|
||||
"<SIZE>" + ((image.size/1024)/1024).to_s + "</SIZE>" +
|
||||
"<URL>" + image.description + "<URL>" +
|
||||
"</IMAGE>"
|
||||
else
|
||||
status 404
|
||||
"Image with id = \"" + params[:id] + "\" not found"
|
||||
end
|
||||
end
|
||||
|
||||
delete '/images/:id' do
|
||||
protected!
|
||||
"Not yet implemented"
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,117 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-delete-image
|
||||
#
|
||||
# Uploads an image for use with an OpenNebula Cloud.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-delete-image[OPTIONS] IMAGE-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# IMAGE-ID ID of the image to be deleted
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{$0}: missing IMAGE-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
pp "Not implemented yet"
|
||||
|
||||
# vmi_client.delete_image(image_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-delete-network
|
||||
#
|
||||
# Uploads an image for use with an OpenNebula Cloud.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-delete-network [OPTIONS] NETWORK-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# NETWORK-ID ID of the network to be deleted
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
network_id = ARGV.shift
|
||||
|
||||
if !network_id
|
||||
puts "#{$0}: missing NETWORK-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.delete_network(network_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-delete-vms
|
||||
#
|
||||
# Deletes a Virtual Machine
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-image [OPTIONS] VM-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# VM-ID ID of the Virtual Machine to be deleted
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
vm_id = ARGV.shift
|
||||
|
||||
if !vm_id
|
||||
puts "#{$0}: missing VM-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.delete_vm(vm_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-image
|
||||
#
|
||||
# Retrieves the VMI representation of an Image
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-network [OPTIONS] IMAGE-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# IMAGE-ID Image Identifier
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{$0}: missing IMAGE-ID parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_image(image_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-images
|
||||
#
|
||||
# Retrieves all availables images
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-get-images [OPTIONS]
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_images
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-network
|
||||
#
|
||||
# Retrieves the VMI representation of a Virtual Network
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-network [OPTIONS] NETWORK-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# NETWORK-ID Network Identifier
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
network_id = ARGV.shift
|
||||
|
||||
if !network_id
|
||||
puts "#{$0}: missing NETWORK-ID parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_network(network_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-networks
|
||||
#
|
||||
# Retrieves all availables networks
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-get-networks [OPTIONS]
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_networks
|
||||
|
||||
exit 0
|
||||
|
@ -1,114 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-vm
|
||||
#
|
||||
# Retrieves the VMI representation of a Virtual Machine
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-get-vm [OPTIONS] VM-ID
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# VM-ID VM Identifier
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
vm_id = ARGV.shift
|
||||
|
||||
if !vm_id
|
||||
puts "#{$0}: missing VM-ID parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_vm(vm_id)
|
||||
|
||||
exit 0
|
||||
|
@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-get-vms
|
||||
#
|
||||
# Retrieves all availables Virtual Machines
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-get-vms [OPTIONS]
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.get_vms
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-post-image
|
||||
#
|
||||
# Uploads an image for use with an OpenNebula Cloud.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-image [OPTIONS] VMI-XML
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# VMI-XML Path to the xml file containing the VMI description of the image
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_xml = ARGV.shift
|
||||
|
||||
if !image_xml || !File.exists?(image_xml)
|
||||
puts "#{$0}: missing VMI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.post_image(image_xml)
|
||||
|
||||
exit 0
|
||||
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-post-network
|
||||
#
|
||||
# Creates a virtual network
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-network [OPTIONS] VMI-XML
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# VMI-XML Path to the xml file containing the VMI description of the Virtual Network
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
network_xml = ARGV.shift
|
||||
|
||||
if !network_xml || !File.exists?(network_xml)
|
||||
puts "#{$0}: missing VMI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.post_network(network_xml)
|
||||
|
||||
exit 0
|
||||
|
@ -1,127 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-post-vm
|
||||
#
|
||||
# Creates a new Virtual Machine from its VMI representation
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-post-vm [OPTIONS] VMI-XML
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
# --instance-type, -T
|
||||
# Specifies the type of Virtual Machine we want
|
||||
#
|
||||
# VMI-XML Path to the xml file containing the VMI description of the Virtual Machine
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--instance-type','-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
type = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--instance-type'
|
||||
type = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !type
|
||||
puts "#{$0}: missing compulsory instance type"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vm_xml = ARGV.shift
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{$0}: missing VMI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.post_vms(type, vm_xml)
|
||||
|
||||
exit 0
|
||||
|
@ -1,117 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# == Synopsis
|
||||
# vmi-put-vms
|
||||
#
|
||||
# Updates the representation of a Virtual Machine
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# vmi-put-vms [OPTIONS] VMI-XML
|
||||
#
|
||||
# -h, --help:
|
||||
# show help
|
||||
#
|
||||
# --username <id>, -U <id>:
|
||||
# The username of the user
|
||||
#
|
||||
# --password <key>, -P <key>:
|
||||
# The password of the user
|
||||
#
|
||||
# --url <url>, -U <url>:
|
||||
# Set url as the web service url to use
|
||||
#
|
||||
# --debug, -D
|
||||
# Enables verbosity
|
||||
#
|
||||
#
|
||||
# VMI-XML Path to the xml file containing the VMI description of the Virtual Machine
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
|
||||
# Complutense de Madrid (dsa-research.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/vmi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/vmiserver"
|
||||
|
||||
require 'VMIQueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
type = nil
|
||||
debug = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
RDoc::usage
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
vm_xml = ARGV.shift
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{$0}: missing VMI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
vmi_client = VMIQueryClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmi_client.put_vm(vm_xml)
|
||||
|
||||
exit 0
|
||||
|
@ -1,73 +0,0 @@
|
||||
|
||||
class VMIConfiguration
|
||||
|
||||
NAME_REG=/[\w\d_-]+/
|
||||
VARIABLE_REG=/\s*(#{NAME_REG})\s*=\s*/
|
||||
SIMPLE_VARIABLE_REG=/#{VARIABLE_REG}([^\[]+?)(#.*)?/
|
||||
SINGLE_VARIABLE_REG=/^#{SIMPLE_VARIABLE_REG}$/
|
||||
ARRAY_VARIABLE_REG=/^#{VARIABLE_REG}\[(.*?)\]/m
|
||||
|
||||
def initialize(file)
|
||||
@conf=parse_conf(file)
|
||||
end
|
||||
|
||||
def add_value(conf, key, value)
|
||||
if conf[key]
|
||||
if !conf[key].kind_of?(Array)
|
||||
conf[key]=[conf[key]]
|
||||
end
|
||||
conf[key]<<value
|
||||
else
|
||||
conf[key]=value
|
||||
end
|
||||
end
|
||||
|
||||
def parse_conf(file)
|
||||
conf_file=File.read(file)
|
||||
|
||||
conf=Hash.new
|
||||
|
||||
conf_file.scan(SINGLE_VARIABLE_REG) {|m|
|
||||
key=m[0].strip.upcase
|
||||
value=m[1].strip
|
||||
|
||||
# hack to skip multiline VM_TYPE values
|
||||
next if %w{NAME TEMPLATE}.include? key.upcase
|
||||
|
||||
add_value(conf, key, value)
|
||||
}
|
||||
|
||||
conf_file.scan(ARRAY_VARIABLE_REG) {|m|
|
||||
master_key=m[0].strip.upcase
|
||||
|
||||
pieces=m[1].split(',')
|
||||
|
||||
vars=Hash.new
|
||||
pieces.each {|p|
|
||||
key, value=p.split('=')
|
||||
vars[key.strip.upcase]=value.strip
|
||||
}
|
||||
|
||||
add_value(conf, master_key, vars)
|
||||
}
|
||||
|
||||
conf
|
||||
end
|
||||
|
||||
def conf
|
||||
@conf
|
||||
end
|
||||
|
||||
def [](key)
|
||||
@conf[key.to_s.upcase]
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
|
||||
require 'pp'
|
||||
|
||||
conf=VMIConfiguration.new('vmi-server.conf')
|
||||
pp conf.conf
|
||||
|
||||
end
|
@ -1,306 +0,0 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'curb'
|
||||
require 'uri'
|
||||
require 'OpenNebula'
|
||||
require 'Crack'
|
||||
|
||||
module VMIQueryClient
|
||||
###########################################################################
|
||||
#
|
||||
#
|
||||
###########################################################################
|
||||
class Client
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
#
|
||||
#######################################################################
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil, debug_flag=false)
|
||||
@debug = debug_flag
|
||||
|
||||
# Server location
|
||||
if !endpoint_str
|
||||
@endpoint = "http://localhost:4567"
|
||||
else
|
||||
@endpoint = endpoint_str
|
||||
end
|
||||
|
||||
# Autentication
|
||||
if user && pass
|
||||
@vmiauth = user + ":" + Digest::SHA1.hexdigest(pass)
|
||||
elsif
|
||||
raise "No authorization data present"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Pool Resource Request Methods
|
||||
#######################################################################
|
||||
|
||||
#######################################################################
|
||||
# Post a new VM to the VM Pool
|
||||
# :instance_type
|
||||
# :xmlfile
|
||||
#######################################################################
|
||||
def post_vms(instance_type,xmlfile)
|
||||
curl=Curl::Easy.new(@endpoint+"/vms")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
xml=File.read(xmlfile)
|
||||
|
||||
begin
|
||||
curl.http_post(
|
||||
Curl::PostField.content('vmixml', xml),
|
||||
Curl::PostField.content('InstanceType', instance_type)
|
||||
)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retieves the pool of Virtual Machines
|
||||
#######################################################################
|
||||
def get_vms
|
||||
curl=Curl::Easy.new(@endpoint+"/vms")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Post a new Network to the VN Pool
|
||||
# :xmlfile xml description of the Virtual Network
|
||||
#######################################################################
|
||||
def post_network(xmlfile)
|
||||
curl=Curl::Easy.new(@endpoint+"/networks")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
xml=File.read(xmlfile)
|
||||
|
||||
begin
|
||||
curl.http_post(
|
||||
Curl::PostField.content('vmixml', xml)
|
||||
)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retieves the pool of Virtual Networks
|
||||
#######################################################################
|
||||
def get_networks
|
||||
curl=Curl::Easy.new(@endpoint+"/networks")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Post a new Image to the Image Pool
|
||||
# :xmlfile
|
||||
#######################################################################
|
||||
def post_image(xmlfile)
|
||||
xml=File.read(xmlfile)
|
||||
image_info=Crack::XML.parse(xml)
|
||||
|
||||
curl=Curl::Easy.new(@endpoint+"/images")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
curl.multipart_form_post = true
|
||||
|
||||
file_path = image_info['IMAGE']['URL']
|
||||
|
||||
m=file_path.match(/^\w+:\/\/(.*)$/)
|
||||
|
||||
if m
|
||||
file_path="/"+m[1]
|
||||
end
|
||||
|
||||
begin
|
||||
curl.http_post(
|
||||
Curl::PostField.content('vmixml', xml),
|
||||
Curl::PostField.file('file', file_path)
|
||||
)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retieves the pool of Images owned by the user
|
||||
#######################################################################
|
||||
def get_images
|
||||
curl=Curl::Easy.new(@endpoint+"/images")
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Entity Resource Request Methods
|
||||
#######################################################################
|
||||
|
||||
#######################################################################
|
||||
# :id VM identifier
|
||||
#######################################################################
|
||||
def get_vm(id)
|
||||
curl=Curl::Easy.new(@endpoint+"/vms/" + id.to_s)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
pp curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Puts a new VM representation in order to change VM state
|
||||
# :xmlfile VM VMI xml representation
|
||||
#######################################################################
|
||||
def put_vm(id,xmlfile)
|
||||
xml=File.read(xmlfile)
|
||||
vm_info=Crack::XML.parse(xml)
|
||||
|
||||
curl=Curl::Easy.new(@endpoint+"/vms/"+id)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_post(Curl::PostField.content('vmixml', xml))
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
puts curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# :id VM identifier
|
||||
#######################################################################
|
||||
def delete_vm(id)
|
||||
curl=Curl::Easy.new(@endpoint+"/vms/" + id.to_s)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_delete
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
pp curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retrieves a Virtual Network
|
||||
# :id Virtual Network identifier
|
||||
#######################################################################
|
||||
def get_network(id)
|
||||
curl=Curl::Easy.new(@endpoint+"/networks/" + id.to_s)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
pp curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# :id VM identifier
|
||||
#######################################################################
|
||||
def delete_network(id)
|
||||
curl=Curl::Easy.new(@endpoint+"/networks/" + id.to_s)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_delete
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
pp curl.body_str
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retieves an Image
|
||||
# :image_uuid Image identifier
|
||||
#######################################################################
|
||||
def get_image(image_uuid)
|
||||
curl=Curl::Easy.new(@endpoint+"/images/"+image_uuid)
|
||||
curl.userpwd=@vmiauth
|
||||
curl.verbose=true if @debug
|
||||
|
||||
begin
|
||||
curl.http_get
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
puts curl.body_str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
vmiqc = VMIQueryClient::Client.new("http://localhost:4567","tinova","opennebula",true)
|
||||
#vmiqc.get_networks
|
||||
#vmiqc.post_network("vnxml")
|
||||
#vmiqc.post_image("imagexml")
|
||||
#vmiqc.get_images
|
||||
#vmiqc.get_image("988117f0-752a-012c-f16c-00254bd6f386")
|
||||
#vmiqc.post_vms("small","vmxml")
|
||||
#vmiqc.delete_vm("11")
|
||||
#vmiqc.delete_network("1")
|
||||
#vmiqc.put_vm("8","vmxml")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
require 'OpenNebula'
|
||||
require 'Crack'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualMachinePoolVMI < VirtualMachinePool
|
||||
# Creates the VMI representation of a Virtual Machine Pool
|
||||
def to_vmi(base_url)
|
||||
pool_hash=Crack::XML.parse(to_xml)
|
||||
vmi_xml = "<VMS>"
|
||||
|
||||
pool_hash['VM_POOL']['VM'].each{|vm|
|
||||
vmi_xml+='<VM id="' + vm['ID'].strip + '"' +
|
||||
' href="' + base_url + '/vms/' + vm['ID'].strip + '"/>'
|
||||
}
|
||||
vmi_xml += "</VMS>"
|
||||
end
|
||||
end
|
||||
|
@ -1,69 +0,0 @@
|
||||
require 'OpenNebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualMachineVMI < VirtualMachine
|
||||
# Creates the VMI representation of a Virtual Machine
|
||||
def to_vmi
|
||||
vmi_xml = "<VM>"
|
||||
vmi_xml += "<ID>" + id.to_s + "</ID>"
|
||||
vmi_xml += "<NAME>" + self['NAME'] + "</NAME>"
|
||||
vmi_xml += "<TYPE>" + self['VMI_SIZE_TYPE'] + "</TYPE>" if self['VMI_SIZE_TYPE']
|
||||
vmi_xml += "<STATE>" + state_str + "</STATE>"
|
||||
|
||||
# Now let's parse the template
|
||||
template=self.to_hash("TEMPLATE")
|
||||
|
||||
template['DISK']=[template['DISK']].flatten
|
||||
|
||||
if template['DISK']
|
||||
|
||||
vmi_xml += "<DISKS>"
|
||||
|
||||
template['DISK'].each{|disk|
|
||||
case disk['TYPE']
|
||||
when "disk" then
|
||||
vmi_xml += "<DISK image=#{disk['ID']} dev=#{disk['TARGET']}/>"
|
||||
when "swap" then
|
||||
vmi_xml += "<SWAP size=#{disk['SIZE']} dev=#{disk['TARGET']}/>"
|
||||
when "fs" then
|
||||
vmi_xml += "<FS size=#{disk['SIZE']} format=#{disk['FORMAT']} dev=#{disk['TARGET']}/>"
|
||||
end
|
||||
}
|
||||
|
||||
vmi_xml += "</DISKS>"
|
||||
end
|
||||
|
||||
template['NIC']=[template['NIC']].flatten
|
||||
|
||||
if template['NIC']
|
||||
vmi_xml += "<NICS>"
|
||||
|
||||
template['NIC'].each{|nic|
|
||||
|
||||
vmi_xml += "<NIC network=#{nic['VNID']}"
|
||||
if nic['IP']
|
||||
vmi_xml += " ip=#{nic['IP']}"
|
||||
end
|
||||
vmi_xml += "/>"
|
||||
}
|
||||
|
||||
vmi_xml += "</NICS>"
|
||||
end
|
||||
|
||||
vmi_xml += "</VM>"
|
||||
|
||||
return vmi_xml
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
t=VirtualMachineVMI.new(VirtualMachine.build_xml(6),Client.new("tinova:opennebula"))
|
||||
# t=VirtualMachineVMI.new(VirtualMachine.build_xml,nil)
|
||||
t.info
|
||||
puts t.to_vmi
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
require 'OpenNebula'
|
||||
require 'Crack'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualNetworkPoolVMI < VirtualNetworkPool
|
||||
# Creates the VMI representation of a Virtual Network
|
||||
def to_vmi(base_url)
|
||||
network_pool_hash=Crack::XML.parse(to_xml)
|
||||
vmi_xml = "<NETWORKS>"
|
||||
|
||||
network_pool_hash['VNET_POOL']['VNET'].each{|network|
|
||||
vmi_xml+='<NETWORK id="' + network['ID'].strip + '"' +
|
||||
' href="' + base_url + '/networks/' + network['ID'].strip + '"/>'
|
||||
}
|
||||
|
||||
vmi_xml += "</NETWORKS>"
|
||||
end
|
||||
end
|
@ -1,28 +0,0 @@
|
||||
require 'OpenNebula'
|
||||
require 'Crack'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualNetworkVMI < VirtualNetwork
|
||||
# Creates the VMI representation of a Virtual Network
|
||||
def to_vmi()
|
||||
vn_hash=Crack::XML.parse(to_xml)
|
||||
vmi_xml = "<NETWORK>"
|
||||
|
||||
vmi_xml += "<ID>" + vn_hash['VNET']['ID'].strip + "</ID>"
|
||||
vmi_xml += "<NAME>" + vn_hash['VNET']['NAME'].strip + "</NAME>"
|
||||
vmi_xml += "<ADDRESS>" + vn_hash['VNET']['TEMPLATE']['NETWORK_ADDRESS'].strip + "</ADDRESS>"
|
||||
vmi_xml += "<SIZE>" + vn_hash['VNET']['TEMPLATE']['NETWORK_SIZE'].strip + "</SIZE>"
|
||||
|
||||
vmi_xml += "</NETWORK>"
|
||||
end
|
||||
|
||||
def to_one_template(network_hash, bridge)
|
||||
one_template = "NAME=" + network_hash['NAME'] + "\n"
|
||||
one_template += "TYPE=RANGED\n"
|
||||
one_template += "BRIDGE=" + bridge + "\n"
|
||||
one_template += "NETWORK_ADDRESS=" + network_hash['ADDRESS'] + "\n"
|
||||
one_template += "NETWORK_SIZE=" + network_hash['SIZE'] + "\n"
|
||||
end
|
||||
end
|
||||
|
@ -1,45 +0,0 @@
|
||||
NAME = <%= @vm_info['NAME']%>
|
||||
|
||||
CPU = 8
|
||||
MEMORY = 8192
|
||||
|
||||
OS = [ kernel = /vmlinuz,
|
||||
initrd = /initrd.img,
|
||||
root = sda1,
|
||||
kernel_cmd = "ro xencons=tty console=tty1"]
|
||||
<% @vm_info['DISKS'].each do |key, image|
|
||||
|
||||
case key
|
||||
|
||||
when "SWAP"
|
||||
%>
|
||||
DISK = [ type = "swap",
|
||||
size=<%= image['size']%>,
|
||||
dev=<%= image['dev']%> ]
|
||||
<%
|
||||
when "DISK"
|
||||
%>
|
||||
DISK = [ type = "disk",
|
||||
dev=<%= image['dev']%>,
|
||||
source=<%= image['source']%>,
|
||||
image_id=<%= image['image']%> ]
|
||||
<%
|
||||
when "FS"
|
||||
%>
|
||||
DISK = [ type = "fs",
|
||||
dev=<%= image['dev']%>,
|
||||
size=<%= image['size']%>,
|
||||
format=<%= CONFIG[:fs_format]||"ext3"%> ]
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% @vm_info['NICS']['NIC'].each do |nic| %>
|
||||
NIC = [
|
||||
<% if nic['ip'] %>
|
||||
IP=<%= nic['ip'] %>,
|
||||
<% end %>
|
||||
NETWORK=<%= nic['network']%>,
|
||||
NETWORK_ID=<%= nic['network_id'] %>
|
||||
]
|
||||
<% end %>
|
||||
INSTANCE_TYPE = <%= @vm_info[:instance_type ]%>
|
||||
|
@ -1,45 +0,0 @@
|
||||
NAME = <%= @vm_info['NAME']%>
|
||||
|
||||
CPU = 4
|
||||
MEMORY = 4096
|
||||
|
||||
OS = [ kernel = /vmlinuz,
|
||||
initrd = /initrd.img,
|
||||
root = sda1,
|
||||
kernel_cmd = "ro xencons=tty console=tty1"]
|
||||
<% @vm_info['DISKS'].each do |key, image|
|
||||
|
||||
case key
|
||||
|
||||
when "SWAP"
|
||||
%>
|
||||
DISK = [ type = "swap",
|
||||
size=<%= image['size']%>,
|
||||
dev=<%= image['dev']%> ]
|
||||
<%
|
||||
when "DISK"
|
||||
%>
|
||||
DISK = [ type = "disk",
|
||||
dev=<%= image['dev']%>,
|
||||
source=<%= image['source']%>,
|
||||
image_id=<%= image['image']%> ]
|
||||
<%
|
||||
when "FS"
|
||||
%>
|
||||
DISK = [ type = "fs",
|
||||
dev=<%= image['dev']%>,
|
||||
size=<%= image['size']%>,
|
||||
format=<%= CONFIG[:fs_format]||"ext3"%> ]
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% @vm_info['NICS']['NIC'].each do |nic| %>
|
||||
NIC = [
|
||||
<% if nic['ip'] %>
|
||||
IP=<%= nic['ip'] %>,
|
||||
<% end %>
|
||||
NETWORK=<%= nic['network']%>,
|
||||
NETWORK_ID=<%= nic['network_id'] %>
|
||||
]
|
||||
<% end %>
|
||||
INSTANCE_TYPE = <%= @vm_info[:instance_type ]%>
|
||||
|
@ -1,45 +0,0 @@
|
||||
NAME = <%= @vm_info['NAME']%>
|
||||
|
||||
CPU = 1
|
||||
MEMORY = 1024
|
||||
|
||||
OS = [ kernel = /vmlinuz,
|
||||
initrd = /initrd.img,
|
||||
root = sda1,
|
||||
kernel_cmd = "ro xencons=tty console=tty1"]
|
||||
<% @vm_info['DISKS'].each do |key, image|
|
||||
|
||||
case key
|
||||
|
||||
when "SWAP"
|
||||
%>
|
||||
DISK = [ type = "swap",
|
||||
size=<%= image['size']%>,
|
||||
dev=<%= image['dev']%> ]
|
||||
<%
|
||||
when "DISK"
|
||||
%>
|
||||
DISK = [ type = "disk",
|
||||
dev=<%= image['dev']%>,
|
||||
source=<%= image['source']%>,
|
||||
image_id=<%= image['image']%> ]
|
||||
<%
|
||||
when "FS"
|
||||
%>
|
||||
DISK = [ type = "fs",
|
||||
dev=<%= image['dev']%>,
|
||||
size=<%= image['size']%>,
|
||||
format=<%= CONFIG[:fs_format]||"ext3"%> ]
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% @vm_info['NICS']['NIC'].each do |nic| %>
|
||||
NIC = [
|
||||
<% if nic['ip'] %>
|
||||
IP=<%= nic['ip'] %>,
|
||||
<% end %>
|
||||
NETWORK=<%= nic['network']%>,
|
||||
NETWORK_ID=<%= nic['network_id'] %>
|
||||
]
|
||||
<% end %>
|
||||
INSTANCE_TYPE = <%= @vm_info[:instance_type ]%>
|
||||
|
@ -1,26 +0,0 @@
|
||||
# OpenNebula administrator user
|
||||
USER=oneadmin
|
||||
PASSWORD=<PUT HERE ONEADMIN PASS>
|
||||
|
||||
# OpenNebula server contact information
|
||||
ONE_XMLRPC=http://localhost:2633/RPC2
|
||||
|
||||
# Host and port where the vmi server will run
|
||||
SERVER=<FQDN OF VMI SERVER>
|
||||
PORT=4567
|
||||
|
||||
# Configuration for the image repository
|
||||
DATABASE=<ONELOCATION>/var/vmi.db
|
||||
IMAGE_DIR=<PATH TO EXISTING IMAGE DIRECTORY>
|
||||
|
||||
# Configuration for OpenNebula's Virtual Networks
|
||||
BRIDGE=<NAME OF DEFAULT BRIDGE>
|
||||
|
||||
# Default format for FS
|
||||
FS_FORMAT=ext3
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
VM_TYPE=[NAME=small, TEMPLATE=small.erb]
|
||||
VM_TYPE=[NAME=medium, TEMPLATE=medium.erb]
|
||||
VM_TYPE=[NAME=large, TEMPLATE=large.erb]
|
||||
|
Loading…
x
Reference in New Issue
Block a user