User Tools

Site Tools


cobbler_api_hook_for_vm_creation

This is an old revision of the document!


#!/bin/env python
import sys
import re
import xmlrpclib
import cobbler.api as capi
 
automagick = xmlrpclib.Server("http://automagick01vm.ewr1.pokkari.net/cobbler_api")
token = automagick.login("jthomas","*******")
default_profile = 'Centos5-Base-KVM-CORP'
 
#Get required information from user for vm creation:
if len(sys.argv) < 3:
  print ("usage: sys.argv[0] hostname")
  sys.exit(1)
 
## Need to check if it is also a valid hostname with proper fqdn 
def check_hostname (hostname):
  if len(automagick.find_system({"hostname":hostname})) == 0:
    return hostname
  else:
    print "already exists. please pass switch to reinstall"
    sys.exit(1)
 
def build_system_definition(hostname):
  host_id = automagick.new_system(token)
  automagick.modify_system(host_id,'name',hostname,token)
  automagick.modify_system(host_id,'profile',default_profile,token)
  automagick.save_system(host_id,token)
 
 
hostname = check_hostname(sys.argv[1])
print hostname
build_system_definition(hostname)
cobbler_api_hook_for_vm_creation.1311883489.txt.gz ยท Last modified: 2020/08/10 02:28 (external edit)