Exemplo n.º 1
0
def gather_facts(host, inventory=None, user=None):
    if inventory is None:
        inventory = get_inventory()

    # Gather facts
    try:

        # ... temporary playbook file
        playbook_file = tempfile.NamedTemporaryFile()
        playbook_file.write(SETUP_PLAYBOOK.format(host=host))
        playbook_file.seek(0)

        # ... run setup module
        stats = ansible.callbacks.AggregateStats()
        playbook = PlayBook(
            playbook=playbook_file.name,
            inventory=inventory,
            callbacks=Callbacks(),
            runner_callbacks=Callbacks(),
            remote_user=user or C.DEFAULT_REMOTE_USER,
            stats=stats,
        )
        results = playbook.run()

        # ... notify the user of failures
        for host, result in results.iteritems():
            if result.get('unreachable') or result.get('failures'):
                yellow('Unable to gather facts for host "{}"'.format(host))

    finally:
        playbook_file.close()

    return playbook.SETUP_CACHE
Exemplo n.º 2
0
def main():
    path_to_stack = sys.argv[1]
    # path_to_nginx_conf = f"{path_to_stack}/volumes/nginx/conf"
    path_to_nginx_conf = path_to_stack + "/volumes/nginx/conf"
    inventory = get_inventory()

    service_hosts = inventory["stroom_services_stack"]["hosts"]
    # write_upstream_file(service_hosts, f"{path_to_nginx_conf}/upstreams.auth.service.conf.template", "8099")
    write_upstream_file(
        service_hosts,
        path_to_nginx_conf + "/upstreams.auth.service.conf.template", "8099")
    # write_upstream_file(service_hosts, f"{path_to_nginx_conf}/upstreams.auth.ui.conf.template", "9443")
    write_upstream_file(
        service_hosts, path_to_nginx_conf + "/upstreams.auth.ui.conf.template",
        "9443")

    if "stroom_and_proxy" in inventory.keys():
        stroom_and_proxy_hosts = inventory["stroom_and_proxy"]["hosts"]
    else:
        stroom_and_proxy_hosts = inventory["stroom_and_proxy_stack"]["hosts"]

    # write_upstream_file(stroom_and_proxy_hosts, f"{path_to_nginx_conf}/upstreams.proxy.conf.template", "8090")
    # write_upstream_file(stroom_and_proxy_hosts, f"{path_to_nginx_conf}/upstreams.stroom.ui.conf.template", "8080")
    # write_upstream_file(stroom_and_proxy_hosts, f"{path_to_nginx_conf}/upstreams.stroom.processing.conf.template", "8080")
    write_upstream_file(stroom_and_proxy_hosts,
                        path_to_nginx_conf + "/upstreams.proxy.conf.template",
                        "8090")
    write_upstream_file(
        stroom_and_proxy_hosts,
        path_to_nginx_conf + "/upstreams.stroom.ui.conf.template", "8080")
    write_upstream_file(
        stroom_and_proxy_hosts,
        path_to_nginx_conf + "/upstreams.stroom.processing.conf.template",
        "8080")
Exemplo n.º 3
0
def gather_facts(host, inventory=None):
    if inventory is None:
        inventory = get_inventory()

    # Gather facts
    try:

        # ... temporary playbook file
        playbook_file = tempfile.NamedTemporaryFile()
        playbook_file.write(SETUP_PLAYBOOK.format(host=host))
        playbook_file.seek(0)

        # ... run setup module
        stats = ansible.callbacks.AggregateStats()
        # callbacks = ansible.callbacks.PlaybookCallbacks(verbose=VERBOSITY)
        # runner_callbacks = ansible.callbacks.PlaybookRunnerCallbacks(
        #     stats, verbose=VERBOSITY)
        playbook = PlayBook(
            playbook=playbook_file.name,
            inventory=inventory,
            callbacks=Callbacks(),
            runner_callbacks=Callbacks(),
            stats=stats,
        )
        playbook.run()

    finally:
        playbook_file.close()

    return playbook.SETUP_CACHE
Exemplo n.º 4
0
def gather_facts(host, inventory=None):
    if inventory is None:
        inventory = get_inventory()

    # Gather facts
    try:

        # ... temporary playbook file
        playbook_file = tempfile.NamedTemporaryFile()
        playbook_file.write(SETUP_PLAYBOOK.format(host=host))
        playbook_file.seek(0)

        # ... run setup module
        stats = ansible.callbacks.AggregateStats()
        # callbacks = ansible.callbacks.PlaybookCallbacks(verbose=VERBOSITY)
        # runner_callbacks = ansible.callbacks.PlaybookRunnerCallbacks(
        #     stats, verbose=VERBOSITY)
        playbook = PlayBook(
            playbook=playbook_file.name,
            inventory=inventory,
            callbacks=Callbacks(),
            runner_callbacks=Callbacks(),
            stats=stats,
        )
        playbook.run()

    finally:
        playbook_file.close()

    return playbook.SETUP_CACHE
