码迷,mamicode.com
首页 > Web开发 > 详细

Cobbler Web界面操作(五)

时间:2015-07-06 21:53:52      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:cobbler

编辑snippet

1、添加自动意的snippet文件

技术分享

技术分享



2、把下面的三个自定义的snippet文件添加上

1)、my_add_command

rm -rf /etc/yum.repos.d/CentOS*


modprobe 8021q


sed -i /GATEWAY/d /etc/sysconfig/network-scripts/ifcfg-`route -n | awk  ‘{if ($2 == "192.168.102.254" ) print $8}‘`



cat >/etc/hosts <<-EOF

172.16.15.1 hscloud-node1

172.16.15.2 hscloud-node2

172.16.15.3 hscloud-node3

172.16.15.4 hscloud-node4

172.16.15.5 hscloud-node5

172.16.15.6 hscloud-node6

172.16.15.7 hscloud-node7

172.16.15.8 hscloud-node8

172.16.15.9 hscloud-node9

172.16.15.10 hscloud-node10

EOF



echo "*/30 * * * *   ntpdate 172.16.15.1" >> /var/spool/cron/root




mkdir /root/.ssh/


chmod 700 /root/.ssh/

cat >/root/.ssh/config <<-EOF


StrictHostKeyChecking no


UserKnownHostsFile /dev/null


EOF






cat >/root/.ssh/id_rsa <<-EOF

-----BEGIN RSA PRIVATE KEY-----

MIIEoQIBAAKCAQEA159xWLESQKxo7xm2iN5Gs//YXvOX6H4pcZJnCgc53vT4I4Di

h3SdnS7g33WezkzNjasuzuiflWB7XkPnCHWMP2LpshY7MAjMtgfv3t4Lo7W4zlhh

IgrynJbzPCFMgLQhCAzOzgOPgV/szPA0ydka82Mo9eScUnzLOuVFYEjCKe2g/TVL

mmfIgMtE4bI3G6df8BNH+9g/L5id/fWT+FUMjVX0gMWgd3Q9xi984WJaQKQu+y60

tt1s38P/5xA1+ly7jN8MgJeHTRt//Xa61g7n5qWd1z29HJObmT2KbvuWyZXxYJLd

KyWcfIRxPY7hursIBHtEmvGnaau/gD4XLe7QlwIBIwKCAQAYpIH7gfN1GwStnInj

waGuK942vMDnXuAqPJ4Pxk/BtZizmbN9MeYgl6Sr0u2T64U0wxtK2MHH7cT01I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WDKJY211Ut5snkV6wGKb5KkVczzRjmvCv77rH9

b80ZLdnIvTS8clQIQE/0DVwmEQ5LNf9vdIMKr6gZ2CEMySyzsA==

-----END RSA PRIVATE KEY-----

EOF


cat >>/root/.ssh/authorized_keys <<-EOF

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA159xWLESQKxo7xm2iN5Gs//YXvOX6H4pcZJnCgc53vT4I4Dih3SdnS7g33WezkzNjasuzuiflWB7XkPnCHWMP2LpshY7MAjMtgfv3t4Lo7W4zlhhIgrynJbzPCFMgLQhCAzOzgOPgV/szPA0ydka82Mo9eScUnzLOuVFYEjCKe2g/TVLmmfIgMtE4bI3G6df8BNH+9g/L5id/fWT+FUMjVX0gMWgd3Q9xi984WJaQKQu+y60tt1s38P/5xA1+ly7jN8MgJeHTRt//Xa61g7n5qWd1z29HJObmT2KbvuWyZXxYJLdKyWcfIRxPY7hursIBHtEmvGnaau/gD4XLe7Qlw== root@bgw-os-node152

EOF


chmod 600 /root/.ssh/id_rsa


chmod 600 /root/.ssh/authorized_keys






useradd nova -U  -d /var/lib/nova


mkdir -p /var/lib/nova/.ssh/


chmod 700 /var/lib/nova/.ssh/



cat >/var/lib/nova/.ssh/config <<-EOF


StrictHostKeyChecking no


UserKnownHostsFile /dev/null


EOF



cat > /var/lib/nova/.ssh/id_rsa <<-EOF

-----BEGIN RSA PRIVATE KEY-----

MIIEoQIBAAKCAQEA159xWLESQKxo7xm2iN5Gs//YXvOX6H4pcZJnCgc53vT4I4Di

h3SdnS7g33WezkzNjasuzuiflWB7XkPnCHWMP2LpshY7MAjMtgfv3t4Lo7W4zlhh

IgrynJbzPCFMgLQhCAzOzgOPgV/szPA0ydka82Mo9eScUnzLOuVFYEjCKe2g/TVL

