feature #476: draft of vlan hook

This commit is contained in:
Jaime Melis committed 2011-04-29 01:14:05 +02:00
1 parent d5ddaea463
commit c3b07bef34
3 files changed
+199

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env ruby
require 'base64'
require 'rexml/xpath'
require 'rexml/document'
#TODO: hypervisor arg?
$hypervisor = "kvm"
#TODO: start vlan arg?
$start_vlan = 2
#TODO: other possible args?
def tag(nic, hypervisor)
if hypervisor == "kvm"
tag_kvm(nic)
#TODO:
#elsif hypervisor == "xen"
# tag_xen(nic)
end
end
def tag_kvm(nic)
tag_id = $start_vlan + nic[:network_id].to_i
#TODO: real tag command
puts "sudo ovs-vsctl set Port #{nic[:tap]} tag=#{tag_id}"
end
#TODO:
#def tag_xen(nic)
#end
def get_tap(nic, hypervisor)
if hypervisor == "kvm"
get_tap_kvm(nic)
#TODO:
#elsif hypervisor == "xen"
# get_tap_xen(nic)
end
end
def get_tap_kvm(nic)
dumpxml = File.read('vm_dumpxml') # virsh dumpxml
dumpxml_root = REXML::Document.new(dumpxml).root
xpath = "devices/interface[@type='bridge']/"
xpath << "mac[@address='#{nic[:mac]}']/../target"
tap = dumpxml_root.elements[xpath]
if tap
nic[:tap] = tap.attributes['dev']
end
nic
end
#TODO:
#def get_tap_xen(nic)
#end
vm_xml = File.read('vm_xml') # Base64::decode64(ARGV[0])
vm_doc = REXML::Document.new(vm_xml)
vm_root = vm_doc.root
vm_id = vm_root.elements["ID"]
#nics = Array.new #TODO: not needed
vm_root.elements.each("TEMPLATE/NIC") do |nic_element|
nic = Hash.new
nic_element.elements.each('*') do |nic_attribute|
key = nic_attribute.xpath.split('/')[-1].downcase.to_sym
nic[key] = nic_attribute.text
end
next if !(nic[:bridge] and nic[:network_id])
nic = get_tap(nic, $hypervisor)
if nic[:tap]
tag(nic, $hypervisor)
end
#nics << nic #TODO: not needed
end
+48
View File
@@ -0,0 +1,48 @@
<domain type='kvm' id='3'>
<name>one-1</name>
<uuid>95502733-f45a-aa1e-7a46-d40d0a1c88c6</uuid>
<memory>65536</memory>
<currentMemory>65536</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc-0.14'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/home/jmelis/work/git/one/one/var//1/images/disk.0'/>
<target dev='sda' bus='scsi'/>
<alias name='scsi0-0-0'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='scsi' index='0'>
<alias name='scsi0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='02:00:ac:10:00:64'/>
<source bridge='br0'/>
<target dev='vnet0'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</interface>
<interface type='bridge'>
<mac address='02:00:ac:10:00:65'/>
<source bridge='br1'/>
<target dev='vnet1'/>
<alias name='net1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</interface>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
+68
View File
@@ -0,0 +1,68 @@
<VM>
<ID>1</ID>
<ID>11</ID>
<UID>0</UID>
<USERNAME>oneadmin</USERNAME>
<NAME>ttylinux</NAME>
<LAST_POLL>1304001042</LAST_POLL>
<STATE>3</STATE>
<LCM_STATE>3</LCM_STATE>
<STIME>1304000879</STIME>
<ETIME>1304000887</ETIME>
<DEPLOY_ID>one-1</DEPLOY_ID>
<MEMORY>65536</MEMORY>
<CPU>97</CPU>
<NET_TX>0</NET_TX>
<NET_RX>1236</NET_RX>
<TEMPLATE>
<CPU><![CDATA[0.1]]></CPU>
<DISK>
<DISK_ID><![CDATA[0]]></DISK_ID>
<READONLY><![CDATA[no]]></READONLY>
<SOURCE><![CDATA[/home/jmelis/work/git/one/files/templates/ttylinux/ttylinux.img]]></SOURCE>
<TARGET><![CDATA[sda]]></TARGET>
<TYPE><![CDATA[file]]></TYPE>
</DISK>
<ERROR>
<MESSAGE><![CDATA[Error deploying virtual machine: Could not create domain from /home/jmelis/work/git/one/one/var//1/images/deployment.0]]></MESSAGE>
<TIMESTAMP><![CDATA[Thu Apr 28 16:28:07 2011]]></TIMESTAMP>
</ERROR>
<FEATURES>
<ACPI><![CDATA[no]]></ACPI>
</FEATURES>
<MEMORY><![CDATA[64]]></MEMORY>
<NAME><![CDATA[ttylinux]]></NAME>
<NIC>
<BRIDGE><![CDATA[br0]]></BRIDGE>
<IP><![CDATA[172.16.0.100]]></IP>
<MAC><![CDATA[02:00:ac:10:00:64]]></MAC>
<NETWORK><![CDATA[Small network]]></NETWORK>
<NETWORK_ID><![CDATA[0]]></NETWORK_ID>
</NIC>
<NIC>
<BRIDGE><![CDATA[br1]]></BRIDGE>
<IP><![CDATA[172.16.0.101]]></IP>
<MAC><![CDATA[02:00:ac:10:00:65]]></MAC>
<NETWORK><![CDATA[Small network]]></NETWORK>
<NETWORK_ID><![CDATA[1]]></NETWORK_ID>
</NIC>
<VMID><![CDATA[1]]></VMID>
</TEMPLATE>
<HISTORY>
<SEQ>1</SEQ>
<HOSTNAME>localhost</HOSTNAME>
<VM_DIR>/home/jmelis/work/git/one/one/var/</VM_DIR>
<HID>2</HID>
<STIME>1304000924</STIME>
<ETIME>0</ETIME>
<VMMMAD>vmm_kvm</VMMMAD>
<TMMAD>tm_nfs</TMMAD>
<PSTIME>1304000924</PSTIME>
<PETIME>1304000924</PETIME>
<RSTIME>1304000924</RSTIME>
<RETIME>0</RETIME>
<ESTIME>0</ESTIME>
<EETIME>0</EETIME>
<REASON>0</REASON>
</HISTORY>
</VM>