Bläddra i källkod

Merge pull request #821 from smunilla/connect_to

atomic-openshift-installer: Better specification of ansible connection point
Brenton Leanhardt 9 år sedan
förälder
incheckning
f50cb24856

+ 3 - 0
utils/docs/config.md

@@ -19,16 +19,19 @@ hosts:
   master: true
   node: true
   containerized: true
+  connect_to: 24.222.0.1
 - ip: 10.0.0.2
   hostname: node1-private.example.com
   public_ip: 24.222.0.2
   public_hostname: node1.example.com
   node: true
+  connect_to: 10.0.0.2
 - ip: 10.0.0.3
   hostname: node2-private.example.com
   public_ip: 24.222.0.3
   public_hostname: node2.example.com
   node: true
+  connect_to: 10.0.0.3
 ```
 
 ## Primary Settings

+ 16 - 22
utils/src/ooinstall/cli_installer.py

@@ -101,18 +101,13 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen
 
     hosts = []
     more_hosts = True
-    ip_regex = re.compile(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$')
-
     while more_hosts:
         host_props = {}
         hostname_or_ip = click.prompt('Enter hostname or IP address:',
                                       default='',
                                       value_proc=validate_prompt_hostname)
 
-        if ip_regex.match(hostname_or_ip):
-            host_props['ip'] = hostname_or_ip
-        else:
-            host_props['hostname'] = hostname_or_ip
+        host_props['connect_to'] = hostname_or_ip
 
         host_props['master'] = click.confirm('Will this host be an OpenShift Master?')
         host_props['node'] = True
@@ -150,7 +145,7 @@ Plese confirm that they are correct before moving forward.
     notes = """
 Format:
 
-IP,public IP,hostname,public hostname
+connect_to,IP,public IP,hostname,public hostname
 
 Notes:
  * The installation host is the hostname from the installer's perspective.
@@ -168,16 +163,15 @@ Notes:
 
     default_facts_lines = []
     default_facts = {}
-    validated_facts = {}
     for h in hosts:
-        default_facts[h] = {}
-        h.ip = callback_facts[str(h)]["common"]["ip"]
-        h.public_ip = callback_facts[str(h)]["common"]["public_ip"]
-        h.hostname = callback_facts[str(h)]["common"]["hostname"]
-        h.public_hostname = callback_facts[str(h)]["common"]["public_hostname"]
-
-        validated_facts[h] = {}
-        default_facts_lines.append(",".join([h.ip,
+        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"]
+
+        default_facts_lines.append(",".join([h.connect_to,
+                                             h.ip,
                                              h.public_ip,
                                              h.hostname,
                                              h.public_hostname]))
@@ -316,10 +310,10 @@ Add new nodes here
 def get_installed_hosts(hosts, callback_facts):
     installed_hosts = []
     for host in hosts:
-        if(host.name in callback_facts.keys()
-           and 'common' in callback_facts[host.name].keys()
-           and callback_facts[host.name]['common'].get('version', '')
-           and callback_facts[host.name]['common'].get('version', '') != 'None'):
+        if(host.connect_to in callback_facts.keys()
+           and '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'):
             installed_hosts.append(host)
     return installed_hosts
 
@@ -475,7 +469,7 @@ def uninstall(ctx):
     if not ctx.obj['unattended']:
         # Prompt interactively to confirm:
         for host in oo_cfg.hosts:
-            click.echo("  * %s" % host.name)
+            click.echo("  * %s" % host.connect_to)
         proceed = click.confirm("\nDo you wish to proceed?")
         if not proceed:
             click.echo("Uninstall cancelled.")
@@ -505,7 +499,7 @@ def upgrade(ctx):
         old_variant, old_version, oo_cfg.settings['variant'],
         oo_cfg.settings['variant_version']))
     for host in oo_cfg.hosts:
-        click.echo("  * %s" % host.name)
+        click.echo("  * %s" % host.connect_to)
 
     if not ctx.obj['unattended']:
         # Prompt interactively to confirm:

+ 9 - 13
utils/src/ooinstall/oo_config.py

@@ -35,6 +35,7 @@ class Host(object):
         self.hostname = kwargs.get('hostname', None)
         self.public_ip = kwargs.get('public_ip', None)
         self.public_hostname = kwargs.get('public_hostname', None)
+        self.connect_to = kwargs.get('connect_to', None)
 
         # Should this host run as an OpenShift master:
         self.master = kwargs.get('master', False)
@@ -43,30 +44,25 @@ class Host(object):
         self.node = kwargs.get('node', False)
         self.containerized = kwargs.get('containerized', False)
 
-        if self.ip is None and self.hostname is None:
-            raise OOConfigInvalidHostError("You must specify either 'ip' or 'hostname'")
+        if self.connect_to is None:
+            raise OOConfigInvalidHostError("You must specify either and 'ip' " \
+                                           "or 'hostname' to connect to.")
 
         if self.master is False and self.node is False:
             raise OOConfigInvalidHostError(
                 "You must specify each host as either a master or a node.")
 
-        # Hosts can be specified with an ip, hostname, or both. However we need
-        # something authoritative we can connect to and refer to the host by.
-        # Preference given to the IP if specified as this is more specific.
-        # We know one must be set by this point.
-        self.name = self.ip if self.ip is not None else self.hostname
-
     def __str__(self):
-        return self.name
+        return self.connect_to
 
     def __repr__(self):
-        return self.name
+        return self.connect_to
 
     def to_dict(self):
         """ Used when exporting to yaml. """
         d = {}
         for prop in ['ip', 'hostname', 'public_ip', 'public_hostname',
-                     'master', 'node', 'containerized']:
+                     'master', 'node', 'containerized', 'connect_to']:
             # If the property is defined (not None or False), export it:
             if getattr(self, prop):
                 d[prop] = getattr(self, prop)
@@ -182,7 +178,7 @@ class OOConfig(object):
                 if not getattr(host, required_fact):
                     missing_facts.append(required_fact)
             if len(missing_facts) > 0:
-                result[host.name] = missing_facts
+                result[host.connect_to] = missing_facts
         return result
 
     def save_to_disk(self):
@@ -214,6 +210,6 @@ class OOConfig(object):
 
     def get_host(self, name):
         for host in self.hosts:
-            if host.name == name:
+            if host.connect_to == name:
                 return host
         return None

+ 1 - 1
utils/src/ooinstall/openshift_ansible.py

@@ -88,7 +88,7 @@ def write_host(host, inventory, scheduleable=True):
                 sys.exit(1)
             facts += ' ansible_become=true'
 
-    inventory.write('{} {}\n'.format(host, facts))
+    inventory.write('{} {}\n'.format(host.connect_to, facts))
 
 
 def load_system_facts(inventory_file, os_facts_path, env_vars):