diff --git a/files/repackiso.py b/files/repackiso.py
new file mode 100755
index 0000000..f768fa8
--- /dev/null
+++ b/files/repackiso.py
@@ -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 = ' \n'
+ st += ' \n'
+ st += ' \n'
+ st += 'VMware ESXi \n'
+ st += '4.0.0 \n'
+ st += 'VMware, Inc. \n'
+ st += 'en \n'
+ st += ' \n'
+ st += ' \n'
+ st += ' \n' % (domain)
+ st += ' \n'
+ st += ' \n' % (gateway)
+ st += ' \n' % (hostname)
+ st += ' \n' % (ip)
+ st += ' \n' % (subnet)
+ st += ' \n'
+ st += ' \n'
+ st += ' \n' % (password)
+ st += ' \n' % (vsm_mode)
+ #if vsm_mode == "primary":
+ # st += ' \n' % (vsm_mode)
+ #else:
+ # st += ' \n'
+ st += ' \n'
+ st += ' \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()
+
diff --git a/manifests/deploy.pp b/manifests/deploy.pp
new file mode 100644
index 0000000..c07bc31
--- /dev/null
+++ b/manifests/deploy.pp
@@ -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"]
+}
+
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..b546f96
--- /dev/null
+++ b/manifests/init.pp
@@ -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']
+}
diff --git a/manifests/pkgprep_ovscfg.pp b/manifests/pkgprep_ovscfg.pp
new file mode 100644
index 0000000..9ee8cb9
--- /dev/null
+++ b/manifests/pkgprep_ovscfg.pp
@@ -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(": os[$os] is not supported")
+ }
+ }
+}
diff --git a/manifests/vsmprep.pp b/manifests/vsmprep.pp
new file mode 100644
index 0000000..4c9ae86
--- /dev/null
+++ b/manifests/vsmprep.pp
@@ -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(": 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"]
+
+}
diff --git a/templates/vsm_vm.xml.erb b/templates/vsm_vm.xml.erb
new file mode 100644
index 0000000..74d017e
--- /dev/null
+++ b/templates/vsm_vm.xml.erb
@@ -0,0 +1,86 @@
+
+ <%= scope.lookupvar('n1k_vsm::vsmname') %>
+ <%= scope.lookupvar('n1k_vsm::memory') %>
+ <%= scope.lookupvar('n1k_vsm::vcpu') %>
+
+
+ hvm
+
+
+
+
+
+
+
+ destroy
+ restart
+ restart
+
+
+ /usr/libexec/qemu-kvm
+
+
+ '/>
+
+
+
+
+
+ '/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ '>
+ '/>
+
+
+
+