henrydenhengst

rdo_xenserver_helper.sh

Dec 1st, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.14 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # https://github.com/Annie-XIE/summary-os/blob/master/rdo_xenserver_helper.sh
  4. #
  5. INT_NET=openstack-int-network
  6. EXT_NET=openstack-ext-network
  7. VM_NET=openstack-vm-network
  8.  
  9. function create_network()
  10. {
  11.     xe network-create name-label=$INT_NET
  12.     xe network-create name-label=$EXT_NET
  13.     xe network-create name-label=$VM_NET
  14. }
  15.  
  16. function create_vif {
  17.     local vm_uuid=$(xe vm-list name-label=CentOS_RDO minimal=true)
  18.  
  19.     local vm_net_uuid=$(xe network-list name-label=openstack-vm-network minimal=true)
  20.     local next_device=$(xe vm-param-get uuid=$vm_uuid param-name=allowed-VIF-devices | cut -d';' -f1)
  21.     local vm_vif_uuid=$(xe vif-create device=$next_device network-uuid=$vm_net_uuid vm-uuid=$vm_uuid)
  22.     xe vif-plug uuid=$vm_vif_uuid
  23.  
  24.     local ext_net_uuid=$(xe network-list name-label=openstack-ext-network minimal=true)
  25.     local next_device=$(xe vm-param-get uuid=$vm_uuid param-name=allowed-VIF-devices | cut -d';' -f1)
  26.     local ext_vif_uuid=$(xe vif-create device=$next_device network-uuid=$ext_net_uuid vm-uuid=$vm_uuid)
  27.     xe vif-plug uuid=$ext_vif_uuid
  28. }
  29.  
  30. function create_himn {
  31.     local vm_uuid=$(xe vm-list name-label=CentOS_RDO minimal=true)
  32.     local net=$(xe network-list bridge=xenapi --minimal)
  33.     local vif=$(xe vif-create vm-uuid=$vm_uuid network-uuid=$net device=9)
  34.     xe vif-plug uuid=$vif
  35.     local mac=$(xe vif-param-get uuid=$vif param-name=MAC)
  36.     xe vm-param-set uuid=$vm_uuid xenstore-data:vm-data/himn_mac=$mac
  37. }
  38.  
  39. # run this function in domU
  40. function active_himn_interface {
  41.  
  42.     local domid=$(xenstore-read domid)
  43.     local mac=$(xenstore-read /local/domain/$domid/vm-data/himn_mac)
  44.     local dev_path=$(grep -l $mac /sys/class/net/*/address)
  45.     local dev=$(basename $(dirname $dev_path))
  46.     local ifcfg_file=/etc/sysconfig/network-scripts/ifcfg-$dev
  47.  
  48.     touch $ifcfg_file
  49.     echo "DEVICE=$dev" >> $ifcfg_file
  50.     echo "BOOTPROTO=dhcp" >> $ifcfg_file
  51.     echo "ONBOOT=yes" >> $ifcfg_file
  52.     echo "TYPE=Ethernet" >> $ifcfg_file
  53.  
  54.     ifup $dev
  55. }
  56.  
  57. function install_dom0_plugins {
  58.     local dom0_ip=169.254.0.1
  59.  
  60.     ################## nova #################
  61.     mkdir -p /tmp/nova_plugins
  62.     local tag=$(rpm -q openstack-nova-compute --queryformat '%{Version}')
  63.     local base=https://git.openstack.org/cgit/openstack/nova/plain
  64.     local path=plugins/xenserver/xenapi/etc/xapi.d/plugins
  65.  
  66.     local files=$(curl -s -S $base/$path?id=$tag | grep li | grep $path | sed -e 's#.*xapi.d/plugins/##' -e 's#\?id=.*##')
  67.     for f in $files; do
  68.         curl -s -S $base/$path/$f?id=$tag -o /tmp/nova_plugins/$f
  69.     done
  70.     chmod +x /tmp/nova_plugins/*
  71.     scp -p /tmp/nova_plugins/* root@$dom0_ip:/etc/xapi.d/plugins/
  72.  
  73.     ################## neutron ##############
  74.     mkdir -p /tmp/neutron_plugins
  75.     cp /usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/openvswitch/agent/xenapi/etc/xapi.d/plugins/* /tmp/neutron_plugins
  76.     chmod +x /tmp/neutron_plugins/*
  77.     sed -i "/ALLOWED_CMDS = /a    'ipset', 'iptables-save', 'iptables-restore', 'ip6tables-save', 'ip6tables-restore'," /tmp/neutron_plugins/netwrap
  78.     scp -p /tmp/neutron_plugins/* root@$dom0_ip:/etc/xapi.d/plugins/
  79. }
Advertisement
Add Comment
Please, Sign In to add comment