Пример #1
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)
        if not hosts:
            raise ArgRequired(self, 'host')

        if len(hosts) > 1:
            raise ArgUnique(self, 'host')

        (key_id, ) = self.fillParams([('id', None, True)])

        host = hosts[0]

        if self.db.count(
                """
			(ID) from public_keys
			where id=%s and node=(
				select id from nodes where name=%s
			)""", (key_id, host)) == 0:
            raise CommandError(
                self,
                f"public key with id {key_id} doesn't exist for host {host}")

        self.db.execute('delete from public_keys where id=%s', (key_id, ))
Пример #2
0
	def run(self, params, args):
		if not len(args):
			raise ArgRequired(self, 'host')

		hosts = self.getHostnames(args)
		if not hosts:
			raise ArgRequired(self, 'host')

		(partition, device, uuid) = self.fillParams([
			('partition', None),
			('device', None),
			('uuid', None)
		])

		for host in hosts:
			sql = """
				delete from partitions
				where node=(select id from nodes where name=%s)
			"""
			values = [host]

			if uuid:
				sql += ' and uuid=%s'
				values.append(uuid)

			if partition:
				sql += ' and mountpoint=%s'
				values.append(partition)

			if device:
				sql += ' and device=%s'
				values.append(device)

			self.db.execute(sql, values)
Пример #3
0
	def run(self, params, args):
		if len(args) == 0:
			raise ArgRequired(self, 'host')

		hosts = self.getHostnames(args)

		if not hosts:
			raise ArgRequired(self, 'host')

		if not len(hosts) == 1:
			raise ArgUnique(self, 'host')

		alias, interface, = self.fillParams([
			('alias', None),
			('interface', None)
		])

		query = """
			DELETE aliases
			FROM aliases
			LEFT JOIN networks ON aliases.network = networks.id
			LEFT JOIN nodes ON networks.node = nodes.id
			WHERE nodes.name = %s
		"""
		values = [hosts[0]]

		if alias:
			query += ' AND aliases.name = %s'
			values.append(alias)

		if interface:
			query += ' AND networks.device = %s'
			values.append(interface)

		self.db.execute(query, values)
Пример #4
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)
        if not hosts:
            raise ArgRequired(self, 'host')

        (
            address,
            syncnow,
        ) = self.fillParams([('address', None, True), ('syncnow', None)])

        syncnow = self.str2bool(syncnow)
        me = self.db.getHostname()

        for host in hosts:
            result = self.db.execute(
                """
				delete from node_routes
				where node=(select id from nodes where name=%s) and network=%s
			""", (host, address))

            # Remove the route from the frontend, if needed
            if syncnow and result and host == me:
                self._exec(f'route del -host {address}', shlexsplit=True)
Пример #5
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)
        if not hosts:
            raise ArgRequired(self, 'host')

        (group, ) = self.fillParams([('group', None, True)])

        membership = {
            row['host']: row['groups']
            for row in self.call('list.host.group')
        }

        for host in hosts:
            if group not in membership[host]:
                raise CommandError(self,
                                   '%s is not a member of %s' % (host, group))

        for host in hosts:
            self.db.execute(
                """
				delete from memberships
				where nodeid=(select id from nodes where name=%s)
				and	groupid=(select id from groups where name=%s)
			""", (host, group))
Пример #6
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)

        if not hosts:
            raise ArgRequired(self, 'host')

        if not len(hosts) == 1:
            raise ArgUnique(self, 'host')

        (
            alias,
            interface,
        ) = self.fillParams([('alias', None), ('interface', None)])

        for host in self.getHostnames(args):
            if not alias and not interface:
                self.db.execute(
                    """
					delete from aliases
					where network IN (
						select id from networks where node=(
							select id from nodes where name=%s
						)
					)
				""", (host, ))
            elif not alias:
                self.db.execute(
                    """
					delete from aliases
					where network IN (
						select id from networks where node=(
							select id from nodes where name=%s
						) and device=%s
					)
				""", (host, interface))
            elif not interface:
                self.db.execute(
                    """
					delete from aliases
					where network IN (
						select id from networks where node=(
							select id from nodes where name=%s
						)
					) and name=%s
				""", (host, alias))
            else:
                self.db.execute(
                    """
					delete from aliases
					where network=(
						select id from networks where node=(
							select id from nodes where name=%s
						) and device=%s
					) and name=%s
				""", (host, interface, alias))
