Пример #1
0
	def run(self, params, args):
		hosts = self.getHostnames(args)

		threads = []
		for host in hosts:
			#
			# make sure the host is a physical host
			#
			vm = rocks.vm.VM(self.db)
			if vm.isVM(host):
				continue

			if max_threading > 0:
				while threading.activeCount() > max_threading:
					#
					# need to wait for some threads to
					# complete before starting any new ones
					#
					time.sleep(0.001)

			cmd = '/opt/rocks/bin/rocks report host xen bridge '
			cmd += '%s | ' % host
			cmd += '/opt/rocks/bin/rocks report script | '
			cmd += 'ssh %s bash > /dev/null 2>&1' % host

			p = Parallel(cmd)
			threads.append(p)
			p.start()

		#
		# collect the threads
		#
		for thread in threads:
			thread.join(timeout)

		threads = []
		for host in hosts:
			if max_threading > 0:
				while threading.activeCount() > max_threading:
					#
					# need to wait for some threads to
					# complete before starting any new ones
					#
					time.sleep(0.001)

			cmd = 'ssh %s "/sbin/service xend restart" ' % host
			cmd += '> /dev/null 2>&1'

			p = Parallel(cmd)
			threads.append(p)
			p.start()

		#
		# collect the threads
		#
		for thread in threads:
			thread.join(timeout)
Пример #2
0
    def run(self, params, args):
        hosts = self.getHostnames(args)

        threads = []
        for host in hosts:
            #
            # make sure the host is a physical host
            #
            vm = rocks.vm.VM(self.db)
            if vm.isVM(host):
                continue

            if max_threading > 0:
                while threading.activeCount() > max_threading:
                    #
                    # need to wait for some threads to
                    # complete before starting any new ones
                    #
                    time.sleep(0.001)

            cmd = '/opt/rocks/bin/rocks report host xen bridge '
            cmd += '%s | ' % host
            cmd += '/opt/rocks/bin/rocks report script | '
            cmd += 'ssh %s bash > /dev/null 2>&1' % host

            p = Parallel(cmd)
            threads.append(p)
            p.start()

        #
        # collect the threads
        #
        for thread in threads:
            thread.join(timeout)

        threads = []
        for host in hosts:
            if max_threading > 0:
                while threading.activeCount() > max_threading:
                    #
                    # need to wait for some threads to
                    # complete before starting any new ones
                    #
                    time.sleep(0.001)

            cmd = 'ssh %s "/sbin/service xend restart" ' % host
            cmd += '> /dev/null 2>&1'

            p = Parallel(cmd)
            threads.append(p)
            p.start()

        #
        # collect the threads
        #
        for thread in threads:
            thread.join(timeout)
Пример #3
0
    def run(self, params, args):
        if len(args) == 0:
            self.abort("must supply at least one frontend name")

        vm = rocks.vm.VM(self.db)
        frontends = self.getHostnames(["frontend"])
        hosts = self.getHostnames(args)
        for host in hosts:
            if host not in frontends:
                self.abort("host %s is not a frontend" % host)
            if not vm.isVM(host):
                self.abort("host %s is not a virtual frontend" % host)

        for frontend in hosts:
            #
            # find all the client nodes related to this frontend.
            #
            # all client nodes of this VM frontend have
            # the same vlan ids as this frontend
            #
            rows = self.db.execute(
                """select net.vlanid, net.subnet
				from networks net, nodes n where n.name = '%s'
				and net.node = n.id and net.vlanid > 1"""
                % frontend
            )

            vlans = []
            for vlanid, subnet in self.db.fetchall():
                vlans.append((vlanid, subnet))

            if not vlans:
                self.abort("could not find VLAN Id " + "for frontend %s" % frontend)

            phys_nodes = []
            vm_nodes = []
            for vlanid, subnet in vlans:
                self.db.execute(
                    """select n.name from
					networks net, nodes n where
					net.vlanid = %s and net.node = n.id"""
                    % vlanid
                )

                for (node,) in self.db.fetchall():
                    if vm.isVM(node):
                        vm_nodes.append((node, vlanid, subnet))
                    else:
                        phys_nodes.append((node, vlanid, subnet))

                        #
                        # remove the VLAN configuration from the physical nodes
                        #
            pnodes = []
            for node, vlanid, subnet in phys_nodes:
                rows = self.db.execute(
                    """select net.device from
					nodes n, networks net where
					n.name = '%s' and n.id = net.node and
					net.vlanid = %s"""
                    % (node, vlanid)
                )

                if rows != 1:
                    self.abort("could not find VLAN " + "%s for node %s" % (vlanid, node))

                iface, = self.db.fetchone()

                self.command("remove.host.interface", [node, iface])

                #
                # remove the ifcfg file from the physical host
                #
                rows = self.db.execute(
                    """select net.device from
					nodes n, networks net where
					n.name = '%s' and n.id = net.node and
					net.subnet = %s and net.device not like
					'vlan%%' """
                    % (node, subnet)
                )

                if rows != 1:
                    self.abort("could not find VLAN " + "%s for node %s" % (vlanid, node))

                device, = self.db.fetchone()
                cmd = "rm -f /etc/sysconfig/network-scripts/"
                cmd += "ifcfg-%s.%s" % (device, vlanid)

                self.command("run.host", [node, cmd])

                pnodes.append(node)

                #
                # reconfigure and restart the network on the
                # physical hosts
                #
            try:
                self.command("sync.host.network", pnodes)
            except:
                pass

                #
                # remove all the VMs associated with the cluster
                #
            vnodes = []
            for node, vlanid, subnet in vm_nodes:
                vnodes.append(node)

            self.command("remove.host", vnodes)

        self.command("sync.config")
