• cobbler api


     1 try:
     2     import xmlrpclib
     3 
     4 except ImportError as e:
     5     import xmlrpc.client
     6 
     7 
     8 SERVER_IP = '192.168.144.11'
     9 
    10 
    11 try:
    12     # 连接你的cobbler服务器,ip自改,后面的url是固定的
    13     remote = xmlrpclib.Server("http://{}/cobbler_api".format(SERVER_IP))
    14 
    15 except Exception as e:
    16     remote = xmlrpc.client.Server("http://{}/cobbler_api".format(SERVER_IP))
    17 
    18 # 这个帐号密码就是登录cobbler web的帐号密码,用htdigest /etc/cobbler/users.digest "加密字符" cobbler命令生成
    19 token = remote.login("cobbler", "bfmq")
    20 
    21 # 身份认证后拿到token后以后就用token操作喽,新建一个系统,获取id
    22 system_id = remote.new_system(token)
    23 
    24 # 起一个名字,名字随意不重要,都是以id为标准操作的
    25 remote.modify_system(system_id, "name", "CentOS7.2-x86_64", token)
    26 
    27 # 关联相关profile,必须是cobbler profile list存在的
    28 remote.modify_system(system_id, "profile", "centos7.2-x86_64", token)
    29 
    30 # 关联kickstart,相当于cobbler profile edit --name=CentOS7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.2-x86_64.cfg
    31 remote.modify_system(system_id, "ks_meta", "/var/lib/cobbler/kickstarts/CentOS-7.2-x86_64.cfg", token)
    32 
    33 # 关联内核参数,相当于cobbler profile edit --name=CentOS7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0',这个装6系统不需要
    34 remote.modify_system(system_id, "kernel_options", "net.ifnames=0 biosdevname=0", token)
    35 
    36 # 这是对指定mac地址进行ip指定,但是在北看来没什么意义....因为你还要去查他的mac,更麻烦
    37 # remote.modify_system(system_id,'modify_interface', {
    38 #                 "macaddress-eth0"   : "66:66:66:66:66:66",
    39 #                 "ipaddress-eth0"    : "192.168.144.100",
    40 #                 "Gateway-eth0"      : "192.168.144.254",
    41 #                 "subnet-eth0"       : "255.255.255.0",
    42 #                 "static-eth0"       : 1,
    43 #                 "dnsname-eth0"      :"114.114.114.114"
    44 #         }, token)
    45 
    46 # 将刚才所有操作保存,如果在机器上执行cobbler system list就会发现多出了新系统的name
    47 remote.save_system(system_id, token)
    48 
    49 # 相当于ccobbler sync
    50 remote.sync(token)
  • 相关阅读:
    Hadoop之MapReduce
    Hadoop之序列化
    Hadoop之mapreduce 实例五
    Hadoop之hive和hadoop的交互流程
    protel总结1
    将正数十进制转换为2~16进制数
    基于verilog分频器总结
    MATLAB设计FIR滤波器
    centos7+hadoop完全分布式集群搭建
    Linux下常用配置文件
  • 原文地址:https://www.cnblogs.com/bfmq/p/7146765.html
Copyright © 2020-2023  润新知