Пример #7
0
    def _get_hosts(self, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)

        if not hosts:
            raise ArgRequired(self, 'host')

        return hosts
Пример #8
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        hosts = self.getHostnames(args)
        if not hosts:
            raise ArgRequired(self, 'host')

        (interface, mac, all_interfaces) = self.fillParams([('interface',
                                                             None),
                                                            ('mac', None),
                                                            ('all', 'false')])

        all_interfaces = self.str2bool(all_interfaces)
        if not all_interfaces and not interface and not mac:
            raise ParamRequired(self, ('interface', 'mac'))

        networks = ()
        for host in hosts:
            if all_interfaces:
                networks = flatten(
                    self.db.select(
                        """
					id from networks where
					node=(select id from nodes where name=%s)
				""", (host, )))
            elif interface:
                networks = flatten(
                    self.db.select(
                        """
					id from networks where
					node=(select id from nodes where name=%s) and device=%s
				""", (host, interface)))

                if not networks:
                    raise CommandError(
                        self,
                        'no interface "%s" exists on %s' % (interface, host))
            else:
                networks = flatten(
                    self.db.select(
                        """
					id from networks where
					node=(select id from nodes where name=%s) and mac=%s
				""", (host, mac)))

                if not networks:
                    raise CommandError(
                        self, 'no mac address "%s" exists on %s' % (mac, host))

            self.runPlugins(networks)
Пример #9
0
    def run(self, params, args):

        (service, network, outnetwork, chain, action, protocol, flags, comment,
         table, rulename) = self.doParams()

        if len(args) == 0:
            raise ArgRequired(self, 'appliance')

        apps = self.getApplianceNames(args)

        for app in apps:
            sql = """appliance = (select id from appliances where
				name = '%s') and""" % app

            self.checkRule('appliance_firewall', sql, service, network,
                           outnetwork, chain, action, protocol, flags, comment,
                           table, rulename)

        #
        # all the rules are valid, now let's add them
        #
        for app in apps:
            sql = """(select id from appliances where
				name='%s'), """ % app

            self.insertRule('appliance_firewall', 'appliance, ', sql, service,
                            network, outnetwork, chain, action, protocol,
                            flags, comment, table, rulename)
