1. 4 Cobbler高级话题

在实际的工作环境中,Cobbler还有很多高级的应用可以帮助我们更快的进行操作系统的部署工作。例如网卡绑定、电源管理和Cobbler API等。

1.1. 4.1 自定义物理网卡bonding

  1. 添加一台主机linux-node4
[root@linux-node1 ~]# cobbler system add --name=linux-node4 --profile=CentOS-7.7-x86_64 \
 --hostname=new.devopsedu.com \
 --name-servers="192.168.56.2" \
 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.7-x86_64-Cobbler.cfg
  1. 添加bonding网卡
[root@linux-node1 ~]# cobbler system edit --name=linux-node4 --interface=eth0 \
 --mac=00:50:56:27:F0:07 --interface-type=bond_slave --interface-master=bond0
  1. 添加bonding网卡
[root@linux-node1 ~]# cobbler system edit --name=linux-node4 --interface=eth1 \
 --mac=00:50:56:36:09:66 --interface-type=bond_slave --interface-master=bond0
  1. 设置绑定网卡
[root@linux-node1 ~]# cobbler system edit --name=linux-node4 --interface=bond0 \
 --interface-type=bond --bonding-opts="miimon=100 mode=1" \
 --ip-address=192.168.56.111 --subnet=255.255.255.0 --gateway=192.168.56.2 --static=1

好的,万事具备,就差开机安装操作系统了。等等,怎么开机呢?既然是自动化安装,打电话让机房值班人员帮我们开机当然是不合适的,还记得IPMI吗,我们可以使用IPMI来进行电源管理。

  1. 网卡绑定后的效果
[root@new ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:27:f0:07
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:36:09:66
Slave queue ID: 0

1.2. 4.2 Cobbler电源管理

要管理服务器的电源,你可以直接使用IPMI命令进行,也可以使用cobbler间接的调用IPMI进行操作。默认情况下Cobbler使用IPMI进行电源管理,我们可以在cobbler的settings配置看到以下配置。

[root@linux-node1 ~]# vim /etc/cobbler/settings
power_management_default_type: 'ipmitool'
power_template_dir: "/etc/cobbler/power"
[root@linux-node1 ~]# cobbler system edit --name=linux-node3 --power-address=192.168.0.21 --power-type='ipmilan' --power-user=ipmi --power-pass=ipmi

服务器电源管理:

  • cobbler system poweroff
  • cobbler system poweron
  • cobbler system powerstatus
  • cobbler system reboot

重启从PXE引导启动,并指定安装的操作系统配置,如下命令,

[root@log-node1 ~]# cobbler system edit  --name=host-188116  --netboot-enabled=1 --profile=centos5.8-x86_64
[root@log-node1 ~]# cobbler reposync

1.3. 4.3 Cobbler API使用

  1. 连接Cobbler

    [root@linux-node1 ~]# cat cobbler.py 
    #!/usr/bin/env python
    import xmlrpclib
    server = xmlrpclib.Server("http://192.168.56.11/cobbler_api")
    print server.get_distros()
    print server.get_profiles()
    print server.get_systems()
    print server.get_images()
    print server.get_repos()
    
  2. 登录Cobbler

默认情况下,不用登录Cobbler就可以获取到Cobbler的信息,但是如果需要进行操作,就需要登录。使用用户名和密码登录后,Cobbler会返回一个token令牌,后面的操作,我们调用任何一个Cobbler的方法,都需要将token作为最后一个参数。

[root@linux-node1 ~]# cat cobbler.py 
#!/usr/bin/env python
import xmlrpclib
server = xmlrpclib.Server("http://192.168.56.11/cobbler_api")
print server.get_distros()
print server.get_profiles()
print server.get_systems()
print server.get_images()
print server.get_repos()
token = server.login("cobbler","devopsedu.com")
print(token)


一个添加主机的例子
#!/usr/bin/env python 
# -*- coding: utf-8 -*-
import xmlrpclib 

class CobblerAPI(object):
    def __init__(self,url,user,password):
        self.cobbler_user= user
        self.cobbler_pass = password
        self.cobbler_url = url

    def add_system(self,hostname,ip_add,mac_add,profile):
        '''
        Add Cobbler System Infomation
        '''
        ret = {
            "result": True,
            "comment": [],
        }
        #get token
        remote = xmlrpclib.Server(self.cobbler_url) 
        token = remote.login(self.cobbler_user,self.cobbler_pass) 

        #add system
        system_id = remote.new_system(token) 
        remote.modify_system(system_id,"name",hostname,token) 
        remote.modify_system(system_id,"hostname",hostname,token) 
        remote.modify_system(system_id,'modify_interface', { 
            "macaddress-eth0" : mac_add, 
            "ipaddress-eth0" : ip_add, 
            "dnsname-eth0" : hostname, 
        }, token) 
        remote.modify_system(system_id,"profile",profile,token) 
        remote.save_system(system_id, token) 
        try:
            remote.sync(token)
        except Exception as e:
            ret['result'] = False
            ret['comment'].append(str(e))
        return ret

def main():
    cobbler = CobblerAPI("http://192.168.56.11/cobbler_api","cobbler","devopsedu.com")
    ret = cobbler.add_system(hostname='cobbler-api-test',ip_add='192.168.56.111',mac_add='00:50:56:25:C2:AA',profile='CentOS-7.4-x86_64')
    print ret

if __name__ == '__main__':
    main()
Copyright © 赵班长@新运维社区 2019 all right reserved,powered by Gitbook该文件修订时间: 2020-05-15 21:56:05

results matching ""

    No results matching ""