Beispiel #1
0
        def getnextIP(self, subnet):
		"""originally compied from insert-ether"""
                self.db.execute("select subnet,netmask from subnets where name='%s'" % (subnet))
                network,mask = self.db.fetchone()
                mask_ip = rocks.ip.IPAddr(mask)
                network_ip = rocks.ip.IPAddr(network)
                bcast_ip = rocks.ip.IPAddr(network_ip | rocks.ip.IPAddr(~mask_ip))
                bcast = "%s" % (bcast_ip)

                if bcast != '' and mask != '':
                        ip = rocks.ip.IPGenerator(bcast, mask)
                        # look in the database for a free address
                        while 1:

                                # Go to the next ip address backward
                                ip.next(-1)

			        self.db.execute("""select networks.node from nodes,networks where
			                networks.node = nodes.id and networks.ip ="%s" and
			                (networks.device is NULL or
			                networks.device not like 'vlan%%') """ % (ip.curr()))
			        try:
			                nodeid, = self.db.fetchone()
			        except TypeError:
    			        	nodeid = None

                                if nodeid is None:
                                        return ip.curr()

                #
                # if we make it to here, an error occurred
                #
                print 'error: getnextIP: could not get IP address ',
                print 'for device (%s)' % (dev)
                return '0.0.0.0'
Beispiel #2
0
	def getnextIP(self, subnet):
	
		network,mask = self.getnetwork(subnet)
		mask_ip = rocks.ip.IPAddr(mask)
		network_ip = rocks.ip.IPAddr(network)
		bcast_ip = rocks.ip.IPAddr(network_ip | rocks.ip.IPAddr(~mask_ip))
		bcast = "%s" % (bcast_ip)
		
		if self.ipaddr is not None :
			return self.ipaddr

		if bcast != '' and mask != '':
		
			# Create the IPGenerator and if the user choose a 
			# base ip address to the IPGenerator to start there.
			# Should really be a method in the class to set this,
			# but I need this today on 3.2.0.  Revisit soon (mjk)
			
			ip = rocks.ip.IPGenerator(bcast, mask)
			if self.sql.ipBaseAddress:
				ip.addr = rocks.ip.IPAddr(
							self.sql.ipBaseAddress)

			#
			# look in the database for a free address
			#
			while 1:
			
				# Go to the next ip address.  Default is still
				# to count backwards, but allow the user to
				# set us to count forwards.
				
				ip.next(self.sql.ipIncrement)
				
				nodeid = self.sql.getNodeId(ip.curr())
				if nodeid is None:
					return ip.curr()

		#
		# if we make it to here, an error occurred
		#
		print 'error: getnextIP: could not get IP address ',
		print 'for device (%s)' % (dev)
		return '0.0.0.0'
Beispiel #3
0
	def run(self, param, args):

		(increment, baseip) = self.fillParams( [
			('increment', '-1'), 
			('baseip', '')
			])

		if len(args) != 1:
			self.abort('must supply the subnet')

		increment = int(increment)

		subnet = args[0]
		
		try:			
			subnet_db = self.newdb.getSession().query(rocks.db.mappings.base.Subnet)\
				.options(sqlalchemy.orm.joinedload('networks'))\
				.filter(Subnet.name == subnet).one()
		except sqlalchemy.orm.exc.NoResultFound:
			self.abort('subnet %s is not valid' % subnet)

		mask_ip = rocks.ip.IPAddr(subnet_db.netmask)
		network_ip = rocks.ip.IPAddr(subnet_db.subnet)
		bcast_ip = rocks.ip.IPAddr(network_ip | rocks.ip.IPAddr(~mask_ip))
		bcast = "%s" % (bcast_ip)
		used_ip = [ net.ip for net in subnet_db.networks]
		
		# Create the IPGenerator and if the user choose a 
		# base ip address to the IPGenerator to start there.
		# Should really be a method in the class to set this,
		# but I need this today on 3.2.0.  Revisit soon (mjk)
		ip = rocks.ip.IPGenerator(bcast, subnet_db.netmask)
		if baseip:
			ip.addr = rocks.ip.IPAddr(baseip)

		#
		# look in the database for a free address
		#
		while 1:
		
			# Go to the next ip address.  Default is still
			# to count backwards, but allow the user to
			# set us to count forwards.
			nextip = ip.next(increment)
			if str(nextip) not in used_ip:
				# we found it
				break

		self.beginOutput()
		self.addOutput('localhost', nextip)
		self.endOutput(padChar='')
Beispiel #4
0
    def getnextIP(self, subnet):
        """originally compied from insert-ether"""
        self.db.execute("select subnet,netmask from subnets where name='%s'" %
                        (subnet))
        network, mask = self.db.fetchone()
        mask_ip = rocks.ip.IPAddr(mask)
        network_ip = rocks.ip.IPAddr(network)
        bcast_ip = rocks.ip.IPAddr(network_ip | rocks.ip.IPAddr(~mask_ip))
        bcast = "%s" % (bcast_ip)

        if bcast != '' and mask != '':
            ip = rocks.ip.IPGenerator(bcast, mask)
            # look in the database for a free address
            while 1:

                # Go to the next ip address backward
                ip.next(-1)

                self.db.execute(
                    """select networks.node from nodes,networks where
			                networks.node = nodes.id and networks.ip ="%s" and
			                (networks.device is NULL or
			                networks.device not like 'vlan%%') """ % (ip.curr()))
                try:
                    nodeid, = self.db.fetchone()
                except TypeError:
                    nodeid = None

                if nodeid is None:
                    return ip.curr()

#
# if we make it to here, an error occurred
#
        print 'error: getnextIP: could not get IP address ',
        print 'for device (%s)' % (dev)
        return '0.0.0.0'
Beispiel #5
0
    def run(self, param, args):

        (increment, baseip) = self.fillParams([('increment', '-1'),
                                               ('baseip', '')])

        if len(args) != 1:
            self.abort('must supply the subnet')

        increment = int(increment)

        subnet = args[0]

        try:
            subnet_db = self.newdb.getSession().query(rocks.db.mappings.base.Subnet)\
             .options(sqlalchemy.orm.joinedload('networks'))\
             .filter(Subnet.name == subnet).one()
        except sqlalchemy.orm.exc.NoResultFound:
            self.abort('subnet %s is not valid' % subnet)

        mask_ip = rocks.ip.IPAddr(subnet_db.netmask)
        network_ip = rocks.ip.IPAddr(subnet_db.subnet)
        bcast_ip = rocks.ip.IPAddr(network_ip | rocks.ip.IPAddr(~mask_ip))
        bcast = "%s" % (bcast_ip)
        used_ip = [net.ip for net in subnet_db.networks]

        # Create the IPGenerator and if the user choose a
        # base ip address to the IPGenerator to start there.
        # Should really be a method in the class to set this,
        # but I need this today on 3.2.0.  Revisit soon (mjk)
        ip = rocks.ip.IPGenerator(bcast, subnet_db.netmask)
        if baseip:
            ip.addr = rocks.ip.IPAddr(baseip)

        #
        # look in the database for a free address
        #
        while 1:

            # Go to the next ip address.  Default is still
            # to count backwards, but allow the user to
            # set us to count forwards.
            nextip = ip.next(increment)
            if str(nextip) not in used_ip:
                # we found it
                break

        self.beginOutput()
        self.addOutput('localhost', nextip)
        self.endOutput(padChar='')