Пример #10
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'appliance')

        apps = self.getApplianceNames(args)

        (service, network, outnetwork, chain, action, protocol, flags, comment,
         table, rulename) = self.doParams()

        # Make sure we have a new rule
        for app in apps:
            if self.db.count(
                    """(*) from appliance_firewall where
				appliance = (select id from appliances where name = %s) and
				service = %s and action = %s and chain = %s and
				if (%s is NULL, insubnet is NULL, insubnet = %s) and
				if (%s is NULL, outsubnet is NULL, outsubnet = %s) and
				if (%s is NULL, protocol is NULL, protocol = %s) and
				if (%s is NULL, flags is NULL, flags = %s)""",
                (app, service, action, chain, network, network, outnetwork,
                 outnetwork, protocol, protocol, flags, flags)) > 0:
                raise CommandError(self, 'firewall rule already exists')

        # Now let's add them
        for app in apps:
            self.db.execute(
                """insert into appliance_firewall
				(appliance, insubnet, outsubnet, service, protocol,
				action, chain, flags, comment, tabletype, name)
				values ((select id from appliances where name=%s),
				%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
                (app, network, outnetwork, service, protocol, action, chain,
                 flags, comment, table, rulename))
Пример #11
0
    def run(self, params, args):
        self.beginOutput()

        (arch, OS) = self.fillParams([('arch', '%'), ('os', '%')])

        if len(args) < 1:
            raise ArgRequired(self, 'pallet')

        for (roll, version, release) in self.getRollNames(args, params):
            rows = self.db.execute("""
				select os, arch from rolls where
				name = '%s' and version = '%s' and
				arch like '%s' and os like '%s'
				""" % (roll, version, arch, OS))

            if rows == 0:  # empty table is OK
                continue

            # Remove each arch's instance of this pallet version
            for (
                    thisos,
                    thisarch,
            ) in self.db.fetchall():
                self.clean_pallet(roll, version, release, thisos, thisarch)

        self.endOutput(padChar='')
Пример #12
0
	def run(self, params, args):
		if len(args) == 0:
			raise ArgRequired(self, 'appliance')

		(rulename, ) = self.fillParams([ ('rulename', None, True) ])

		for appliance in self.getApplianceNames(args):
			# Make sure our rule exists
			if self.db.count("""
				(*) from appliance_firewall
				where name=%s and appliance=(
					select id from appliances where name=%s
				)""", (rulename, appliance)
			) == 0:
				raise CommandError(
					self,
					f'firewall rule {rulename} does not '
					f'exist for appliance {appliance}'
				)

			# It exists, so delete it
			self.db.execute("""
				delete from appliance_firewall
				where name=%s and appliance=(
					select id from appliances where name=%s
				)
			""", (rulename, appliance))
Пример #13
0
    def run(self, params, args):
        if not len(args):
            raise ArgRequired(self, 'host')

        cmd, debug = self.fillParams([('command', None, True),
                                      ('debug', False)])

        if cmd == 'status':
            #
            # used by "stack list host power" -- this is an easy way in which to
            # share code between the two commands
            #
            # set 'debug' to True in order to get output from the status command
            #
            debug = True
        elif cmd not in ['on', 'off', 'reset']:
            raise ParamError(self, 'command', 'must be "on", "off" or "reset"')

        self.debug = self.str2bool(debug)

        for host in self.getHostnames(args):
            for o in self.call('list.host.interface', [host]):
                if o['interface'] == 'ipmi':
                    self.doPower(host, o['ip'], cmd)
                    break
Пример #14
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'appliance')

        appliances = self.getApplianceNames(args)

        #
        # don't remove the default appliance
        #
        if 'backend' in appliances:
            raise CommandError(self, 'cannot remove default appliance')

        #
        # check if the appliance is associated with any hosts
        #
        for appliance in appliances:
            for row in self.call('list.host'):
                if row['appliance'] == appliance:
                    raise CommandError(
                        self,
                        'cannot remove appliance "%s"\nbecause host "%s" is assigned to this appliance'
                        % (appliance, row['host']))

        #
        # good to go
        #
        for appliance in appliances:
            self.runPlugins(appliance)
Пример #15
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'host')

        (rulename, ) = self.fillParams([('rulename', None, True)])

        for host in self.getHostnames(args):
            # Make sure our rule exists
            if self.db.count(
                    """
				(*) from node_firewall
				where name=%s and node=(
					select id from nodes where name=%s
				)""", (rulename, host)) == 0:
                raise CommandError(
                    self, f'firewall rule {rulename} does not '
                    f'exist for host {host}')

            # It exists, so delete it
            self.db.execute(
                """
				delete from node_firewall
				where name=%s and node=(
					select id from nodes where name=%s
				)
			""", (rulename, host))
Пример #16
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'cart')

        box, = self.fillParams([('box', 'default')])

        rows = self.db.execute("""
			select * from boxes where name='%s' """ % box)

        if not rows:
            raise CommandError(self, 'unknown box "%s"' % box)

        for cart in self.getCartNames(args, params):
            self.db.execute("""
				delete from cart_stacks where
				box = (select id from boxes where name='%s')
				and
				cart = (select id from carts where name='%s')
				""" % (box, cart))

        # Regenerate stacki.repo
        os.system("""
			/opt/stack/bin/stack report host repo localhost | 
			/opt/stack/bin/stack report script | 
			/bin/sh
			""")
Пример #17
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'pallet')

        (arch, box) = self.fillParams([('arch', self.arch),
                                       ('box', 'default')])

        rows = self.db.execute("""
			select * from boxes where name = '%s'
			""" % box)
        if not rows:
            raise CommandError(self, 'unknown box "%s"' % box)

        for (roll, version, release) in self.getRollNames(args, params):
            if release:
                rel = "rel='%s'" % release
            else:
                rel = 'rel=""'

            self.db.execute("""
				delete from stacks where
				box = (select id from boxes where name='%s')
				and
				roll = (select id from rolls where name='%s'
				and version='%s' and %s and arch='%s') """ %
                            (box, roll, version, rel, arch))

        # Regenerate stacki.repo
        os.system("""
			/opt/stack/bin/stack report host repo localhost | 
			/opt/stack/bin/stack report script | 
			/bin/sh
			""")
Пример #18
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'pallet')

        (arch, box) = self.fillParams([('arch', self.arch),
                                       ('box', 'default')])

        # Make sure our box exists
        rows = self.db.select('ID from boxes where name=%s', (box, ))
        if len(rows) == 0:
            raise CommandError(self, 'unknown box "%s"' % box)

        # Remember the box ID to simply queries down below
        box_id = rows[0][0]

        for (roll, version, release) in self.getRollNames(args, params):
            self.db.execute(
                """
				delete from stacks where
				box=%s and roll=(
					select id from rolls where name=%s
					and version=%s and rel=%s and arch=%s
				)""", (box_id, roll, version, release, arch))

        # Regenerate stacki.repo
        self._exec("""
			/opt/stack/bin/stack report host repo localhost |
			/opt/stack/bin/stack report script |
			/bin/sh
			""",
                   shell=True)
Пример #19
0
	def run(self, params, args):

		if len(args) < 1:
			raise ArgRequired(self, 'os')
			
		for os in self.getOSNames(args):
			self.runPlugins(os)
Пример #20
0
	def getBootActionTypeOS(self, params, args):
		if not len(args):
			raise ArgRequired(self, 'action')
		if len(args) != 1:
			raise ArgUnique(self, 'action')

		b_action = args[0]

		(b_type, b_os) = self.fillParams([
			('type', None, True),
			('os', '')
		])

		if b_type not in [ 'os', 'install' ]:
			raise ParamValue(self, 'type', '"os" or "install"')

		# If bootaction type is not os, then get the default
		# os so code doesn't break.
		if not b_os and b_type != 'os':
			b_os = self.os

		if b_os:
			b_os = self.getOSNames([b_os])[0]

		return (b_action, b_type, b_os)
Пример #21
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'pallet')

        (arch, box) = self.fillParams([('arch', self.arch),
                                       ('box', 'default')])

        # We need to write the default arch back to the params list
        params['arch'] = arch

        # Make sure our box exists
        rows = self.db.select('ID from boxes where name=%s', (box, ))
        if len(rows) == 0:
            raise CommandError(self, 'unknown box "%s"' % box)

        # Remember the box ID to simply queries down below
        box_id = rows[0][0]

        for pallet in self.getPallets(args, params):
            self.db.execute('delete from stacks where box=%s and roll=%s',
                            (box_id, pallet.id))

        # Regenerate stacki.repo
        self._exec("""
			/opt/stack/bin/stack report host repo localhost |
			/opt/stack/bin/stack report script |
			/bin/sh
			""",
                   shell=True)
Пример #22
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'appliance')

        self.command('remove.storage.controller',
                     self._argv + ['scope=appliance'])
        return self.rc
Пример #23
0
    def run(self, params, args):

        if len(args) < 1:
            raise ArgRequired(self, 'os')

        for os in self.getOSNames(args):
            self.db.execute('delete from oses where name=%s', (os, ))
Пример #24
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'os')

        oses = self.getOSNames(args)

        (service, network, outnetwork, chain, action, protocol, flags, comment,
         table, rulename) = self.doParams()

        # Make sure we have a new rule
        for os in oses:
            if self.db.count(
                    """(*) from os_firewall where os = %s and
				service = %s and action = %s and chain = %s and
				if (%s is NULL, insubnet is NULL, insubnet = %s) and
				if (%s is NULL, outsubnet is NULL, outsubnet = %s) and
				if (%s is NULL, protocol is NULL, protocol = %s) and
				if (%s is NULL, flags is NULL, flags = %s)""",
                (os, service, action, chain, network, network, outnetwork,
                 outnetwork, protocol, protocol, flags, flags)) > 0:
                raise CommandError(self, 'firewall rule already exists')

        # Now let's add them
        for os in oses:
            self.db.execute(
                """insert into os_firewall
				(os, insubnet, outsubnet, service, protocol,
				action, chain, flags, comment, tabletype, name)
				values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
                (os, network, outnetwork, service, protocol, action, chain,
                 flags, comment, table, rulename))
