Created
September 18, 2012 12:17
-
-
Save dmamolina/3742802 to your computer and use it in GitHub Desktop.
Creating a new VNET in OpenNebula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
############################################################################## | |
# Environment Configuration | |
############################################################################## | |
ONE_LOCATION=ENV["ONE_LOCATION"] | |
if !ONE_LOCATION | |
RUBY_LIB_LOCATION="/usr/lib/one/ruby" | |
else | |
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" | |
end | |
$: << RUBY_LIB_LOCATION | |
############################################################################## | |
# Required libraries | |
############################################################################## | |
require 'OpenNebula' | |
include OpenNebula | |
# OpenNebula credentials | |
CREDENTIALS = "oneuser:onepass" | |
# XML_RPC endpoint where OpenNebula is listening | |
ENDPOINT = "http://localhost:2633/RPC2" | |
client = Client.new(CREDENTIALS, ENDPOINT) | |
template = <<-EOT | |
NAME = "Red LAN" | |
TYPE = RANGED | |
# Now we'll use the host private network (physical) | |
BRIDGE = vbr0 | |
NETWORK_SIZE = C | |
NETWORK_ADDRESS = 192.168.0.0 | |
# Custom Attributes to be used in Context | |
GATEWAY = 192.168.0.1 | |
DNS = 192.168.0.1 | |
LOAD_BALANCER = 192.168.0.3 | |
EOT | |
xml = OpenNebula::VirtualNetwork.build_xml | |
vn = OpenNebula::VirtualNetwork.new(xml, client) | |
rc = vn.allocate(template) | |
if OpenNebula.is_error?(rc) | |
exit -1, rc.message | |
else | |
puts "ID: #{vn.id.to_s}" | |
end | |
puts "Before info:" | |
puts vn.to_xml | |
puts | |
vn.info | |
puts "After info:" | |
puts vn.to_xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment