Пример #1
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		
Пример #2
0
	if cmd == "hostadd":
		parser.set_usage("usage: %s %s [options] hostname " % (shell_cmd_name,cmd))
		parser.add_option("-m", "--hw-addr", dest="hwaddr",default=None,
		                  help="The hardware address of the host's network interface (mac-address)", metavar="HWADDR")
		parser.add_option("-t", "--host-type", dest="hosttype",default=None,
		                  help="The host's type (mainserver,ltspserver,workstation)", metavar="HOSTTYPE")
		parser.add_option("-i", "--ip-address", dest="ipaddr",default=None,
		                  help="Try to register the host with this ip-address", metavar="IPADDR")
		(options, args) = parser.parse_args()
		
		if len(args)<2:
			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)
Пример #3
0
        portnum = options.portnum

    if not server_url:
        server_url = raw_input("Mainserver SOAP url [https://mainserver.localnet]: ")
        if server_url == "":
            server_url = "https://mainserver.localnet"

    if not portnum:
        portnum = raw_input("Mainserver SOAP port [10033]: ")
        if portnum == "":
            portnum = 10033
    else:
        portnum = int(portnum)

    if options.hostname:
        options.hostname = hostdef.check_hostname(options.hostname)
    while not options.hostname:
        input_hostname = raw_input("Input the hostname for the host being assigned: ")
        options.hostname = hostdef.check_hostname(input_hostname)
        if not options.hostname:
            print '"%s" is not a valid hostname. Use only letters and numbers.' % input_hostname

    hosttype_id = None
    if options.hosttype:
        hosttype_id = hostdef.hosttype_as_text(options.hosttype)
    while not hosttype_id:
        input_hosttype = raw_input("Input the host type (mainserver,ltspserver,workstation or ltspclient): ")
        hosttype_id = hostdef.hosttype_as_text(input_hosttype)
        if not hosttype_id:
            print '"%s" is not a valid host type.' % input_hosttype