Пример #25
0
    def run(self, params, args):
        if len(args) == 0:
            raise ArgRequired(self, 'environment')

        self.command('add.storage.controller',
                     self._argv + ['scope=environment'])
        return self.rc
Пример #26
0
	def run(self, params, args):

		(action, ) = self.fillParams([
			('action', None, True)
			])
		
		if not len(args):
			raise ArgRequired(self, 'host')

		if action.lower() == 'none':
			osaction = 'NULL'
		else:
			rows = self.db.execute(
				"""
				select ba.bootname from 
				bootactions ba, bootnames bn 
				where bn.name='%s' 
				and ba.bootname=bn.id
				and bn.type = 'os';
				""" % (action))

			if rows != 1:
				raise CommandError(self, 'invalid action parameter')
			# OSaction is now an ID, not a name so fetch it.
			osaction, = self.db.fetchone()

		for host in self.getHostnames(args):
			self.db.execute("""
				update nodes set osaction=%s
				where name='%s'
				""" % (osaction, host))
Пример #27
0
    def run(self, params, args):
        if not len(args):
            raise ArgRequired(self, 'network')

        # use the default argument handling but protect the user
        # from ever deleting networks (subnets table) that are
        # in use.  More general than just protecting the 'public'
        # and 'private' networks.

        networks = self.getNetworkNames(args)

        for network in networks:
            rows = self.db.execute("""select * from 
				networks net, subnets sub where
				net.subnet=sub.id and 
				sub.name='%s'""" % network)

            if rows > 0:
                raise CommandError(
                    self, 'cannot remove ' + '"%s" ' % (network) +
                    'network. There are nodes still ' + 'associated with it.')

        for network in networks:
            self.db.execute("""delete from subnets where 
				name='%s'""" % network)
