Initial version from puppet-n1k-vsm-archive/rh-n1k-vsm branch
This commit is contained in:
parent
eec4ee87e6
commit
69ff094069
145
files/repackiso.py
Executable file
145
files/repackiso.py
Executable file
@ -0,0 +1,145 @@
|
||||
#!/usr/bin/python
|
||||
import shutil, tempfile, os, optparse, logging
|
||||
import sys
|
||||
|
||||
usage = "usage: %prog [options]"
|
||||
parser = optparse.OptionParser(usage=usage)
|
||||
parser.add_option("-i", "--isofile", help="ISO image", dest="isoimg")
|
||||
parser.add_option("-d", "--domainid", help="Domain id ", dest="domainid")
|
||||
parser.add_option("-n", "--vsmname", help="VSM name", dest="vsmname")
|
||||
parser.add_option("-m", "--mgmtip", help="Management Ip address", dest="mgmtip")
|
||||
parser.add_option("-s", "--mgmtsubnet", help="Management Subnet", dest="mgmtsubnet")
|
||||
parser.add_option("-g", "--gateway", help="Management gateway", dest="mgmtgateway")
|
||||
parser.add_option("-p", "--password", help="Admin account password", dest="adminpasswd")
|
||||
parser.add_option("-r", "--vsmrole", help="VSM Role, primary ,secondary or standalone", dest="vsmrole")
|
||||
parser.add_option("-f", "--file", help="Repackaged file", dest="repackediso")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
isoimg = options.isoimg
|
||||
domainid = int(options.domainid)
|
||||
vsmname = options.vsmname
|
||||
mgmtip = options.mgmtip
|
||||
mgmtsubnet = options.mgmtsubnet
|
||||
mgmtgateway = options.mgmtgateway
|
||||
adminpasswd = options.adminpasswd
|
||||
vsmrole = options.vsmrole
|
||||
repackediso = options.repackediso
|
||||
|
||||
|
||||
class Command(object):
|
||||
"""Run a command and capture it's output string, error string and exit status"""
|
||||
def __init__(self, command):
|
||||
self.command = command
|
||||
|
||||
def run(self, shell=True):
|
||||
import subprocess as sp
|
||||
process = sp.Popen(self.command, shell = shell, stdout = sp.PIPE, stderr = sp.PIPE)
|
||||
self.pid = process.pid
|
||||
self.output, self.error = process.communicate()
|
||||
self.failed = process.returncode
|
||||
return self
|
||||
|
||||
@property
|
||||
def returncode(self):
|
||||
return self.failed
|
||||
|
||||
def createOvfEnvXmlFile(domain, gateway, hostname, ip, subnet, password, vsm_mode):
|
||||
#TODO: write a proper xml
|
||||
ovf_f = tempfile.NamedTemporaryFile(delete=False)
|
||||
|
||||
st = '<?xml version="1.0" encoding="UTF-8"?> \n'
|
||||
st += '<Environment \n'
|
||||
st += 'xmlns="http://schemas.dmtf.org/ovf/environment/1" \n'
|
||||
st += 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n'
|
||||
st += 'xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" \n'
|
||||
st += 'xmlns:ve="http://www.vmware.com/schema/ovfenv" \n'
|
||||
st += 'oe:id=""> \n'
|
||||
st += '<PlatformSection> \n'
|
||||
st += '<Kind>VMware ESXi</Kind> \n'
|
||||
st += '<Version>4.0.0</Version> \n'
|
||||
st += '<Vendor>VMware, Inc.</Vendor> \n'
|
||||
st += '<Locale>en</Locale> \n'
|
||||
st += '</PlatformSection> \n'
|
||||
st += '<PropertySection> \n'
|
||||
st += '<Property oe:key="DomainId" oe:value="%s" /> \n' % (domain)
|
||||
st += '<Property oe:key="EnableTelnet" oe:value="True" /> \n'
|
||||
st += '<Property oe:key="GatewayIpV4" oe:value="%s" /> \n' % (gateway)
|
||||
st += '<Property oe:key="HostName" oe:value="%s" /> \n' % (hostname)
|
||||
st += '<Property oe:key="ManagementIpV4" oe:value="%s" /> \n' % (ip)
|
||||
st += '<Property oe:key="ManagementIpV4Subnet" oe:value="%s" /> \n' % (subnet)
|
||||
st += '<Property oe:key="OvfDeployment" oe:value="installer" /> \n'
|
||||
st += '<Property oe:key="SvsMode" oe:value="L3" /> \n'
|
||||
st += '<Property oe:key="Password" oe:value="%s" /> \n' % (password)
|
||||
st += '<Property oe:key="HARole" oe:value="%s" /> \n' % (vsm_mode)
|
||||
#if vsm_mode == "primary":
|
||||
# st += '<Property oe:key="HARole" oe:value="%s" /> \n' % (vsm_mode)
|
||||
#else:
|
||||
# st += '<Property oe:key="HARole" oe:value="standalone" /> \n'
|
||||
st += '</PropertySection> \n'
|
||||
st += '</Environment> \n'
|
||||
|
||||
ovf_f.write(st)
|
||||
ovf_f.close()
|
||||
return ovf_f
|
||||
|
||||
def main():
|
||||
""" repackages the iso file, with modified ovf file """
|
||||
|
||||
#logger = logging.getLogger('myapp')
|
||||
#hdlr = logging.FileHandler('/tmp/myapp.log')
|
||||
#formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
||||
#hdlr.setFormatter(formatter)
|
||||
#logger.addHandler(hdlr)
|
||||
#logger.setLevel(logging.DEBUG)
|
||||
|
||||
ovf_f = createOvfEnvXmlFile(domain=domainid, gateway=mgmtgateway, hostname=vsmname, ip=mgmtip, subnet=mgmtsubnet, password=adminpasswd, vsm_mode=vsmrole)
|
||||
|
||||
mntdir = tempfile.mkdtemp()
|
||||
ddir = tempfile.mkdtemp()
|
||||
|
||||
cret = Command('/bin/mount -o loop -t iso9660 %s %s' % (isoimg, mntdir)).run()
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
if cret.failed:
|
||||
print(sys.argv[0], "1 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
cret = Command('/bin/cp -r %s/* %s' % (mntdir, ddir)).run()
|
||||
print(sys.argv[0], "2 cwchang X", cret.output, "X", cret.error,"X")
|
||||
if cret.failed:
|
||||
print(sys.argv[0], "2 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
|
||||
cret = Command('/bin/umount %s' % (mntdir)).run()
|
||||
if cret.failed:
|
||||
print(sys.argv[0], "3 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
|
||||
cret = Command('/bin/cp %s %s/ovf-env.xml' % (ovf_f.name, ddir)).run()
|
||||
if cret.failed:
|
||||
print(sys.argv[0], "4 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
|
||||
|
||||
if os.path.exists('%s/isolinux/isolinux.bin' % (ddir)):
|
||||
cret = Command('cd %s; /usr/bin/mkisofs -uid 0 -gid 0 -J -R -A Cisco_Nexus_1000V_VSM -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o %s .' % (ddir, repackediso)).run()
|
||||
if cret.failed:
|
||||
print(sys.argv[0],"5 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
else:
|
||||
cret = Command('cd %s; /usr/bin/mkisofs -uid 0 -gid 0 -J -R -A Cisco_Nexus_1000V_VSM -b boot/grub/iso9660_stage1_5 -no-emul-boot -boot-load-size 4 -boot-info-table -o %s .' % (ddir, repackediso)).run()
|
||||
if cret.failed:
|
||||
print(sys.argv[0], "6 ", cret.output, cret.error)
|
||||
sys.exit(1)
|
||||
#logger.info("%s %s" % (cret.output, cret.error))
|
||||
|
||||
os.unlink(ovf_f.name)
|
||||
shutil.rmtree(mntdir)
|
||||
shutil.rmtree(ddir)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
76
manifests/deploy.pp
Normal file
76
manifests/deploy.pp
Normal file
@ -0,0 +1,76 @@
|
||||
class n1k_vsm::deploy {
|
||||
|
||||
#ensure tap interfaces and deploy the vsm
|
||||
|
||||
$ctrltap = $n1k_vsm::ctrlinterface[0]
|
||||
$ctrlmac = $n1k_vsm::ctrlinterface[1]
|
||||
$ctrlbridge = $n1k_vsm::ctrlinterface[2]
|
||||
$mgmttap = $n1k_vsm::mgmtinterface[0]
|
||||
$mgmtmac = $n1k_vsm::mgmtinterface[1]
|
||||
$mgmtbridge = $n1k_vsm::mgmtinterface[2]
|
||||
$pkttap = $n1k_vsm::pktinterface[0]
|
||||
$pktmac = $n1k_vsm::pktinterface[1]
|
||||
$pktbridge = $n1k_vsm::pktinterface[2]
|
||||
|
||||
# tapint {"$ctrltap":
|
||||
# bridge => $ctrlbridge,
|
||||
# ensure => present
|
||||
# }
|
||||
#
|
||||
# tapint {"$mgmttap":
|
||||
# bridge => $mgmtbridge,
|
||||
# ensure => present
|
||||
# }
|
||||
#
|
||||
# tapint {"$pkttap":
|
||||
# bridge => $pktbridge,
|
||||
# ensure => present
|
||||
# }
|
||||
|
||||
|
||||
$diskfile = "/var/spool/vsm/${n1k_vsm::role}_disk"
|
||||
|
||||
exec { "Exec_create_disk":
|
||||
command => "/usr/bin/qemu-img create -f raw $diskfile ${n1k_vsm::disksize}G",
|
||||
unless => "/usr/bin/virsh list | grep -c ' ${n1k_vsm::vsmname} .* running'",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_create_disk_debug":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\nExec_create_disk /usr/bin/qemu-img create -f raw $diskfile ${n1k_vsm::disksize}G\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
$targetxmlfile = "/var/spool/vsm/vsm_${n1k_vsm::role}_deploy.xml"
|
||||
file { "File_Target_XML_File":
|
||||
path => "$targetxmlfile",
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '666',
|
||||
content => template('n1k_vsm/vsm_vm.xml.erb'),
|
||||
require => Exec["Exec_create_disk"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_File_Target_XML_FILE":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\nFile_Target_XML_File\n path=$targetxmlfile \n owner=root \n group=root \n mode=666 \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
exec { "Exec_Create_VSM":
|
||||
command => "/usr/bin/virsh define $targetxmlfile",
|
||||
unless => "/usr/bin/virsh list | grep -c ' ${n1k_vsm::vsmname} .* running'",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_Create_VSM":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\nExec_Launch_VSM \n command=/bin/echo /usr/bin/virsh define $targetxmlfile \n unless=/usr/bin/virsh list --all | grep -c ' ${n1k_vsm::vsmname} ' \" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
exec { "Exec_Launch_VSM":
|
||||
command => "/usr/bin/virsh start ${n1k_vsm::vsmname}",
|
||||
unless => "/usr/bin/virsh list --all | grep -c ' ${n1k_vsm::vsmname} .* running '",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_Launch_VSM":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\nExec_Launch_VSM \n command=/bin/echo /usr/bin/virsh start ${n1k_vsm::vsmname} \n unless=/usr/bin/virsh list --all | grep -c ' ${n1k_vsm::vsmname} .* running' \" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
Exec["Exec_create_disk"] -> File["File_Target_XML_File"] -> Exec["Exec_Create_VSM"] -> Exec["Exec_Launch_VSM"]
|
||||
}
|
||||
|
46
manifests/init.pp
Normal file
46
manifests/init.pp
Normal file
@ -0,0 +1,46 @@
|
||||
class n1k_vsm(
|
||||
$configureovs = false,
|
||||
$ovsbridge,
|
||||
$physicalinterfaceforovs = 'enp1s0f0',
|
||||
$nodeip,
|
||||
$nodenetmask,
|
||||
$nodegateway,
|
||||
$vsmname,
|
||||
$consolepts = 2,
|
||||
$role = 'primary',
|
||||
$domainid,
|
||||
$adminpasswd,
|
||||
$mgmtip,
|
||||
$mgmtnetmask,
|
||||
$mgmtgateway,
|
||||
$ctrlinterface,
|
||||
$mgmtinterface,
|
||||
$pktinterface,
|
||||
$memory = 4096000,
|
||||
$vcpu = 2,
|
||||
$disksize = 4,
|
||||
$n1kv_source = "puppet:///modules/n1k_vsm/vsm.iso",
|
||||
$n1kv_version = "latest",
|
||||
)
|
||||
{
|
||||
|
||||
$imgfile = "/var/spool/vsm/${role}_repacked.iso"
|
||||
$diskfile = "/var/spool/vsm/${role}_disk"
|
||||
|
||||
$Debug_Print = "/usr/bin/printf"
|
||||
$Debug_Log = "/tmp/n1kv_vsm_puppet.log"
|
||||
|
||||
#
|
||||
# Clean up debug log
|
||||
#
|
||||
file {"File_$Debug_Log":
|
||||
path => $Debug_Log,
|
||||
ensure => "absent",
|
||||
}
|
||||
|
||||
include n1k_vsm::pkgprep_ovscfg
|
||||
include n1k_vsm::vsmprep
|
||||
include n1k_vsm::deploy
|
||||
|
||||
File["File_$Debug_Log"] -> Class['n1k_vsm::pkgprep_ovscfg'] -> Class['n1k_vsm::vsmprep'] -> Class['n1k_vsm::deploy']
|
||||
}
|
264
manifests/pkgprep_ovscfg.pp
Normal file
264
manifests/pkgprep_ovscfg.pp
Normal file
@ -0,0 +1,264 @@
|
||||
class n1k_vsm::pkgprep_ovscfg {
|
||||
|
||||
# Definition of sync points
|
||||
|
||||
$Sync_Point_KVM = "##SYNC_POINT_KVM"
|
||||
$Sync_Point_Virsh_Network = "##SYNC_POINT_VIRSH_NETWORK"
|
||||
|
||||
case "$::osfamily" {
|
||||
"RedHat": {
|
||||
#
|
||||
# Order indepedent resources
|
||||
#
|
||||
service {"Service_network":
|
||||
name => "network",
|
||||
ensure => "running",
|
||||
restart => "/sbin/service network restart || /bin/true",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Service_network":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Service_network\n name=network\n ensure=running\n enable=true\n restart=/sbin/service network restart\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
# VSM dependent packages installation section
|
||||
#
|
||||
# Eng note
|
||||
# cwchang: Ideally we should have either of this logic
|
||||
# 1. Have an iteration thru the package list in the $pkgs.each ...
|
||||
# Somehow this syntax needs to turn on future parser by document
|
||||
# 2. package resource should be able to run a name list
|
||||
# Neither one works. We go for rudimentary one-by-one here for now.
|
||||
# Pitfalls observed:
|
||||
# 1. We cannot reassign variables for some reason
|
||||
# 2. We cannot leave spaces in name
|
||||
# qemu-kvm-rhev
|
||||
package {"Package_qemu-kvm":
|
||||
name => "qemu-kvm",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_qemu-kvm":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_qemu-kvm \n name=qemu-kvm \n ensure=installed\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
package {"Package_virt-viewer":
|
||||
name => "virt-viewer",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_virt-viewer":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_virt-viewer \n name=virt-viewer \n ensure=installed \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
package {"Package_virt-manager":
|
||||
name => "virt-manager",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_virt-manager":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_virt-manager \n name=virt-manager \n ensure=installed\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
package {"Package_libvirt":
|
||||
name => "libvirt",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_libvirt":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_libvirt \n name=libvirt \n ensure=installed\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
package {"Package_libvirt-python":
|
||||
name => "libvirt-python",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_libvirt-python":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_libvirt-python \n name=libvirt-python \n ensure=installed\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#package {"Package_python-virtinst":
|
||||
# name => "python-virtinst",
|
||||
# ensure => "installed",
|
||||
# before => Notify["$Sync_Point_KVM"],
|
||||
#}
|
||||
#->
|
||||
#exec {"Debug_Package_python-virtinst":
|
||||
# command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_python-virtinst \n name=python-virtinst \n ensure=installed \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
#}
|
||||
|
||||
#package {"Package_genisoimage":
|
||||
# name => "genisoimage",
|
||||
# ensure => "installed",
|
||||
# before => Notify["$Sync_Point_KVM"],
|
||||
#}
|
||||
#->
|
||||
#exec {"Debug_Package_genisoimage":
|
||||
# command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_genisoimage \n name=genisoimage \n ensure=installed \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
#}
|
||||
|
||||
package {"Package_ebtables":
|
||||
name => "ebtables",
|
||||
#ensure => "purged",
|
||||
ensure => "installed",
|
||||
before => Notify["$Sync_Point_KVM"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_ebtables":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_ebtables \n name=ebtables \n ensure=purged \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
notify{"$Sync_Point_KVM":}
|
||||
|
||||
service {"Service_libvirtd":
|
||||
name => "libvirtd",
|
||||
ensure => "running",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Service_libvirtd":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Service_libvirtd\n name=libvirtd \n ensure=running \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#
|
||||
# Virsh network exec configuration section
|
||||
#
|
||||
exec {"Exec_removenet":
|
||||
command => "/usr/bin/virsh net-destroy default || /bin/true",
|
||||
unless => "/usr/bin/virsh net-info default | /bin/grep -c 'Active: .* no'",
|
||||
before => Notify["$Sync_Point_Virsh_Network"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_removenet":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_removenet \n command=/usr/bin/virsh net-destroy default || /bin/true \n unless=/usr/bin/virsh net-info default | /bin/grep -c 'Active: .* no'\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
exec {"Exec_disableautostart":
|
||||
command => "/usr/bin/virsh net-autostart --disable default || /bin/true",
|
||||
unless => "/usr/bin/virsh net-info default | /bin/grep -c 'Autostart: .* no'",
|
||||
before => Notify["$Sync_Point_Virsh_Network"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_disableautostart":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_disableautostart' \n command=/usr/bin/virsh net-autostart --disable default || /bin/true \n unless /usr/bin/virsh net-info default | grep -c 'Autostart: .* no'\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
notify{"$Sync_Point_Virsh_Network":}
|
||||
|
||||
package {"Package_openvswitch":
|
||||
name => "openvswitch",
|
||||
ensure => "installed",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Package_openvswitch":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Package_openvswitch \n name=openvswitch \n ensure=installed\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
#
|
||||
# bring up OVS and perform interface configuration
|
||||
#
|
||||
|
||||
service {"Service_openvswitch":
|
||||
name => "openvswitch",
|
||||
ensure => "running",
|
||||
enable => "true",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Service_openvswitch":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Service_openvswitch \n name=openvswitch \n ensure=running \n enable=true\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
|
||||
exec {"Exec_AddOvsBr":
|
||||
command => "/usr/bin/ovs-vsctl -- --may-exist add-br $n1k_vsm::ovsbridge",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_AddOvsBr":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_AddOvsBr \n command=/usr/bin/ovs-vsctl -- --may-exist add-br $n1k_vsm::ovsbridge \n \" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#
|
||||
# Modify Ovs bridge inteface configuation file
|
||||
#
|
||||
augeas {"Augeas_modify_ifcfg-ovsbridge":
|
||||
name => "$n1k_vsm::ovsbridge",
|
||||
context => "/files/etc/sysconfig/network-scripts/ifcfg-$n1k_vsm::ovsbridge",
|
||||
changes => [
|
||||
"set DEVICE $n1k_vsm::ovsbridge",
|
||||
"set BOOTPROTO none",
|
||||
"set IPADDR $n1k_vsm::nodeip",
|
||||
"set NETMASK $n1k_vsm::nodenetmask",
|
||||
"set ONBOOT yes",
|
||||
"set TYPE OVSBridge",
|
||||
"set DEVICETYPE ovs",
|
||||
],
|
||||
notify => Service["Service_network"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Augeas_modify_ifcfg-ovsbridge":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Augeas_modify_ifcfg-$n1k_vsm::ovsbridge \n name=$n1k_vsm::ovsbridge \n context=/files/etc/sysconfig/network-scripts/ifcfg-$n1k_vsm::ovsbridge \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#
|
||||
# Modify Physical Interface config file
|
||||
#
|
||||
augeas {"Augeas_modify_ifcfg-physicalinterfaceforovs":
|
||||
name => "$n1k_vsm::physicalinterfaceforovs",
|
||||
context => "/files/etc/sysconfig/network-scripts/ifcfg-$n1k_vsm::physicalinterfaceforovs",
|
||||
changes => [
|
||||
"set ONBOOT yes",
|
||||
"set BOOTPROTO none",
|
||||
"set TYPE OVSPort",
|
||||
"set DEVICETYPE ovs",
|
||||
"set OVS_BRIDGE $n1k_vsm::ovsbridge",
|
||||
"rm IPADDR",
|
||||
"rm NETMASK",
|
||||
],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Augeas_modify_ifcfg-physicalinterfaceforovs":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Augeas_modify_ifcfg-physicalinterfaceforovs \n name=$n1k_vsm::physicalinterfaceforovs \n context=/files/etc/sysconfig/network-scripts/ifcfg-$n1k_vsm::physicalinterfaceforovs\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
$intf=$n1k_vsm::physicalinterfaceforovs
|
||||
$phy_bridge="/tmp/phy_bridge"
|
||||
#
|
||||
# Move physical port around from host bridge if any, to ovs bridge
|
||||
#
|
||||
#exec {"Exec_phy_bridge":
|
||||
# command => "/usr/sbin/brctl show | /bin/grep $intf | /bin/sed 's/[\t ].*//' > $phy_bridge",
|
||||
#}
|
||||
#->
|
||||
#exec {"Debug_Exec_phy_bridge":
|
||||
# command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_phy_bridge \n /usr/sbin/brctl show | /bin/grep $intf | /bin/sed 's/[\t ].*//' > $phy_bridge \n \" >> ${n1k_vsm::Debug_Log}",
|
||||
#}
|
||||
|
||||
exec {"Exec_rebridge":
|
||||
#command => "/usr/bin/test -s $phy_bridge && /usr/sbin/brctl delif \$(cat $phy_bridge) $intf || /bin/true; /usr/bin/ovs-vsctl -- --may-exist add-port $n1k_vsm::ovsbridge $intf",
|
||||
command => "/usr/bin/ovs-vsctl -- --may-exist add-port $n1k_vsm::ovsbridge $intf",
|
||||
#notify => Service["Service_network"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_rebridge":
|
||||
#command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_rebridge \n /usr/bin/test -s $phy_bridge && /usr/sbin/brctl delif \$(cat $phy_bridge) $intf || /bin/true; /usr/bin/ovs-vsctl -- --may-exist add-port $n1k_vsm::ovsbridge $intf; /bin/rm -f $phy_bridge \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_rebridge \n /usr/bin/ovs-vsctl -- --may-exist add-port $n1k_vsm::ovsbridge $intf \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#
|
||||
# Order enforcement logic
|
||||
#
|
||||
#Notify["$Sync_Point_KVM"] -> Service["Service_libvirtd"] -> Notify["$Sync_Point_Virsh_Network"] -> Package["Package_openvswitch"] -> Service["Service_openvswitch"] -> Exec["Exec_AddOvsBr"]->Augeas["Augeas_modify_ifcfg-ovsbridge"]->Augeas["Augeas_modify_ifcfg-physicalinterfaceforovs"]->Exec["Exec_phy_bridge"]->Exec["Exec_rebridge"]
|
||||
Notify["$Sync_Point_KVM"] -> Service["Service_libvirtd"] -> Notify["$Sync_Point_Virsh_Network"] -> Package["Package_openvswitch"] -> Service["Service_openvswitch"] -> Exec["Exec_AddOvsBr"]->Augeas["Augeas_modify_ifcfg-ovsbridge"]->Augeas["Augeas_modify_ifcfg-physicalinterfaceforovs"]->Exec["Exec_rebridge"]
|
||||
}
|
||||
"Ubuntu": {
|
||||
}
|
||||
default: {
|
||||
#
|
||||
# bail out for unsupported OS
|
||||
#
|
||||
fail("<Error>: os[$os] is not supported")
|
||||
}
|
||||
}
|
||||
}
|
162
manifests/vsmprep.pp
Normal file
162
manifests/vsmprep.pp
Normal file
@ -0,0 +1,162 @@
|
||||
class n1k_vsm::vsmprep {
|
||||
include 'stdlib'
|
||||
|
||||
#
|
||||
# VSM package source parsing logic
|
||||
#
|
||||
$source = $n1k_vsm::n1kv_source
|
||||
|
||||
$source_method = regsubst($source, "^(.+):.*", '\1')
|
||||
$dest = inline_template('<%= File.basename(source) %>')
|
||||
|
||||
|
||||
$VSM_Bin_Prepare_Sync_Point="##VSM_BIN_PREPARE_SYNC_POINT"
|
||||
$VSM_Spool_Dir="/var/spool/vsm"
|
||||
$VSM_RPM_Install_Dir="/opt/cisco/vsm"
|
||||
$VSM_Repackage_Script_Name="repackiso.py"
|
||||
$VSM_Repackage_Script="/tmp/$VSM_Repackage_Script_Name"
|
||||
$VSM_DEST="$VSM_Spool_Dir/$dest"
|
||||
$VSM_PKG_NAME="nexus-1000v-vsm"
|
||||
$VSM_ISO="vsm.iso"
|
||||
|
||||
#
|
||||
# prepare vsm spool folder
|
||||
#
|
||||
file {"File_VSM_Spool_Dir":
|
||||
path => "$VSM_Spool_Dir",
|
||||
ensure => "directory",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
mode => "664",
|
||||
}
|
||||
->
|
||||
exec {"Debug_File_VSM_Spool_Dir":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n File_VSM_Spool_Dir\n path=$VSM_Spool_Dir \n ensure=directory \n owner=root \n group=root \n mode=664 \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
|
||||
case "$source_method" {
|
||||
"http": {
|
||||
yumrepo {"http-cisco-foreman":
|
||||
baseurl => "$n1k_vsm::n1kv_source",
|
||||
descr => "Internal repo for Foreman",
|
||||
enabled => "1",
|
||||
gpgcheck => "1",
|
||||
proxy => "_none_",
|
||||
gpgkey => "${n1k_vsm::n1kv_source}/RPM-GPG-KEY",
|
||||
}
|
||||
->
|
||||
package {"Package_VSM":
|
||||
name => "$VSM_PKG_NAME",
|
||||
ensure => "${n1k_vsm::n1kv_version}",
|
||||
}
|
||||
->
|
||||
exec {"Copy_VSM":
|
||||
command => "/bin/cp $VSM_RPM_Install_Dir/*.iso $VSM_Spool_Dir/$VSM_ISO",
|
||||
before => Notify["$VSM_Bin_Prepare_Sync_Point"],
|
||||
}
|
||||
->
|
||||
exec {"Debug-http-cisco-os and Package_VSM":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Debug-http-cisco-os and Package_VSM \n baseurl=$n1k_vsm::n1kv_source \n descr=>Internal repo for Foreman \n enabled = 1 \n gpgcheck=1 \n gpgkey => $n1kv_source::n1kv_source/RPM-GPG-KEY\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
}
|
||||
|
||||
"ftp": {
|
||||
package {"ftp":
|
||||
name => "ftp",
|
||||
ensure => "installed",
|
||||
}
|
||||
->
|
||||
yumrepo {"ftp-cisco-foreman":
|
||||
baseurl => "$n1k_vsm::n1kv_source",
|
||||
descr => "Internal repo for Foreman",
|
||||
enabled => "1",
|
||||
gpgcheck => "1",
|
||||
proxy => "_none_",
|
||||
gpgkey => "${n1k_vsm::n1kv_source}/RPM-GPG-KEY",
|
||||
}
|
||||
->
|
||||
package {"Package_VSM":
|
||||
name => "$VSM_PKG_NAME",
|
||||
ensure => "${n1k_vsm::n1kv_version}",
|
||||
}
|
||||
->
|
||||
exec {"Copy_VSM":
|
||||
command => "/bin/cp $VSM_RPM_Install_Dir/*.iso $VSM_Spool_Dir/$VSM_ISO",
|
||||
before => Notify["$VSM_Bin_Prepare_Sync_Point"],
|
||||
}
|
||||
->
|
||||
exec {"Debug-ftp-cisco-os and Package_VSM":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Debug-ftp-cisco-os and Package_VSM \n baseurl=$n1k_vsm::n1kv_source \n descr=>Internal repo for Foreman \n enabled = 1 \n gpgcheck=1 \n gpgkey => $n1kv_source::n1kv_source/RPM-GPG-KEY\n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
}
|
||||
"puppet": {
|
||||
#
|
||||
# make sure the file does not exist
|
||||
#
|
||||
exec {"File_VSM_Bin_Remove":
|
||||
command => "/bin/rm -f $VSM_DEST || /bin/true",
|
||||
before => Notify["$VSM_Bin_Prepare_Sync_Point"],
|
||||
}
|
||||
->
|
||||
file {"File_VSM_Bin_Prepare":
|
||||
path => "$VSM_DEST",
|
||||
ensure => "present",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
mode => "664",
|
||||
source => "$n1k_vsm::n1kv_source",
|
||||
before => Notify["$VSM_Bin_Prepare_Sync_Point"],
|
||||
}
|
||||
->
|
||||
exec {"Exec_RPM_TO_ISO":
|
||||
#
|
||||
# If it's an RPM, we do a local rpm installation ..."
|
||||
#
|
||||
command => "/bin/rpm -i --force $VSM_DEST && /bin/cp $VSM_RPM_Install_Dir/*.iso $VSM_Spool_Dir/$VSM_ISO",
|
||||
unless => "/usr/bin/file $VSM_DEST | /bin/grep -c ' ISO '",
|
||||
before => Notify["$VSM_Bin_Prepare_Sync_Point"],
|
||||
}
|
||||
->
|
||||
exec {"Debug_File_VSM_Bin_Prepare_Exec_RPM_TO_ISO":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Debug_File_VSM_Bin_Prepare_Exec_RPM_TO_ISO \n path=$VSM_DEST \n ensure=directory \n owner=root\n group=root\n mode=664\n source=$n1k_vsm::n1kv_source\n \" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
}
|
||||
default: {
|
||||
fail("<Error>: Unknown sourcing method [$source_method] is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
notify {"$VSM_Bin_Prepare_Sync_Point":}
|
||||
|
||||
#
|
||||
# copy repackiso.py to local place
|
||||
#
|
||||
file {"File_VSM_Repackage_Script_Name":
|
||||
path => "$VSM_Repackage_Script",
|
||||
ensure => "present",
|
||||
owner => "root",
|
||||
group => "root",
|
||||
mode => "774",
|
||||
source => "puppet:///modules/n1k_vsm/$VSM_Repackage_Script_Name",
|
||||
}
|
||||
->
|
||||
exec {"Debug_File_VSM_Repackage_Script_Name":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Debug_VSM_Repackage_Script_Name \n path=$VSM_Repackage_Script \n ensure=present \n owner=root \n group=root \n mode=774\n source=puppet:///modules/n1k_vsm/$VSM_REPACKAGE_SCRIPT_NAME \n\" >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
|
||||
#
|
||||
# Now generate ovf xml file and repackage the iso
|
||||
#
|
||||
exec {"Exec_VSM_Repackage_Script_Name":
|
||||
command => "${VSM_Repackage_Script} -i$VSM_Spool_Dir/$VSM_ISO -d${n1k_vsm::domainid} -n${n1k_vsm::vsmname} -m${n1k_vsm::mgmtip} -s${n1k_vsm::mgmtnetmask} -g${n1k_vsm::mgmtgateway} -p${n1k_vsm::adminpasswd} -r${n1k_vsm::role} -f${VSM_Spool_Dir}/${n1k_vsm::role}_repacked.iso >> ${n1k_vsm::Debug_Log}",
|
||||
}
|
||||
->
|
||||
exec {"Debug_Exec_VSM_Repackage_Script_Name":
|
||||
command => "${n1k_vsm::Debug_Print} \"[INFO]\n Exec_VSM_Repackage_Script_Name\n command=$VSM_Repackage_Script -i$VSM_ISO -d${n1k_vsm::domainid} -n${n1k_vsm::vsmname} -m${n1k_vsm::mgmtip} -s${n1k_vsm::mgmtnetmask} -g${n1k_vsm::mgmtgateway} -p${n1k_vsm::adminpasswd} -r${n1k_vsm::role} -f${VSM_Spool_Dir}/${n1k_vsm::role}_repacked.iso \n\" >> ${n1k_vsm::Debug_Log}"
|
||||
}
|
||||
|
||||
File["File_VSM_Spool_Dir"]-> Notify["$VSM_Bin_Prepare_Sync_Point"]->File["File_VSM_Repackage_Script_Name"]->Exec["Exec_VSM_Repackage_Script_Name"]
|
||||
|
||||
}
|
86
templates/vsm_vm.xml.erb
Normal file
86
templates/vsm_vm.xml.erb
Normal file
@ -0,0 +1,86 @@
|
||||
<domain type='kvm' >
|
||||
<name><%= scope.lookupvar('n1k_vsm::vsmname') %></name>
|
||||
<memory unit='KiB'><%= scope.lookupvar('n1k_vsm::memory') %></memory>
|
||||
<vcpu placement='static'> <%= scope.lookupvar('n1k_vsm::vcpu') %></vcpu>
|
||||
|
||||
<os>
|
||||
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
|
||||
<features> <acpi/> <apic/> <pae/> </features>
|
||||
|
||||
<clock offset='localtime'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
|
||||
<devices>
|
||||
<emulator>/usr/libexec/qemu-kvm</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='<%= scope.lookupvar('n1k_vsm::diskfile') %>'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='<%= scope.lookupvar('n1k_vsm::imgfile') %>'/>
|
||||
<target dev='hdb' bus='ide'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
|
||||
<controller type='ide' index='0'>
|
||||
<alias name='ide0'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
|
||||
<interface type='bridge'>
|
||||
<mac address='<%= @ctrlmac %>'/>
|
||||
<source bridge='<%= @ctrlbridge %>'/>
|
||||
<virtualport type='openvswitch' />
|
||||
<target dev='<%= @ctrltap %>'/>
|
||||
<model type='e1000'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</interface>
|
||||
|
||||
<interface type='bridge'>
|
||||
<mac address='<%= @mgmtmac %>'/>
|
||||
<source bridge='<%= @mgmtbridge %>'/>
|
||||
<virtualport type='openvswitch' />
|
||||
<target dev='<%= @mgmttap %>'/>
|
||||
<model type='e1000'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</interface>
|
||||
|
||||
<interface type='bridge'>
|
||||
<mac address='<%= @pktmac %>'/>
|
||||
<source bridge='<%= @pktbridge %>'/>
|
||||
<virtualport type='openvswitch' />
|
||||
<target dev='<%= @pkttap %>'/>
|
||||
<model type='e1000'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</interface>
|
||||
|
||||
<input type='mouse' bus='ps2'/>
|
||||
|
||||
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'>
|
||||
<listen type='address' address='0.0.0.0'/>
|
||||
</graphics>
|
||||
|
||||
<video>
|
||||
<model type='cirrus' vram='9216' heads='1'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</memballoon>
|
||||
|
||||
<console type='pty' tty='/dev/pts/<%= scope.lookupvar('n1k_vsm::consolepts') %>'>
|
||||
<source path='/dev/pts/<%= scope.lookupvar('n1k_vsm::consolepts') %>'/>
|
||||
<target port='0'/>
|
||||
</console>
|
||||
</devices>
|
||||
</domain>
|
Loading…
x
Reference in New Issue
Block a user