Exemplo n.º 1
0
def cloud_clean(
        args=sys.argv[1:],  # pylint: disable=W0102
        config=None):
    """
    Entrypoint for the cloud-clean CLI interface

    :param args: Command line arguments passed from user
    :param config: The config object to be used
    :return: None
    """
    # Construct or configure cloud cleaner config
    if config is None:
        config = CloudCleanerConfig(args=args)
    else:
        config.set_args(args)
    # Register all the resource types and options with the configurator
    for resource in ALL_RESOURCES.values():
        resource.register(config)
    config.parse_args()
    # Call the process method for the target resource type
    print("Options parsed, fetching resources")
    if config.get_arg("force"):
        ALL_RESOURCES[config.get_resource()].prep_deletion()
        ALL_RESOURCES[config.get_resource()].process()
        print("Resources fetched, cleaning")
        ALL_RESOURCES[config.get_resource()].clean()
    else:
        print("No changes made, force option not enabled")
    ALL_RESOURCES[config.get_resource()].process()
    if config.get_arg("email"):
        ALL_RESOURCES[config.get_resource()].send_emails()
Exemplo n.º 2
0
 def test_subcommand_incorrect(self):
     parser = ArgumentParser()
     config = CloudCleanerConfig(parser=parser, args=["notfound"])
     config.set_args(["notfound"])
     config.add_subparser("found")
     # ArgumentError raises SystemExit internally, apparently
     with self.assertRaises(SystemExit):
         config.parse_args()
Exemplo n.º 3
0
 def test_set_args(self):
     parser = ArgumentParser()
     config = CloudCleanerConfig(parser=parser, args=[])
     config.add_subparser("item")
     config.set_args(["--os-auth-url", "http://no.com", "item"])
     config.parse_args()
     self.assertEqual("item", config.get_resource())
     config.warning("Dummy warning")
     log = getLogger("cloud_cleaner")
     self.assertEqual(log.getEffectiveLevel(), WARNING)
     self.assertIsNone(config.get_arg("no_arg"))