mmfIgMtE4bI3G6df8BNH+9g/L5id/fWT+FUMjVX0gMWgd3Q9xi984WJaQKQu+y60

tt1s38P/5xA1+ly7jN8MgJeHTRt//Xa61g7n5qWd1z29HJObmT2KbvuWyZXxYJLd

KyWc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BEPexZKjgD4KL72rOqSMWZJV/da

B0sCgYAwQu2sW2ohR5ZCtI5WZTmSIi5KcBtGCHM8UIMQhl0TgQni83LfkBaUcHAr

Wi6lVvEkFDKpjkS1GICA1JT7vQWDKJY211Ut5snkV6wGKb5KkVczzRjmvCv77rH9

b80ZLdnIvTS8clQIQE/0DVwmEQ5LNf9vdIMKr6gZ2CEMySyzsA==

-----END RSA PRIVATE KEY-----

EOF


cat >>/var/lib/nova/.ssh/authorized_keys <<-EOF

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuWcKohvVRpFCGUAONrYYzFBWr5xZj0BZvWJ7JKf9Y7kEW7yX0A41j4XgV+xjajjye8UxI4eXaW2fgCH6fZe5WKrztlLEZzA6XdD5HnAmNSpys3311ChBYjPbPUvZLdRP2eq/Jc8BRFXQ5C7qgHxunwLP1Q4I+wf7/oaRUIhhoudtK9Dm1EFgWwO+FuTwLqPqV80+b/StVhEsjT9+10G4+I1UAQlOFMHIAWJf15H9rfMYelp979430tQnlzccKtTIkaq2jXeF8TNQosH9c3oL+r4PswL3xMTVbWAsFSmby5YEj5R+0d3Ah7yXDwFEcLhlcbh0cctncCG0HDXk+sAo6Q== nova@bgw-os-node151

EOF


chmod 600 /var/lib/nova/.ssh/id_rsa


chmod 600 /var/lib/nova/.ssh/authorized_keys


chmod 600 /var/lib/nova/.ssh/config



chown nova:nova /var/lib/nova -R


2)、my_root_ssh_key

cd /root

mkdir --mode=700 .ssh

cat >> .ssh/authorized_keys << "PUBLIC_KEY"

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCwww24e5eBdcNAFIYL/4LJ54eH5XQr1GmpuRB4m7NAcsC7PTt2BDob2P5bt+Rg1o64Aah2m1ajt3kIewEeVCKIC6Msocu4W2ERD893aVgo72Dn9+ogPpg7w/GA4GKyXg2DS4mCNPN8pLQa1wxrozyIFqyyNYDFzWE0mSJdwaWzqQ==

chmod 600 .ssh/authorized_keys


3)、my_pre_install_network_config

#if $getVar("system_name","") != ""

# Start pre_install_network_config generated code

#raw

# generic functions to be used later for discovering NICs

mac_exists() {

  [ -z "$1" ] && return 1


  if which ip 2>/dev/null >/dev/null; then

    ip -o link | grep -i "$1" 2>/dev/null >/dev/null

    return $?

  elif which esxcfg-nics 2>/dev/null >/dev/null; then

    esxcfg-nics -l | grep -i "$1" 2>/dev/null >/dev/null

    return $?

  else

    ifconfig -a | grep -i "$1" 2>/dev/null >/dev/null

    return $?

  fi

}

