summaryrefslogtreecommitdiffstats
path: root/roles/openshift_facts/library
diff options
context:
space:
mode:
Diffstat (limited to 'roles/openshift_facts/library')
-rwxr-xr-xroles/openshift_facts/library/openshift_facts.py215
1 files changed, 164 insertions, 51 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index 5648c179e..b06900681 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -27,6 +27,38 @@ from distutils.version import LooseVersion
import struct
import socket
+
+def migrate_docker_facts(facts):
+ """ Apply migrations for docker facts """
+ params = {
+ 'common': (
+ 'additional_registries',
+ 'insecure_registries',
+ 'blocked_registries',
+ 'options'
+ ),
+ 'node': (
+ 'log_driver',
+ 'log_options'
+ )
+ }
+ if 'docker' not in facts:
+ facts['docker'] = {}
+ for role in params.keys():
+ if role in facts:
+ for param in params[role]:
+ old_param = 'docker_' + param
+ if old_param in facts[role]:
+ facts['docker'][param] = facts[role].pop(old_param)
+ return facts
+
+def migrate_local_facts(facts):
+ """ Apply migrations of local facts """
+ migrated_facts = copy.deepcopy(facts)
+ return migrate_docker_facts(migrated_facts)
+
+
+
def first_ip(network):
""" Return the first IPv4 address in network
@@ -662,18 +694,13 @@ def set_deployment_facts_if_unset(facts):
data_dir = '/var/lib/openshift'
facts['common']['data_dir'] = data_dir
- # remove duplicate and empty strings from registry lists
- for cat in ['additional', 'blocked', 'insecure']:
- key = 'docker_{0}_registries'.format(cat)
- if key in facts['common']:
- facts['common'][key] = list(set(facts['common'][key]) - set(['']))
-
-
+ if 'docker' in facts:
+ deployment_type = facts['common']['deployment_type']
if deployment_type in ['enterprise', 'atomic-enterprise', 'openshift-enterprise']:
- addtl_regs = facts['common'].get('docker_additional_registries', [])
+ addtl_regs = facts['docker'].get('additional_registries', [])
ent_reg = 'registry.access.redhat.com'
if ent_reg not in addtl_regs:
- facts['common']['docker_additional_registries'] = addtl_regs + [ent_reg]
+ facts['docker']['additional_registries'] = addtl_regs + [ent_reg]
for role in ('master', 'node'):
if role in facts:
@@ -718,7 +745,7 @@ def set_version_facts_if_unset(facts):
"""
if 'common' in facts:
deployment_type = facts['common']['deployment_type']
- facts['common']['version'] = version = get_openshift_version()
+ facts['common']['version'] = version = get_openshift_version(facts)
if version is not None:
if deployment_type == 'origin':
version_gte_3_1_or_1_1 = LooseVersion(version) >= LooseVersion('1.1.0')
@@ -736,6 +763,15 @@ def set_version_facts_if_unset(facts):
facts['common']['version_gte_3_1_1_or_1_1_1'] = version_gte_3_1_1_or_1_1_1
facts['common']['version_gte_3_2_or_1_2'] = version_gte_3_2_or_1_2
+ if version_gte_3_2_or_1_2:
+ examples_content_version = 'v1.2'
+ elif version_gte_3_1_or_1_1:
+ examples_content_version = 'v1.1'
+ else:
+ examples_content_version = 'v1.0'
+
+ facts['common']['examples_content_version'] = examples_content_version
+
return facts
def set_manageiq_facts_if_unset(facts):
@@ -771,7 +807,7 @@ def set_sdn_facts_if_unset(facts, system_facts):
if 'common' in facts:
use_sdn = facts['common']['use_openshift_sdn']
if not (use_sdn == '' or isinstance(use_sdn, bool)):
- use_sdn = bool(strtobool(str(use_sdn)))
+ use_sdn = safe_get_bool(use_sdn)
facts['common']['use_openshift_sdn'] = use_sdn
if 'sdn_network_plugin_name' not in facts['common']:
plugin = 'redhat/openshift-ovs-subnet' if use_sdn else ''
@@ -878,22 +914,65 @@ def get_current_config(facts):
return current_config
-def get_openshift_version():
+def get_openshift_version(facts, cli_image=None):
""" Get current version of openshift on the host
+ Args:
+ facts (dict): existing facts
+ optional cli_image for pulling the version number
+
Returns:
version: the current openshift version
"""
version = None
+ # No need to run this method repeatedly on a system if we already know the
+ # version
+ if 'common' in facts:
+ if 'version' in facts['common'] and facts['common']['version'] is not None:
+ return facts['common']['version']
+
if os.path.isfile('/usr/bin/openshift'):
_, output, _ = module.run_command(['/usr/bin/openshift', 'version'])
- versions = dict(e.split(' v') for e in output.splitlines() if ' v' in e)
- version = versions.get('openshift', '')
+ version = parse_openshift_version(output)
+
+ if 'is_containerized' in facts['common'] and safe_get_bool(facts['common']['is_containerized']):
+ container = None
+ if 'master' in facts:
+ if 'cluster_method' in facts['master']:
+ container = facts['common']['service_type'] + '-master-api'
+ else:
+ container = facts['common']['service_type'] + '-master'
+ elif 'node' in facts:
+ container = facts['common']['service_type'] + '-node'
+
+ if container is not None:
+ exit_code, output, _ = module.run_command(['docker', 'exec', container, 'openshift', 'version'])
+ # if for some reason the container is installed but not running
+ # we'll fall back to using docker run later in this method.
+ if exit_code == 0:
+ version = parse_openshift_version(output)
+
+ if version is None and cli_image is not None:
+ # Assume we haven't installed the environment yet and we need
+ # to query the latest image
+ exit_code, output, _ = module.run_command(['docker', 'run', '--rm', cli_image, 'version'])
+ version = parse_openshift_version(output)
- #TODO: acknowledge the possility of a containerized install
return version
+def parse_openshift_version(output):
+ """ Apply provider facts to supplied facts dict
+
+ Args:
+ string: output of 'openshift version'
+ Returns:
+ string: the version number
+ """
+ versions = dict(e.split(' v') for e in output.splitlines() if ' v' in e)
+ return versions.get('openshift', '')
+
+
def apply_provider_facts(facts, provider_facts):
""" Apply provider facts to supplied facts dict
@@ -985,7 +1064,7 @@ def merge_facts(orig, new, additive_facts_to_overwrite, protected_facts_to_overw
# ha (bool) can not change unless it has been passed
# as a protected fact to overwrite.
if key == 'ha':
- if bool(value) != bool(new[key]):
+ if safe_get_bool(value) != safe_get_bool(new[key]):
module.fail_json(msg='openshift_facts received a different value for openshift.master.ha')
else:
facts[key] = value
@@ -1074,6 +1153,15 @@ def get_local_facts_from_file(filename):
return local_facts
+def safe_get_bool(fact):
+ """ Get a boolean fact safely.
+
+ Args:
+ facts: fact to convert
+ Returns:
+ bool: given fact as a bool
+ """
+ return bool(strtobool(str(fact)))
def set_container_facts_if_unset(facts):
""" Set containerized facts.
@@ -1119,9 +1207,11 @@ def set_container_facts_if_unset(facts):
if 'ovs_image' not in facts['node']:
facts['node']['ovs_image'] = ovs_image
- if facts['common']['is_containerized']:
+ if safe_get_bool(facts['common']['is_containerized']):
facts['common']['admin_binary'] = '/usr/local/bin/oadm'
facts['common']['client_binary'] = '/usr/local/bin/oc'
+ base_version = get_openshift_version(facts, cli_image).split('-')[0]
+ facts['common']['image_tag'] = "v" + base_version
return facts
@@ -1187,7 +1277,7 @@ class OpenShiftFacts(object):
Raises:
OpenShiftFactsUnsupportedRoleError:
"""
- known_roles = ['common', 'master', 'node', 'etcd', 'hosted']
+ known_roles = ['common', 'master', 'node', 'etcd', 'hosted', 'docker']
# Disabling too-many-arguments, this should be cleaned up as a TODO item.
# pylint: disable=too-many-arguments
@@ -1231,7 +1321,13 @@ class OpenShiftFacts(object):
protected_facts_to_overwrite)
roles = local_facts.keys()
- defaults = self.get_defaults(roles)
+
+ if 'common' in local_facts and 'deployment_type' in local_facts['common']:
+ deployment_type = local_facts['common']['deployment_type']
+ else:
+ deployment_type = 'origin'
+
+ defaults = self.get_defaults(roles, deployment_type)
provider_facts = self.init_provider_facts()
facts = apply_provider_facts(defaults, provider_facts)
facts = merge_facts(facts,
@@ -1255,11 +1351,11 @@ class OpenShiftFacts(object):
facts = set_aggregate_facts(facts)
facts = set_etcd_facts_if_unset(facts)
facts = set_container_facts_if_unset(facts)
- if not facts['common']['is_containerized']:
+ if not safe_get_bool(facts['common']['is_containerized']):
facts = set_installed_variant_rpm_facts(facts)
return dict(openshift=facts)
- def get_defaults(self, roles):
+ def get_defaults(self, roles, deployment_type):
""" Get default fact values
Args:
@@ -1268,8 +1364,7 @@ class OpenShiftFacts(object):
Returns:
dict: The generated default facts
"""
- defaults = dict()
-
+ defaults = {}
ip_addr = self.system_facts['default_ipv4']['address']
exit_code, output, _ = module.run_command(['hostname', '-f'])
hostname_f = output.strip() if exit_code == 0 else ''
@@ -1277,33 +1372,42 @@ class OpenShiftFacts(object):
self.system_facts['fqdn']]
hostname = choose_hostname(hostname_values, ip_addr)
- common = dict(use_openshift_sdn=True, ip=ip_addr, public_ip=ip_addr,
- deployment_type='origin', hostname=hostname,
- public_hostname=hostname)
- common['client_binary'] = 'oc'
- common['admin_binary'] = 'oadm'
- common['dns_domain'] = 'cluster.local'
- common['install_examples'] = True
- defaults['common'] = common
+ defaults['common'] = dict(use_openshift_sdn=True, ip=ip_addr,
+ public_ip=ip_addr,
+ deployment_type=deployment_type,
+ hostname=hostname,
+ public_hostname=hostname,
+ client_binary='oc', admin_binary='oadm',
+ dns_domain='cluster.local',
+ install_examples=True,
+ debug_level=2)
if 'master' in roles:
- master = dict(api_use_ssl=True, api_port='8443', controllers_port='8444',
- console_use_ssl=True, console_path='/console',
- console_port='8443', etcd_use_ssl=True, etcd_hosts='',
- etcd_port='4001', portal_net='172.30.0.0/16',
- embedded_etcd=True, embedded_kube=True,
- embedded_dns=True, dns_port='53',
- bind_addr='0.0.0.0', session_max_seconds=3600,
- session_name='ssn', session_secrets_file='',
- access_token_max_seconds=86400,
- auth_token_max_seconds=500,
- oauth_grant_method='auto')
- defaults['master'] = master
+ defaults['master'] = dict(api_use_ssl=True, api_port='8443',
+ controllers_port='8444',
+ console_use_ssl=True,
+ console_path='/console',
+ console_port='8443', etcd_use_ssl=True,
+ etcd_hosts='', etcd_port='4001',
+ portal_net='172.30.0.0/16',
+ embedded_etcd=True, embedded_kube=True,
+ embedded_dns=True, dns_port='53',
+ bind_addr='0.0.0.0',
+ session_max_seconds=3600,
+ session_name='ssn',
+ session_secrets_file='',
+ access_token_max_seconds=86400,
+ auth_token_max_seconds=500,
+ oauth_grant_method='auto')
if 'node' in roles:
- node = dict(labels={}, annotations={}, portal_net='172.30.0.0/16',
- iptables_sync_period='5s', set_node_ip=False)
- defaults['node'] = node
+ defaults['node'] = dict(labels={}, annotations={},
+ portal_net='172.30.0.0/16',
+ iptables_sync_period='5s',
+ set_node_ip=False)
+
+ if 'docker' in roles:
+ defaults['docker'] = dict(disable_push_dockerhub=False)
defaults['hosted'] = dict(
registry=dict(
@@ -1323,6 +1427,7 @@ class OpenShiftFacts(object):
)
)
+
return defaults
def guess_host_provider(self):
@@ -1448,15 +1553,23 @@ class OpenShiftFacts(object):
local_facts = get_local_facts_from_file(self.filename)
- for arg in ['labels', 'annotations']:
- if arg in facts_to_set and isinstance(facts_to_set[arg],
- basestring):
- facts_to_set[arg] = module.from_json(facts_to_set[arg])
+ migrated_facts = migrate_local_facts(local_facts)
- new_local_facts = merge_facts(local_facts,
+ new_local_facts = merge_facts(migrated_facts,
facts_to_set,
additive_facts_to_overwrite,
protected_facts_to_overwrite)
+
+ if 'docker' in new_local_facts:
+ # remove duplicate and empty strings from registry lists
+ for cat in ['additional', 'blocked', 'insecure']:
+ key = '{0}_registries'.format(cat)
+ if key in new_local_facts['docker']:
+ val = new_local_facts['docker'][key]
+ if isinstance(val, basestring):
+ val = [x.strip() for x in val.split(',')]
+ new_local_facts['docker'][key] = list(set(val) - set(['']))
+
for facts in new_local_facts.values():
keys_to_delete = []
if isinstance(facts, dict):