Exemplo n.º 5
0
    def _on_relation_created(self, event):
        node_name = self._charm.get_hostname()
        node_addr = event.relation.data[self.model.unit]["ingress-address"]

        event.relation.data[self.model.unit]["inventory"] = json.dumps(
            get_inventory(node_name, node_addr))
        if self.framework.model.unit.is_leader():
            self.on.slurmd_peer_available.emit()
def main():
    path_to_stack = sys.argv[1]
    env_file_path = f'{path_to_stack}/latest/config/stroom_core.env'
    inventory = get_inventory()
    fqdn = get_service_fqdn(inventory)
    db_fqdn = get_db_fqdn(inventory)

    replace_host_ip_line(fqdn, env_file_path)
    replace_db_host_ip_line(db_fqdn, env_file_path)
Exemplo n.º 7
0
def main():
    path_to_stack = sys.argv[1]
    inventory = get_inventory()
    fqdn = get_service_fqdn(inventory)
    server_name_directive = "server_name "
    server_name_line = f'{server_name_directive} {fqdn};\n'
    server_conf_file = f"{path_to_stack}/volumes/nginx/conf/server.conf.template"
    print(f"Replacing the {Fore.GREEN}{server_name_directive}{Style.RESET_ALL} line in {Fore.GREEN}{server_conf_file}{Style.RESET_ALL} with {Fore.BLUE}{server_name_line}{Style.RESET_ALL}")
    replace_line(server_conf_file, server_name_directive, server_name_line)
Exemplo n.º 8
0
    def _assemble_slurm_configurator_inventory(self):
        """Assemble the slurm-configurator partition."""
        hostname = socket.gethostname()
        inventory = get_inventory(hostname, hostname)

        return {
            'inventory': [inventory],
            'partition_name': 'configurator',
            'partition_state': 'DRAIN',
            'partition_config': ''
        }
Exemplo n.º 9
0
    def _assemble_slurm_configurator_inventory(self):
        """Assemble the slurm-configurator partition."""
        hostname = socket.gethostname()
        inventory = get_inventory(hostname, hostname)

        return {
            "inventory": [inventory],
            "partition_name": "configurator",
            "partition_state": "INACTIVE",
            "partition_config": "",
        }
Exemplo n.º 10
0
def main():
    path_to_stack = sys.argv[1]
    # env_file_path = f"{path_to_stack}/latest/config/stroom_core.env"
    env_file_path = "{}/latest/config/stroom_core.env".format(path_to_stack)
    inventory = get_inventory()
    fqdn = get_service_fqdn(inventory)
    db_fqdn = get_db_fqdn(inventory)

    set_db_ports(env_file_path)
    replace_host_ip_line(fqdn, env_file_path)
    replace_db_host_ip_line(db_fqdn, env_file_path)
Exemplo n.º 11
0
def show_template(host, path, gather_facts=True,
                  inventory_file=None, password_file=None):
    inventory = get_inventory(inventory_file, password_file)
    setup_cache = get_gathered_facts(host, inventory) if gather_facts else {}

    # Show the template
    runner = Runner(
        inventory=inventory,
        setup_cache=setup_cache,
    )
    host_vars = runner.get_inject_vars(host)
    print template_from_file('.', path, host_vars)
Exemplo n.º 12
0
def show_template(host, path, gather_facts=True,
                  inventory_file=None, password_file=None,
                  user=None):
    inventory = get_inventory(inventory_file, password_file)
    setup_cache = get_gathered_facts(
            host, inventory, user) if gather_facts else {}
    # Show the template
    runner = Runner(
        inventory=inventory,
        setup_cache=setup_cache,
    )
    host_vars = runner.get_inject_vars(host)
    print template_from_file('.', path, host_vars)
def get_inventory():
    '''
    Get all products in the merchant inventory
    '''
    try:
        mid = request.args.get("mid")
    except Exception as e:
        raise InvalidRequest("Missing mid")
    merchant = utils.get_merchant(mid)
    products = utils.get_inventory(mid)
    return {
        "merchant_name": merchant["name"],
        "products": products,
        "message": "OK"
    }
Exemplo n.º 14
0
def show_vars(host, inventory_file=None, password_file=None):
    inventory = get_inventory(inventory_file, password_file)
    Runner.get_inject_vars = get_inject_vars
    runner = Runner(inventory=inventory)
    runner.get_inject_vars(host)
Exemplo n.º 15
0
def show_vars(host, inventory_file=None, password_file=None):
    inventory = get_inventory(inventory_file, password_file)
    Runner.get_inject_vars = get_inject_vars
    runner = Runner(inventory=inventory)
    runner.get_inject_vars(host)
Exemplo n.º 16
0
from utils import get_inventory, get_service_fqdn
from colorama import Fore, Back, Style

service_fqdn = get_service_fqdn(get_inventory())
# stroom_url = f"https://{service_fqdn}"
stroom_url = "https://" + service_fqdn
# print(f"You can get to this Stroom deployment by going here: {Fore.GREEN}{stroom_url}clear/")
print("You can get to this Stroom deployment by going here: " + stroom_url +
      "/")