diff options
Diffstat (limited to 'utils/src')
-rw-r--r-- | utils/src/ooinstall/cli_installer.py | 75 | ||||
-rw-r--r-- | utils/src/ooinstall/oo_config.py | 8 | ||||
-rw-r--r-- | utils/src/ooinstall/openshift_ansible.py | 22 |
3 files changed, 86 insertions, 19 deletions
diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index f09f90288..c53ca7b18 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -163,8 +163,12 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen if masters_set or num_masters != 2: more_hosts = click.confirm('Do you want to add additional hosts?') - if num_masters >= 3: + if num_masters == 1: + master = next((host for host in hosts if host.master), None) + master.storage = True + elif num_masters >= 3: collect_master_lb(hosts) + collect_storage_host(hosts) return hosts @@ -202,8 +206,9 @@ Please add one more to proceed.""" elif len(masters) >= 3: ha_message = """ NOTE: Multiple Masters specified, this will be an HA deployment with a separate -etcd cluster. You will be prompted to provide the FQDN of a load balancer once -finished entering hosts.""" +etcd cluster. You will be prompted to provide the FQDN of a load balancer and +a host for storage once finished entering hosts. +""" click.echo(ha_message) dedicated_nodes_message = """ @@ -243,6 +248,8 @@ def print_host_summary(all_hosts, host): click.echo(" - Etcd Member") else: click.echo(" - Etcd (Embedded)") + if host.storage: + click.echo(" - Storage") def collect_master_lb(hosts): @@ -291,6 +298,43 @@ hostname. master_lb = Host(**host_props) hosts.append(master_lb) +def collect_storage_host(hosts): + """ + Get a valid host for storage from the user and append it to the list of + hosts. + """ + message = """ +Setting up High Availability Masters requires a storage host. Please provide a +host that will be configured as a Registry Storage. +""" + click.echo(message) + host_props = {} + + hostname_or_ip = click.prompt('Enter hostname or IP address', + value_proc=validate_prompt_hostname) + existing, existing_host = is_host_already_node_or_master(hostname_or_ip, hosts) + if existing and existing_host.node: + existing_host.storage = True + else: + host_props['connect_to'] = hostname_or_ip + host_props['preconfigured'] = False + host_props['master'] = False + host_props['node'] = False + host_props['storage'] = True + storage = Host(**host_props) + hosts.append(storage) + +def is_host_already_node_or_master(hostname, hosts): + is_existing = False + existing_host = None + + for host in hosts: + if host.connect_to == hostname and (host.master or host.node): + is_existing = True + existing_host = host + + return is_existing, existing_host + def confirm_hosts_facts(oo_cfg, callback_facts): hosts = oo_cfg.hosts click.clear() @@ -330,11 +374,15 @@ Notes: for h in hosts: if h.preconfigured == True: continue - default_facts[h.connect_to] = {} - h.ip = callback_facts[h.connect_to]["common"]["ip"] - h.public_ip = callback_facts[h.connect_to]["common"]["public_ip"] - h.hostname = callback_facts[h.connect_to]["common"]["hostname"] - h.public_hostname = callback_facts[h.connect_to]["common"]["public_hostname"] + try: + default_facts[h.connect_to] = {} + h.ip = callback_facts[h.connect_to]["common"]["ip"] + h.public_ip = callback_facts[h.connect_to]["common"]["public_ip"] + h.hostname = callback_facts[h.connect_to]["common"]["hostname"] + h.public_hostname = callback_facts[h.connect_to]["common"]["public_hostname"] + except KeyError: + click.echo("Problem fetching facts from {}".format(h.connect_to)) + continue default_facts_lines.append(",".join([h.connect_to, h.ip, @@ -533,22 +581,25 @@ def get_installed_hosts(hosts, callback_facts): try: first_master = next(host for host in hosts if host.master) lb_hostname = callback_facts[first_master.connect_to]['master'].get('cluster_hostname', '') - lb_host = next(host for host in hosts if host.connect_to == lb_hostname) + lb_host = \ + next(host for host in hosts if host.ip == callback_facts[lb_hostname]['common']['ip']) + installed_hosts.append(lb_host) - except KeyError: + except (KeyError, StopIteration): pass - for host in hosts: if host.connect_to in callback_facts.keys() and is_installed_host(host, callback_facts): installed_hosts.append(host) return installed_hosts def is_installed_host(host, callback_facts): - return 'common' in callback_facts[host.connect_to].keys() and \ + version_found = 'common' in callback_facts[host.connect_to].keys() and \ callback_facts[host.connect_to]['common'].get('version', '') and \ callback_facts[host.connect_to]['common'].get('version', '') != 'None' + return version_found or host.master_lb or host.preconfigured + # pylint: disable=too-many-branches # This pylint error will be corrected shortly in separate PR. def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force, verbose): diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index b1af21773..c9498542f 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -50,13 +50,17 @@ class Host(object): # Should this host run as an HAProxy: self.master_lb = kwargs.get('master_lb', False) + # Should this host run as an HAProxy: + self.storage = kwargs.get('storage', False) + self.containerized = kwargs.get('containerized', False) if self.connect_to is None: raise OOConfigInvalidHostError("You must specify either an ip " \ "or hostname as 'connect_to'") - if self.master is False and self.node is False and self.master_lb is False: + if self.master is False and self.node is False and \ + self.master_lb is False and self.storage is False: raise OOConfigInvalidHostError( "You must specify each host as either a master or a node.") @@ -70,7 +74,7 @@ class Host(object): """ Used when exporting to yaml. """ d = {} for prop in ['ip', 'hostname', 'public_ip', 'public_hostname', - 'master', 'node', 'master_lb', 'containerized', + 'master', 'node', 'master_lb', 'storage', 'containerized', 'connect_to', 'preconfigured', 'new_host']: # If the property is defined (not None or False), export it: if getattr(self, prop): diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py index f2c7289fa..04cccf89d 100644 --- a/utils/src/ooinstall/openshift_ansible.py +++ b/utils/src/ooinstall/openshift_ansible.py @@ -21,13 +21,14 @@ def generate_inventory(hosts): nodes = [host for host in hosts if host.node] new_nodes = [host for host in hosts if host.node and host.new_host] proxy = determine_proxy_configuration(hosts) + storage = determine_storage_configuration(hosts) multiple_masters = len(masters) > 1 scaleup = len(new_nodes) > 0 base_inventory_path = CFG.settings['ansible_inventory_path'] base_inventory = open(base_inventory_path, 'w') - write_inventory_children(base_inventory, multiple_masters, proxy, scaleup) + write_inventory_children(base_inventory, multiple_masters, proxy, storage, scaleup) write_inventory_vars(base_inventory, multiple_masters, proxy) @@ -73,11 +74,16 @@ def generate_inventory(hosts): base_inventory.write('\n[lb]\n') write_host(proxy, base_inventory) + if scaleup: base_inventory.write('\n[new_nodes]\n') for node in new_nodes: write_host(node, base_inventory) + if storage: + base_inventory.write('\n[nfs]\n') + write_host(storage, base_inventory) + base_inventory.close() return base_inventory_path @@ -87,11 +93,15 @@ def determine_proxy_configuration(hosts): if proxy.hostname == None: proxy.hostname = proxy.connect_to proxy.public_hostname = proxy.connect_to - return proxy - return None + return proxy + +def determine_storage_configuration(hosts): + storage = next((host for host in hosts if host.storage), None) + + return storage -def write_inventory_children(base_inventory, multiple_masters, proxy, scaleup): +def write_inventory_children(base_inventory, multiple_masters, proxy, storage, scaleup): global CFG base_inventory.write('\n[OSEv3:children]\n') @@ -103,6 +113,8 @@ def write_inventory_children(base_inventory, multiple_masters, proxy, scaleup): base_inventory.write('etcd\n') if not getattr(proxy, 'preconfigured', True): base_inventory.write('lb\n') + if storage: + base_inventory.write('nfs\n') def write_inventory_vars(base_inventory, multiple_masters, proxy): global CFG @@ -117,7 +129,7 @@ def write_inventory_vars(base_inventory, multiple_masters, proxy): "openshift_master_cluster_public_hostname={}\n".format(proxy.public_hostname)) if CFG.settings.get('master_routingconfig_subdomain', False): base_inventory.write( - "osm_default_subdomain={}\n".format(CFG.settings['master_routingconfig_subdomain'])) + "openshift_master_default_subdomain={}\n".format(CFG.settings['master_routingconfig_subdomain'])) |