目前BootAPI 已经不再推荐在cobbler 2.0中使用,官方推荐使用使用XMLRPC
注:要正常使用API,需要确保cobbler服务器apache和cobbler正常运行
连接cobbler
import xmlrpclib server = xmlrpclib.Server("http://cobbler-server.example.org/cobbler_api")
登陆获取token,这个token在修改cobbler对象的时候需要提供,否则只能get
token = server.login("username","password")
获取cobbler服务器的相关信息
#!/usr/bin/python import xmlrpclib server = xmlrpclib.Server("http://127.0.0.1/cobbler_api") print server.get_distros() print server.get_profiles() print server.get_systems() print server.get_images() print server.get_repos()
在服务器上创建一个OS对象
import xmlrpclib remote = xmlrpclib.Server(http://127.0.0.1/cobbler_api) token = remote.login("username","password") distro_id = remote.new_distro(token) remote.modify_distro(distro_id, ‘name‘, ‘example-distro‘,token) remote.modify_distro(distro_id, ‘kernel‘, ‘/opt/stuff/vmlinuz‘,token) remote.modify_distro(distro_id, ‘initrd‘, ‘/opt/stuff/initrd.img‘,token) remote.save_distro(distro_id,token)
创建一个新的主机
remote = xmlrpclib.Server("http://127.0.0.1/cobbler_api") token = remote.login(SATELLITE_USER,SATELLITE_PASSWORD) system_id = remote.new_system(token) remote.modify_system(system_id,"name","hostname",token) remote.modify_system(system_id,"hostname","hostname.example.com",token) remote.modify_system(system_id,‘modify_interface‘, { "macaddress-eth0" : "01:02:03:04:05:06", "ipaddress-eth0" : "192.168.0.1", "dnsname-eth0" : "hostname.example.com", }, token) remote.modify_system(system_id,"profile","rhel6-x86_64",token) remote.modify_system(system_id,"kernel_options", "foo=bar some=thing", token) remote.modify_system(system_id,"ks_meta", "foo=bar some=thing", token) remote.save_system(system_id, token) remote.sync(token)
移除一个对象
remote.remove_profile("name-of-profile",token)
使用API读取ks文件内容,方便修改
remote.read_or_write_kickstart_template("/var/lib/cobbler/foo.ks",False,new_contents_as_a_string,token)
本文出自 “Linux is belong to you” 博客,请务必保留此出处http://jwh5566.blog.51cto.com/7394620/1760789
原文地址:http://jwh5566.blog.51cto.com/7394620/1760789