Sha256: 83268977dcfbe59710518243a6d1ea5d067447ac7f55898f8680eba314382c4f

Contents?: true

Size: 1.27 KB

Versions: 25

Compression:

Stored size: 1.27 KB

Contents

require 'fog'

#
# Create the connection to the XenServer host
#
xenserver = Fog::Compute.new({
  :provider           => 'XenServer',
  :xenserver_url      => '1.2.3.4',
  :xenserver_username => 'root',
  :xenserver_password => 'secret',
})

# We have a bonded interface in XenServer, bond0 and
# we want to add the VLANs there.
# Note the VLAN ID -1, it is important since you
# will problably have many PIFs with device == bond0
# but we need the one without a proper VLAN ID
#
bondmaster_pif = xenserver.pifs.find do |pif|
  pif.vlan == "-1" and pif.device == "bond0"
end

# Another valid way of finding a PIF, without bonding
# pif = xenserver.pifs.find { |pif| pif.physical and pif.device == 'eth0' }

# We want to create these new VLANs
vlans = [
  { "name" => "VLAN 44", "vlanid" => 44},
  { "name" => "VLAN 55", "vlanid" => 55}
]

vlans.each do |vlan|
  # Do not create duplicated networks
  if xenserver.networks.find { |n| n.name == vlan['name'] }
    puts "Network #{vlan['name']} available, skipping"
    next
  end

  puts "Craeting Network #{vlan['name']}, VLAN ID #{vlan['vlanid']}"
  network = xenserver.networks.create :name => vlan['name']
  xenserver.vlans.create :tag => vlan['vlanid'],
                         :network => network,
                         :pif => bondmaster_pif
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.34.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.33.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.32.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.31.0 lib/fog/xenserver/examples/networks-and-vlans.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.30.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.29.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.28.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.27.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.26.0 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.25.0 lib/fog/xenserver/examples/networks-and-vlans.rb
nsidc-fog-1.24.1 lib/fog/xenserver/examples/networks-and-vlans.rb
fog-1.24.0 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.11 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.10 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.9 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.8 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.7 lib/fog/xenserver/examples/networks-and-vlans.rb
ns-fog-1.22.6 lib/fog/xenserver/examples/networks-and-vlans.rb