print "Missing hostname for the hostadd operation"
			exit(0)
		
		hostname = hostdef.check_hostname(args[1])
		if not hostname:
			print "The entered hostname is invalid"
			exit(0)
			
		# Check if this hostname is already registered
		hm = hostmanager.HostManager()
		if hm.host_exists(hostname=hostname):
			print 'The hostname: "%s" has already been registered use hostmod instead' % hostname
			exit(0)
		
		if options.ipaddr:
			ipchk = hostdef.check_ipaddr(options.ipaddr)
			if not ipchk:
				print 'The ipaddress: "%s" entered is not valid' % options.ipaddr
				exit(0)
				
		print "Hostname: %s" % hostname
		
		while not options.hwaddr or not hostdef.check_hwaddr(options.hwaddr):
			options.hwaddr = raw_input("Input the hardware address of the host's network interface (mac-address): ")
		options.hwaddr = hostdef.check_hwaddr(options.hwaddr)
			
		
		# Check if this hwaddr is already registered
		if hm.host_exists(hwaddr=options.hwaddr):
			print 'The hwaddr: "%s" has already been registered use hostmod instead' % options.hwaddr
			exit(0)
	def register_host(self,hwaddr,hostname,hosttype_id,ipaddr=None,update_hosts=True):
		"""
		Register a new host to the SkoleSYS network. The registrationid is the hwaddr
		but the hostname must be unique aswell. If no ipaddr is given or the given ipaddr 
		is in use the system will pick one for the host.
		"""
		
		# check sanity
		hwaddr = hostdef.check_hwaddr(hwaddr)
		if not hwaddr:
			return -1
		hostname = hostdef.check_hostname(hostname)
		if not hostname:
			return -2
		if not hostdef.hosttype_as_text(hosttype_id):
			return -3
		hosttype = hostdef.hosttype_as_text(hosttype_id)
		if ipaddr and not hostdef.check_ipaddr(ipaddr):
			return -4
		
		# check if the hwaddr is already registered.
		if self.host_exists(hwaddr=hwaddr):
			return -5
		
		# check if the hostname is already registered.
		if self.host_exists(hostname=hostname):
			return -6
		
		if ipaddr and self.ipaddr_exists(ipaddr):
			return -7
		
		if not ipaddr:
			ipaddr = self.fetch_next_ip(hosttype_id)
		
		# If still no ip address, there are no more ip addresses in the
		# ip range of the host type (expand the range in skolesys.conf)
		if not ipaddr:
			return -8
		
		path = "%s,%s,%s" % \
			('cn=%s'%hostname,\
			conf.get('LDAPSERVER','hosts_ou'),\
			conf.get('LDAPSERVER','basedn'))
		host_info = {'cn': hostname,
			'macAddress': hwaddr,
			'hostType': hosttype,
			'hostName': hostname,
			'ipHostNumber': ipaddr,
			'objectclass':('skoleSysHost','top')}
		
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.touch_by_dict({path:host_info})
		
		if update_hosts:
			# update-hosts=False is f.inst. used in seed-mainserver config scripts
			import skolesys.cfmachine.configbuilder as cb
			c = cb.ConfigBuilder(hostdef.hosttype_as_id('mainserver'),sysinfo.get_dist_codename(),'',context='update-hosts',context_only=True)
			curdir = os.getcwd()
			os.chdir(c.tempdir)
			os.system('./install.sh')
			os.chdir(curdir)
			del c
		
		return 1