Пример #4
0
	def getmacs(self, dst_mac):
		#
		# return a list of all the MACs associated with this cluster
		#
		macs = []

		try:
			host = self.db.getHostname(dst_mac)
		except:
			host = None
		
		if not host:
			return macs

		vm = rocks.vm.VM(self.db)
		if vm.isVM(host):
			#
			# all the hosts associated with this host have
			# the same vlan id
			#
			rows = self.db.execute("""select vlanid from networks
				where mac = '%s' and vlanid > 0"""  % dst_mac)

			if rows == 0:
				#
				# it may be the case that the MAC is the MAC
				# for the VM frontend and it is associated with
				# the public connection. in this case, there is
				# no vlan id.
				#
				# let's see if we can find a vlan id for the
				# private network for this host
				#
				rows = self.db.execute("""select vlanid from
					networks where node = (select id from
					nodes where name = '%s') and subnet =
					(select id from subnets where name =
					'private') and vlanid is not NULL""" %
					host)

			if rows == 0:
				#
				# this VM doesn't have a VLAN assigned to it.
				# it may be controlled by a physical frontend,
				# so just get the name and MAC from the
				# database
				#
				rows = self.db.execute("""select n.name,
					net.mac from networks net, nodes n
					where net.node = n.id
					and net.mac = '%s' """ % dst_mac)
			elif rows > 0:
				vlanid, = self.db.fetchone()

				rows = self.db.execute("""select n.name,
					net.mac from networks net, nodes n
					where net.vlanid = %s and
					net.node = n.id""" % vlanid)

			if rows:
				for client, mac in self.db.fetchall():
					if vm.isVM(client):
						macs.append(mac)

		return macs
Пример #5
0
    def run(self, params, args):
        if len(args) == 0:
            self.abort('must supply at least one frontend name')

        vm = rocks.vm.VM(self.db)
        frontends = self.getHostnames(['frontend'])
        hosts = self.getHostnames(args)
        for host in hosts:
            if host not in frontends:
                self.abort('host %s is not a frontend' % host)
            if not vm.isVM(host):
                self.abort('host %s is not a virtual frontend' % host)

        for frontend in hosts:
            #
            # find all the client nodes related to this frontend.
            #
            # all client nodes of this VM frontend have
            # the same vlan ids as this frontend
            #
            rows = self.db.execute("""select net.vlanid, net.subnet
				from networks net, nodes n where n.name = '%s'
				and net.node = n.id and net.vlanid > 1""" % frontend)

            vlans = []
            for vlanid, subnet in self.db.fetchall():
                vlans.append((vlanid, subnet))

            if not vlans:
                self.abort('could not find VLAN Id ' +
                           'for frontend %s' % frontend)

            phys_nodes = []
            vm_nodes = []
            for vlanid, subnet in vlans:
                self.db.execute("""select n.name from
					networks net, nodes n where
					net.vlanid = %s and net.node = n.id""" % vlanid)

                for node, in self.db.fetchall():
                    if vm.isVM(node):
                        vm_nodes.append((node, vlanid, subnet))
                    else:
                        phys_nodes.append((node, vlanid, subnet))

            #
            # remove the VLAN configuration from the physical nodes
            #
            pnodes = []
            for node, vlanid, subnet in phys_nodes:
                rows = self.db.execute("""select net.device from
					nodes n, networks net where
					n.name = '%s' and n.id = net.node and
					net.vlanid = %s""" % (node, vlanid))

                if rows != 1:
                    self.abort('could not find VLAN ' + '%s for node %s' %
                               (vlanid, node))

                iface, = self.db.fetchone()

                self.command('remove.host.interface', [node, iface])

                #
                # remove the ifcfg file from the physical host
                #
                rows = self.db.execute("""select net.device from
					nodes n, networks net where
					n.name = '%s' and n.id = net.node and
					net.subnet = %s and net.device not like
					'vlan%%' """ % (node, subnet))

                if rows != 1:
                    self.abort('could not find VLAN ' + '%s for node %s' %
                               (vlanid, node))

                device, = self.db.fetchone()
                cmd = 'rm -f /etc/sysconfig/network-scripts/'
                cmd += 'ifcfg-%s.%s' % (device, vlanid)

                self.command('run.host', [node, cmd])

                pnodes.append(node)

            #
            # reconfigure and restart the network on the
            # physical hosts
            #
            try:
                self.command('sync.host.network', pnodes)
            except:
                pass

            #
            # remove all the VMs associated with the cluster
            #
            vnodes = []
            for node, vlanid, subnet in vm_nodes:
                vnodes.append(node)

            self.command('remove.host', vnodes)

        self.command('sync.config')