Пример #28
0
    def run(self, params, args):
        if len(args) < 1:
            raise ArgRequired(self, 'cart')

        box, = self.fillParams([('box', 'default')])

        # Make sure our box exists
        rows = self.db.select('ID from boxes where name=%s', (box, ))
        if len(rows) == 0:
            raise CommandError(self, 'unknown box "%s"' % box)

        # Remember the box ID to simply queries down below
        box_id = rows[0][0]

        for cart in self.getCartNames(args):
            self.db.execute(
                """
				delete from cart_stacks where
				box=%s and cart=(select id from carts where name=%s)
				""", (box_id, cart))

        # Regenerate stacki.repo
        os.system("""
			/opt/stack/bin/stack report host repo localhost |
			/opt/stack/bin/stack report script |
			/bin/sh
			""")
Пример #29
0
    def run(self, params, args):

        (action, ) = self.fillParams([('action', None, True)])

        if not len(args):
            raise ArgRequired(self, 'host')

        if action.lower() == 'none':
            installaction = 'NULL'
        else:
            rows = self.db.execute("""
				select ba.bootname from 
				bootactions ba, bootnames bn 
				where bn.name='%s' 
				and ba.bootname=bn.id
				and bn.type = 'install';
				""" % (action))
            if rows < 1:
                nrows = self.db.execute("""
				select name from bootnames 
				where type="install";
				""")
                actions = self.db.fetchall()
                msg = '\n\nThese are the available actions: \n'
                msg += '\n'.join([a[0] for a in actions])
                raise CommandError(self, 'invalid action parameter' + msg)

            installaction, = self.db.fetchone()

        for host in self.getHostnames(args):
            self.db.execute("""
				update nodes set installaction=%s
				where name='%s'
				""" % (installaction, host))
Пример #30
0
    def run(self, params, args):

        if not len(args):
            raise ArgRequired(self, 'host')

        (partition, device, uuid) = self.fillParams([('partition', None),
                                                     ('device', None),
                                                     ('uuid', None)])

        for host in self.getHostnames(args):
            conditions = []
            sql_cmd = """delete from partitions where
				node=(select id from nodes
				where name='%s')""" % host
            if uuid:
                conditions.append("uuid='%s'" % uuid)
            if partition:
                conditions.append("mountpoint='%s'" % partition)
            if device:
                conditions.append("device='%s'" % device)
            c = ' and '.join(conditions)
            if c:
                sql_cmd = "%s and %s" % (sql_cmd, c)

            self.db.execute(sql_cmd)