def install_def_json(host, *, connection=None, call_collect=False): print("Transferring def.json to hub: '{}'".format(host)) data = json.dumps(def_json(call_collect), indent=2) path = os.path.join(cf_remote_dir("json"), "def.json") save_file(path, data) scp(path, host, connection=connection) ssh_sudo(connection, "cp def.json /var/cfengine/masterfiles/def.json")
def install_def_json(host): print("Transferring def.json to hub: '{}'".format(host)) data = json.dumps(def_json(), indent=2) path = os.path.join(cf_remote_dir("json"), "def.json") save_file(path, data) remote.scp(path, host) with remote.connect(host) as connection: connection.sudo("cp def.json /var/cfengine/masterfiles/def.json")
def install(hubs, clients, *, bootstrap=None, package=None, hub_package=None, client_package=None, version=None, demo=False, call_collect=False, edition=None): assert hubs or clients assert not (hubs and clients and package) # These assertions are checked in main.py if not hub_package: hub_package = package if not client_package: client_package = package if bootstrap: if type(bootstrap) is str: bootstrap = [bootstrap] save_file(os.path.join(cf_remote_dir(), "policy_server.dat"), "\n".join(bootstrap + [""])) errors = 0 if hubs: if type(hubs) is str: hubs = [hubs] for index, hub in enumerate(hubs): log.debug("Installing {} hub package on '{}'".format(edition, hub)) errors += install_host( hub, hub=True, package=hub_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo, call_collect=call_collect, edition=edition) for index, host in enumerate(clients or []): log.debug("Installing {} client package on '{}'".format(edition, host)) errors += install_host( host, hub=False, package=client_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo, edition=edition) if demo and hubs: for hub in hubs: print( "Your demo hub is ready: https://{}/ (Username: admin, Password: password)" .format(strip_user(hub))) return errors
def install( hubs, clients, *, bootstrap=None, package=None, hub_package=None, client_package=None, version=None, demo=False, call_collect=False): assert hubs or clients assert not (hubs and clients and package) # These assertions are checked in main.py if not hub_package: hub_package = package if not client_package: client_package = package if bootstrap: if type(bootstrap) is str: bootstrap = [bootstrap] save_file(os.path.join(cf_remote_dir(), "policy_server.dat"), "\n".join(bootstrap + [""])) if hubs: if type(hubs) is str: hubs = [hubs] for index, hub in enumerate(hubs): log.debug("Installing hub package on '{}'".format(hub)) install_host( hub, hub=True, package=hub_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo, call_collect=call_collect) for index, host in enumerate(clients or []): log.debug("Installing client package on '{}'".format(host)) install_host( host, hub=False, package=client_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo) if demo and hubs: for hub in hubs: print( "Your demo hub is ready: https://{}/ (Username: admin, Password: password)". format(strip_user(hub)))
def install(hub, clients, *, bootstrap=None, package=None, hub_package=None, client_package=None, version=None, demo=False): assert hub or clients assert not (hub and clients and package) # These assertions are checked in main.py if not hub_package: hub_package = package if not client_package: client_package = package if bootstrap: save_file(os.path.join(cf_remote_dir(), "policy_server.dat"), bootstrap + "\n") if hub: log.debug("Installing hub package on '{}'".format(hub)) install_host(hub, hub=True, package=hub_package, bootstrap=bootstrap, version=version, demo=demo) for host in (clients or []): log.debug("Installing client package on '{}'".format(host)) install_host(host, hub=False, package=client_package, bootstrap=bootstrap, version=version, demo=demo) if demo and hub: print( "Your demo hub is ready: https://{}/ (Username: admin, Password: password)" .format(hub))
def install(hubs, clients, *, bootstrap=None, package=None, hub_package=None, client_package=None, version=None, demo=False, call_collect=False, edition=None, remote_download=False, trust_keys=None): assert hubs or clients assert not (hubs and clients and package) assert (trust_keys is None) or hasattr(trust_keys, "__iter__") # These assertions are checked/ensured in main.py # If there are URLs in any of the package strings and remote_download is FALSE, download and replace with path: packages = (package, hub_package, client_package) if remote_download: package, hub_package, client_package = _verify_package_urls(packages) else: package, hub_package, client_package = _download_urls(packages) # If any of these are folders, transform them to lists of the files inside those folders: package = _maybe_packages_in_folder(package) hub_package = _maybe_packages_in_folder(hub_package) client_package = _maybe_packages_in_folder(client_package) # If --hub-package or --client-pacakge are not specified, use --package argument: if not hub_package: hub_package = package if not client_package: client_package = package if bootstrap: if type(bootstrap) is str: bootstrap = [bootstrap] save_file(os.path.join(cf_remote_dir(), "policy_server.dat"), "\n".join(bootstrap + [""])) hub_jobs = [] if hubs: show_host_info = (len(hubs) == 1) if type(hubs) is str: hubs = [hubs] for index, hub in enumerate(hubs): log.debug("Installing {} hub package on '{}'".format(edition, hub)) hub_jobs.append( HostInstaller( hub, hub=True, packages=hub_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo, call_collect=call_collect, edition=edition, show_info=show_host_info, remote_download=remote_download, trust_keys=trust_keys)) errors = 0 if hub_jobs: with Pool(len(hub_jobs)) as hubs_install_pool: hubs_install_pool.map(lambda job: job.run(), hub_jobs) errors = sum(job.errors for job in hub_jobs) if errors > 0: s = "s" if errors > 1 else "" log.error( f"{errors} error{s} encountered while installing hub packages, aborting..." ) return errors client_jobs = [] show_host_info = (clients and (len(clients) == 1)) for index, host in enumerate(clients or []): log.debug("Installing {} client package on '{}'".format(edition, host)) client_jobs.append( HostInstaller( host, hub=False, packages=client_package, bootstrap=bootstrap[index % len(bootstrap)] if bootstrap else None, version=version, demo=demo, edition=edition, show_info=show_host_info, remote_download=remote_download, trust_keys=trust_keys)) if client_jobs: with Pool(len(client_jobs)) as clients_install_pool: clients_install_pool.map(lambda job: job.run(), client_jobs) errors += sum(job.errors for job in client_jobs) if demo and hubs: for hub in hubs: print( "Your demo hub is ready: https://{}/ (Username: admin, Password: password)" .format(strip_user(hub))) if errors > 0: s = "s" if errors > 1 else "" log.error( f"{errors} error{s} encountered while installing client packages") return errors