Пример #6
0
	def run(self, params, args):
		(showstatus, ) = self.fillParams( [ ('status', 'n') ])
		showstatus = self.str2bool(showstatus)

		frontends = self.getHostnames( [ 'frontend' ])

		if len(args) > 0:
			hosts = self.getHostnames(args)
			for host in hosts:
				if host not in frontends:
					self.abort('host %s is not a frontend'
						% host)
		else:
			hosts = frontends

		vm = rocks.vm.VM(self.db)
		self.beginOutput()

		for frontend in hosts:
			#
			# get the FQDN of the frontend
			#
			rows = self.db.execute("""select net.name from
				nodes n, networks net, subnets s where 
				s.name = 'public' and s.id = net.subnet
				and n.name = '%s' and n.id = net.node"""
				% (frontend))

			if rows == 1:
				fqdn, = self.db.fetchone()
			else:
				fqdn = frontend

			if vm.isVM(frontend):
				info = ('', 'VM')
				if showstatus:
					info += (self.getStatus(frontend),)
		
				self.addOutput(fqdn, info)

				#
				# all client nodes of this VM frontend have
				# the same vlan id as this frontend
				#
				rows = self.db.execute("""select
					net.vlanid from
					networks net, nodes n, subnets s where
					n.name = '%s' and net.node = n.id and
					s.name = 'private' and
					s.id = net.subnet""" % frontend)

				if rows > 0:
					vlanid, = self.db.fetchone()
				else:
					self.abort('could not find Vlan Id ' +
						'for frontend %s' % frontend)

				rows = self.db.execute("""select n.name from
					networks net, nodes n where
					net.vlanid = %s and net.node = n.id
					""" % vlanid)

				for client, in self.db.fetchall():
					if client != frontend and \
						vm.isVM(client):

						info = self.getClientInfo(
							client, showstatus)
		
						self.addOutput('', info)
			else:
				info = ('', 'physical')
				if showstatus:
					info += (None,)
		
				self.addOutput(fqdn, info)

				#
				# a physical frontend. go get all the physical
				# client nodes
				#
				clients = self.getHostnames()

				for client in clients:
					if client not in frontends and \
						not vm.isVM(client):
		
						info = (client, 'physical')
						if showstatus:
							info += (None,)

						self.addOutput('', info)

		header = [ 'frontend', 'client nodes', 'type' ]
		if showstatus:
			header.append('status')

		self.endOutput(header, trimOwner = 0)
Пример #7
0
    def getmacs(self, dst_mac):
        #
        # return a list of all the MACs associated with this cluster
        #
        macs = []

        try:
            host = self.db.getHostname(dst_mac)
        except:
            host = None

        if not host:
            return macs

        vm = rocks.vm.VM(self.db)
        if vm.isVM(host):
            #
            # all the hosts associated with this host have
            # the same vlan id
            #
            rows = self.db.execute("""select vlanid from networks
				where mac = '%s' and vlanid > 0""" % dst_mac)

            if rows == 0:
                #
                # it may be the case that the MAC is the MAC
                # for the VM frontend and it is associated with
                # the public connection. in this case, there is
                # no vlan id.
                #
                # let's see if we can find a vlan id for the
                # private network for this host
                #
                rows = self.db.execute("""select vlanid from
					networks where node = (select id from
					nodes where name = '%s') and subnet =
					(select id from subnets where name =
					'private') and vlanid is not NULL""" % host)

            if rows == 0:
                #
                # this VM doesn't have a VLAN assigned to it.
                # it may be controlled by a physical frontend,
                # so just get the name and MAC from the
                # database
                #
                rows = self.db.execute("""select n.name,
					net.mac from networks net, nodes n
					where net.node = n.id
					and net.mac = '%s' """ % dst_mac)
            elif rows > 0:
                vlanid, = self.db.fetchone()

                rows = self.db.execute("""select n.name,
					net.mac from networks net, nodes n
					where net.vlanid = %s and
					net.node = n.id""" % vlanid)

            if rows:
                for client, mac in self.db.fetchall():
                    if vm.isVM(client):
                        macs.append(mac)

        return macs