get_ifname() {

  if which ip 2>/dev/null >/dev/null; then

    IFNAME=$(ip -o link | grep -i "$1" | sed -e ‘s/^[0-9]*: //‘ -e ‘s/:.*//‘)

  elif which esxcfg-nics 2>/dev/null >/dev/null; then

    IFNAME=$(esxcfg-nics -l | grep -i "$1" | cut -d " " -f 1)

  else

    IFNAME=$(ifconfig -a | grep -i "$1" | cut -d " " -f 1)

    if [ -z $IFNAME ]; then

      IFNAME=$(ifconfig -a | grep -i -B 2 "$1" | sed -n ‘/flags/s/:.*$//p‘)

    fi

  fi

}

#end raw

    #set ikeys = $interfaces.keys()

    #import re

    #set $vlanpattern = $re.compile("[a-zA-Z0-9]+[\.][0-9]+")

    #set $routepattern = $re.compile("[0-9/.]+:[0-9.]+")

    ##

    ## Determine if we should use the MAC address to configure the interfaces first

    ## Only physical interfaces are required to have a MAC address

    #set $configbymac = True

    #for $iname in $ikeys

        #set $idata = $interfaces[$iname]

        #if $idata["mac_address"] == "" and not $vlanpattern.match($iname) and not $idata["interface_type"].lower() in ("master","bond","bridge","bonded_bridge_slave")

            #set $configbymac = False

        #end if

    #end for

    #set $i = 0


    #if $configbymac

        ## Output diagnostic message

# Start of code to match cobbler system interfaces to physical interfaces by their mac addresses

    #end if

    #for $iname in $ikeys

#  Start $iname

        #set $idata         = $interfaces[$iname]

        #set $mac           = $idata["mac_address"]

        #set $static        = $idata["static"]

        #set $ip            = $idata["ip_address"]

        #set $netmask       = $idata["netmask"]

        #set $iface_type    = $idata["interface_type"]

        #set $iface_master  = $idata["interface_master"]

        #set $if_gateway    = $idata["if_gateway"]

        #set $static_routes = $idata["static_routes"]

        #set $devfile       = "/etc/sysconfig/network-scripts/ifcfg-" + $iname

        #if $vlanpattern.match($iname)

            ## If this is a VLAN interface, skip it, anaconda doesn‘t know

            ## about VLANs.

            #set $is_vlan = "true"

        #else

            #set $is_vlan = "false"

        #end if

        #if ($configbymac and $is_vlan == "false" and $iface_type.lower() not in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")) or $iface_type.lower() in ("master","bond","bridge")

            ## This is a physical interface, hand it to anaconda. Do not

            ## process slave interface here.

            #if $iface_type.lower() in ("master","bond","bridge","bonded_bridge_slave")

                ## Find a slave for this interface

                #for $tiname in $ikeys

                    #set $tidata = $interfaces[$tiname]

                    #if $tidata["interface_type"].lower() in ("slave","bond_slave","bridge_slave") and $tidata["interface_master"].lower() == $iname

                        #if $tidata["mac_address"] != ‘‘:

                            #set $mac = $tidata["mac_address"]

#  Found a slave for this interface: $tiname ($mac)

                            #break

                        #end if

                    #else if $tidata["interface_type"].lower() == "bonded_bridge_slave" and $tidata["interface_master"].lower() == $iname

                        ## find a slave for this slave interface...

                        #for $stiname in $ikeys

                            #set $stidata = $interfaces[$stiname]

                            #if $stidata["interface_type"].lower() in ("slave","bond_slave","bridge_slave") and $stidata["interface_master"].lower() == $tiname

                                #if $stidata["mac_address"] != ‘‘:

                                    #set $mac = $stidata["mac_address"]

#  Found a slave for this interface: $tiname -> $stiname ($mac)

                                    #break

                                #end if

                            #end if

                        #end for

                    #end if

                #end for

            #end if

            #if $static and $ip != ""

                #if $netmask == ""

                    ## Netmask not provided, default to /24.

                    #set $netmask = "255.255.255.0"

                #end if

                #set $netinfo = "--bootproto=static --ip=%s --netmask=%s" % ($ip, $netmask)

                #if $if_gateway != ""

           #set $netinfo = "%s --gateway=%s" % ($netinfo, $if_gateway)

                #else

                    #set $netinfo = "%s --gateway=0.0.0.0" % ($netinfo)

                #end if

           #if $len($name_servers) > 0

               #set $netinfo = "%s --nameserver=%s" % ($netinfo, $name_servers[0])

                #end if

            #else if not $static

                #set $netinfo = "--bootproto=dhcp"

            #else

                ## Skip this interface, it‘s set as static, but without

                ## networking info.

#  Skipping (no configuration)...

                #continue

            #end if

            #if $hostname != ""

                #set $netinfo = "%s --hostname=%s" % ($netinfo, $hostname)

            #end if

# Configuring $iname ($mac)

if mac_exists $mac

then

  get_ifname $mac

  echo "network --device=\$IFNAME $netinfo " >> /tmp/pre_install_network_config

            #for $route in $static_routes

                #if $routepattern.match($route)

                    #set $routebits = $route.split(":")

                    #set [$network, $router] = $route.split(":")

  ip route add $network via $router dev \$IFNAME

                #else

  # Warning: invalid route "$route"

                #end if

            #end for

fi

        #else

            #if $iface_type.lower() in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")

#  Skipping (slave-interface)

            #else

#  Skipping (not a physical interface)...

            #end if

        #end if

    #end for

# End pre_install_network_config generated code

#end if



本文出自 “zhanguo1110” 博客,请务必保留此出处http://zhanguo1110.blog.51cto.com/5750817/1671442

Cobbler Web界面操作(五)

标签:cobbler

原文地址:http://zhanguo1110.blog.51cto.com/5750817/1671442

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!