Ejemplo n.º 1
0
Archivo: main.py Proyecto: larsewi/core
def main():
    log.warning("You are using an outdated (deprecated) version of cf-remote")
    log.warning(
        "Please install a new version from: https://github.com/cfengine/cf-remote"
    )
    args = get_args()
    if args.log_level:
        log.set_level(args.log_level)
    validate_args(args)

    exit_code = run_command_with_args(args.command, args)
    assert (type(exit_code) is int)
    sys.exit(exit_code)
Ejemplo n.º 2
0
def run_command_with_args(command, args):
    if command == "info":
        return commands.info(args.hosts, None)
    elif command == "install":
        return commands.install(
            args.hub,
            args.clients,
            package=args.package,
            bootstrap=args.bootstrap,
            hub_package=args.hub_package,
            client_package=args.client_package,
            version=args.version,
            demo=args.demo,
            call_collect=args.call_collect,
            edition=args.edition,
            remote_download=args.remote_download)
    elif command == "uninstall":
        all_hosts = ((args.hosts or []) + (args.hub or []) + (args.clients or []))
        return commands.uninstall(all_hosts)
    elif command == "packages":
        log.warning("packages command is deprecated, please use the new command: download")
        return commands.download(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "list":
        return commands.list_command(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "download":
        return commands.download(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "run":
        return commands.run(hosts=args.hosts, raw=args.raw, command=args.remote_command)
    elif command == "sudo":
        return commands.sudo(hosts=args.hosts, raw=args.raw, command=args.remote_command)
    elif command == "scp":
        return commands.scp(hosts=args.hosts, files=args.args)
    elif command == "spawn":
        if args.list_platforms:
            return commands.list_platforms()
        if args.init_config:
            return commands.init_cloud_config()
        if args.name and "," in args.name:
            user_error("Group --name may not contain commas")
        # else
        if args.role.endswith("s"):
            # role should be singular
            args.role = args.role[:-1]
        return commands.spawn(args.platform, args.count, args.role, args.name)
    elif command == "destroy":
        group_name = args.name if args.name else None
        return commands.destroy(group_name)
    elif command == "deploy":
        return commands.deploy(args.hub, args.directory)
    else:
        user_error("Unknown command: '{}'".format(command))
Ejemplo n.º 3
0
def uninstall_host(host, *, connection=None):
    data = get_info(host, connection=connection)
    print_info(data)

    if not data["agent_version"]:
        log.warning(
            "CFEngine does not seem to be installed on '{}' - attempting uninstall anyway"
            .format(host))

    uninstall_cfengine(host, data, connection=connection)
    data = get_info(host, connection=connection)

    if (not data) or data["agent_version"]:
        print("Failed to uninstall CFEngine on '{}'".format(host))
        return None

    print_info(data)

    print("Uninstallation successful on '{}'".format(host))
    return data
Ejemplo n.º 4
0
def run_command_with_args(command, args):
    if command == "info":
        return commands.info(args.hosts, None)
    elif command == "install":
        if args.trust_keys:
            trust_keys = args.trust_keys.split(",")
        else:
            trust_keys = None

        return commands.install(
            args.hub,
            args.clients,
            package=args.package,
            bootstrap=args.bootstrap,
            hub_package=args.hub_package,
            client_package=args.client_package,
            version=args.version,
            demo=args.demo,
            call_collect=args.call_collect,
            edition=args.edition,
            remote_download=args.remote_download,
            trust_keys=trust_keys)
    elif command == "uninstall":
        all_hosts = ((args.hosts or []) + (args.hub or []) + (args.clients or []))
        return commands.uninstall(all_hosts)
    elif command == "packages":
        log.warning("packages command is deprecated, please use the new command: download")
        return commands.download(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "list":
        return commands.list_command(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "download":
        return commands.download(tags=args.tags, version=args.version, edition=args.edition)
    elif command == "run":
        return commands.run(hosts=args.hosts, raw=args.raw, command=args.remote_command)
    elif command == "sudo":
        return commands.sudo(hosts=args.hosts, raw=args.raw, command=args.remote_command)
    elif command == "scp":
        return commands.scp(hosts=args.hosts, files=args.args)
    elif command == "spawn":
        if args.list_platforms:
            return commands.list_platforms()
        if args.init_config:
            return commands.init_cloud_config()
        if args.name and "," in args.name:
            user_error("Group --name may not contain commas")
        if args.aws and args.gcp:
            user_error("--aws and --gcp cannot be used at the same time")
        if args.role.endswith("s"):
            # role should be singular
            args.role = args.role[:-1]
        if args.gcp:
            provider = Providers.GCP
        else:
            # AWS is currently also the default
            provider = Providers.AWS
            if args.network:
                user_error("--network not supported for AWS")
            if args.no_public_ip:
                user_error("--no-public-ip not supported for AWS")
        if args.network and (args.network.count("/") != 1):
            user_error("Invalid network specified, needs to be in the network/subnet format")

        return commands.spawn(args.platform, args.count, args.role, args.name,
                              provider=provider, size=args.size, network=args.network,
                              public_ip=not args.no_public_ip, extend_group=args.append)
    elif command == "destroy":
        group_name = args.name if args.name else None
        return commands.destroy(group_name)
    elif command == "deploy":
        return commands.deploy(args.hub, args.directory)
    else:
        user_error("Unknown command: '{}'".format(command))