コード例 #1
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        ntp_servers = CloudModel.get(self._cloud_internal, 'ntp_servers')
        dns_settings = CloudModel.get(self._cloud_internal, 'dns_settings')
        smtp_settings = CloudModel.get(self._cloud_internal, 'smtp_settings')
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        net_group_firewall = CloudModel.get(self._cloud_internal, 'net-group-firewall')
        firewall_settings = CloudModel.get(self._cloud_internal, 'firewall_settings')
        pass_through = CloudModel.get(self._cloud_internal, 'pass_through')
        components = CloudModel.get(self._cloud_internal, 'components')
        services = CloudModel.get(self._cloud_internal, 'services')

        for cp_name, cp in control_planes.iteritems():
            for cluster in cp['clusters']:
                for s in cluster['servers']:
                    self._build_ansible_host_vars(cloud_name, s, cp['endpoints'],
                                                  cp, cluster['name'],
                                                  ntp_servers, dns_settings, smtp_settings,
                                                  pass_through, components, services,
                                                  net_group_firewall, firewall_settings)

            for r_name, resources in cp.get('resources', {}).iteritems():
                for s in resources['servers']:
                    self._build_ansible_host_vars(cloud_name, s, cp['endpoints'],
                                                  cp, resources['name'],
                                                  ntp_servers, dns_settings, smtp_settings,
                                                  pass_through, components, services,
                                                  net_group_firewall, firewall_settings)

        CloudModel.put(self._cloud_internal, 'cloud-firewall', self._cloud_firewall)
コード例 #2
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        ntp_servers = CloudModel.get(self._cloud_internal, 'ntp_servers')
        dns_settings = CloudModel.get(self._cloud_internal, 'dns_settings')
        smtp_settings = CloudModel.get(self._cloud_internal, 'smtp_settings')
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        net_group_firewall = CloudModel.get(self._cloud_internal,
                                            'net-group-firewall')
        firewall_settings = CloudModel.get(self._cloud_internal,
                                           'firewall_settings')
        pass_through = CloudModel.get(self._cloud_internal, 'pass_through')
        components = CloudModel.get(self._cloud_internal, 'components')
        services = CloudModel.get(self._cloud_internal, 'services')

        for cp_name, cp in control_planes.iteritems():
            for cluster in cp['clusters']:
                for s in cluster['servers']:
                    self._build_ansible_host_vars(
                        cloud_name, s, cp['endpoints'], cp, cluster['name'],
                        ntp_servers, dns_settings, smtp_settings, pass_through,
                        components, services, net_group_firewall,
                        firewall_settings)

            for r_name, resources in cp.get('resources', {}).iteritems():
                for s in resources['servers']:
                    self._build_ansible_host_vars(
                        cloud_name, s, cp['endpoints'], cp, resources['name'],
                        ntp_servers, dns_settings, smtp_settings, pass_through,
                        components, services, net_group_firewall,
                        firewall_settings)

        CloudModel.put(self._cloud_internal, 'cloud-firewall',
                       self._cloud_firewall)
コード例 #3
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        file_name = os.path.join(self._file_path, 'hosts.hf')
        self.add_artifact(file_name, ArtifactMode.CREATED)

        allocated_addresses = CloudModel.get(self._cloud_internal, 'address_allocations')
        host_aliases = CloudModel.get(self._cloud_internal, 'host_aliases')
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)

        with open(file_name, 'w') as fp:
            fp.write("# Cloud: %s\n" % (cloud_name))
            fp.write("\n")
            fp.write("# Localhost Information\n")
            fp.write("127.0.0.1      localhost\n")
            fp.write("\n")

            for group_name, group in allocated_addresses.iteritems():
                fp.write("#\n")
                fp.write("# Network Group: %s\n" % (group_name))
                fp.write("#\n")
                for network_name, network in group.iteritems():
                    fp.write("# Network: %s\n" % (network_name))
                    ips = []
                    for addr in network:
                        aliases = host_aliases.get(group_name,
                                                   {}).get(network_name,
                                                           {}).get(addr, [])
                        for name in aliases:
                            # Expand the address to a string with leading spaces
                            # in each quad so that it sorts by version
                            ips.append(["%3s.%3s.%3s.%3s" % tuple(addr.split(".")), name])
                    for ip in sorted(ips, key=itemgetter(0)):
                        fp.write("%-16s %s\n" % (ip[0].replace(" ", ""), ip[1]))
コード例 #4
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        components = CloudModel.get(self._cloud_internal, 'components')
        components_by_mnemonic = CloudModel.get(self._cloud_internal, 'components_by_mnemonic')

        for cp_name, cp in control_planes.iteritems():
            self._build_ansible_group_vars(cloud_name, cp, components, components_by_mnemonic)
コード例 #5
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        file_name = os.path.join(self._file_path, 'hosts.hf')
        self.add_artifact(file_name, ArtifactMode.CREATED)

        allocated_addresses = CloudModel.get(self._cloud_internal,
                                             'address_allocations')
        host_aliases = CloudModel.get(self._cloud_internal, 'host_aliases')
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)

        with open(file_name, 'w') as fp:
            fp.write("# Cloud: %s\n" % (cloud_name))
            fp.write("\n")
            fp.write("# Localhost Information\n")
            fp.write("127.0.0.1      localhost\n")
            fp.write("\n")

            for group_name, group in allocated_addresses.iteritems():
                fp.write("#\n")
                fp.write("# Network Group: %s\n" % (group_name))
                fp.write("#\n")
                for network_name, network in group.iteritems():
                    fp.write("# Network: %s\n" % (network_name))
                    ips = []
                    for addr in network:
                        aliases = host_aliases.get(group_name,
                                                   {}).get(network_name,
                                                           {}).get(addr, [])
                        for name in aliases:
                            # Expand the address to a string with leading spaces
                            # in each quad so that it sorts by version
                            ips.append([
                                "%3s.%3s.%3s.%3s" % tuple(addr.split(".")),
                                name
                            ])
                    for ip in sorted(ips, key=itemgetter(0)):
                        fp.write("%-16s %s\n" %
                                 (ip[0].replace(" ", ""), ip[1]))
コード例 #6
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        filename = "%s/group_vars/all" % (self._file_path)
        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))
        self.add_artifact(filename, ArtifactMode.CREATED)

        global_vars = {'global': {'ansible_vars': [],
                                  'all_servers': []}}
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        service_view = CloudModel.get(self._cloud_internal, 'service_view')
        service_view = service_view['by_region']
        servers = CloudModel.get(self._cloud_internal, 'servers')
        ring_specifications = CloudModel.get(self._cloud_internal,
                                             'ring-specifications', [])
        pass_through = CloudModel.get(self._cloud_internal, 'pass_through')
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        ntp_servers = self.cloud_desc['ntp-servers']

        if ntp_servers:
            global_vars['global']['ntp_servers'] = ntp_servers

        #
        # Add a list of all vips
        #
        vips = set()
        for cp_name, cp in control_planes.iteritems():
            for ep_name, ep_data in cp['endpoints'].iteritems():
                for role, role_data in ep_data.iteritems():
                    if role not in ['internal', 'admin']:
                        continue
                    for data in role_data:
                        access = data.get('access', {})
                        if 'hostname' in access:
                            vips.add(data['access']['hostname'])
                        for host_data in access.get('members', []):
                            vips.add(host_data['hostname'])

        if ring_specifications:
            ring_specifications = DataTransformer(
                ring_specifications).all_output('-', '_')
            global_vars['global']['all_ring_specifications'] =\
                ring_specifications
        else:
            global_vars['global']['all_ring_specifications'] = []

        if pass_through:
            global_vars['global']['pass_through'] = pass_through['global']

        global_vars['global']['vips'] = sorted(vips)

        global_vars['topology'] = {'cloud_name': cloud_name,
                                   'control_planes': []}
        for cp_name in sorted(service_view):
            cp = service_view[cp_name]
            cp_data = {'name': cp_name,
                       'services': []}
            for service_name in sorted(cp):
                components = cp[service_name]
                service_data = {'name': service_name,
                                'components': []}

                for component_name in sorted(components):
                    hosts = components[component_name]
                    component_data = {'name': component_name,
                                      'hosts': sorted(hosts)}
                    service_data['components'].append(component_data)

                cp_data['services'].append(service_data)

            global_vars['topology']['control_planes'].append(cp_data)

        #
        # Include disk details of all servers for Swift
        #
        for server in servers:
            if server['state'] == ServerState.ALLOCATED:
                disk_model_out = DataTransformer(
                    server['disk-model']).all_output('-', '_')
                server_info = {'name': server['hostname'],
                               'rack': server.get('rack', None),
                               'region': server.get('region', None),
                               'disk_model': disk_model_out}
                global_vars['global']['all_servers'].append(server_info)

                network_names = []
                for if_name, if_data in server['interfaces'].iteritems():
                    for net_name, net_data in if_data['networks'].iteritems():
                        if 'hostname' in net_data:
                            network_names.append(net_data['hostname'])
                server_info['network_names'] = network_names

        with open(filename, 'w') as fp:
            yaml.dump(global_vars, fp, default_flow_style=False, indent=4)
コード例 #7
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        components = CloudModel.get(self._cloud_internal, 'components')
        server_groups = CloudModel.get(self._cloud_internal, 'server-groups')

        filename = "%s/hosts/localhost" % (self._file_path)
        self.add_artifact(filename, ArtifactMode.CREATED)
        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        with open(filename, 'w') as f:
            f.write("localhost\n")

        filename = "%s/hosts/verb_hosts" % (self._file_path)
        self.add_artifact(filename, ArtifactMode.CREATED)
        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        with open(filename, 'w') as f:
            f.write("[localhost]\n")
            f.write("localhost\n")
            f.write("\n")

            f.write("[resources:children]\n")
            for cp_name in sorted(control_planes):
                cp = control_planes[cp_name]
                for cluster in cp['clusters']:
                    for server in cluster['servers']:
                        f.write("%s\n" % server['hostname'])
                for resource_group_name, resource_group in cp.get('resources', {}).iteritems():
                    for server in resource_group['servers']:
                        f.write("%s\n" % server['hostname'])
            f.write("\n")

            # Build a list of all control_planes
            f.write("[%s:children]\n" % (cloud_name))
            for cp_name in sorted(control_planes):
                f.write("%s-%s\n" % (cloud_name, cp_name))
            f.write("\n")

            # List all clusters and resource in a control plane
            for cp_name in sorted(control_planes):
                cp = control_planes[cp_name]
                f.write("[%s-%s:children]\n" % (cloud_name, cp_name))
                for cluster in cp['clusters']:
                    f.write("%s-%s-%s\n" % (cloud_name, cp_name, cluster['name']))
                for resource_group_name in cp.get('resources', []):
                    f.write("%s-%s-%s\n" % (cloud_name, cp_name, resource_group_name))
                f.write("\n")

            # List all members of each clusters in a cp
            for cp_name in sorted(control_planes):
                cp = control_planes[cp_name]
                for cluster in cp['clusters']:
                    f.write("[%s-%s-%s:children]\n" % (cloud_name, cp_name, cluster['name']))
                    for server in cluster['servers']:
                        f.write("%s\n" % server['hostname'])
                    f.write("\n")

                    for server in cluster['servers']:
                        f.write("[%s]\n" % server['hostname'])
                        f.write("%s ansible_ssh_host=%s\n" % (server['hostname'], server['addr']))
                        f.write("\n")

                for resource_group_name, resource_group in cp.get('resources', {}).iteritems():
                    f.write("[%s-%s-%s:children]\n" % (cloud_name, cp_name, resource_group_name))
                    for server in resource_group['servers']:
                        f.write("%s\n" % server['hostname'])
                    f.write("\n")

                    for server in resource_group['servers']:
                        f.write("[%s]\n" % server['hostname'])
                        f.write("%s ansible_ssh_host=%s\n" % (server['hostname'], server['addr']))
                        f.write("\n")

            # Build list of hosts by component accross all cps
            component_list = {}
            for cp_name, cp in control_planes.iteritems():
                for component_name, component_data in cp['components'].iteritems():
                    if component_name not in components:
                        print "Warning: No data for %s when building host_vars" % component_name
                        continue

                    component_mnemonic = components[component_name]['mnemonic']

                    if component_mnemonic not in component_list:
                        component_list[component_mnemonic] = {}

                    if cp_name not in component_list[component_mnemonic]:
                        component_list[component_mnemonic][cp_name] = {}

                    for cluster in cp['clusters']:
                        if (component_name in cluster['service-components'] or
                                component_name in cp.get('common-service-components', [])):

                            if cluster['name'] not in component_list[component_mnemonic][cp_name]:
                                component_list[component_mnemonic][cp_name][cluster['name']] = []
                            host_list = component_list[component_mnemonic][cp_name][cluster['name']]

                            for server in cluster['servers']:
                                host_list.append(server['hostname'])

                    if 'resources' in cp:
                        for r_name, resources in cp['resources'].iteritems():
                            if (component_name in resources['service-components'] or
                                    component_name in cp.get('common-service-components', [])):

                                if r_name not in component_list[component_mnemonic][cp_name]:
                                    component_list[component_mnemonic][cp_name][r_name] = []
                                host_list = component_list[component_mnemonic][cp_name][r_name]

                                for server in resources['servers']:
                                    host_list.append(server['hostname'])

            for component_name in sorted(component_list):
                component_data = component_list[component_name]
                f.write("[%s:children]\n" % (component_name))
                for cp_name in sorted(component_data):
                    f.write("%s-%s\n" % (component_name, cp_name))
                f.write("\n")

                for cp_name in sorted(component_data):
                    f.write("[%s-%s:children]\n" % (component_name, cp_name))
                    cluster_data = component_data[cp_name]
                    for cluster in sorted(cluster_data):
                        f.write("%s-%s-%s\n" % (component_name, cp_name, cluster))
                    f.write("\n")

                    for cluster in sorted(cluster_data):
                        f.write("[%s-%s-%s:children]\n" % (component_name, cp_name, cluster))
                        hosts = cluster_data[cluster]
                        for host in sorted(hosts):
                            f.write("%s\n" % host)
                        f.write("\n")

            # Build list of server groups
            for sg_name, sg in server_groups.iteritems():
                f.write("[%s:children]\n" % (sg_name))
                for child in sg.get('server-groups', []):
                    f.write("%s\n" % child)
                for server in sg.get('servers', []):
                    if server['state'] == ServerState.ALLOCATED:
                        f.write("%s\n" % server['hostname'])
                f.write("\n")
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        filename = "%s/group_vars/all" % (self._file_path)
        if not os.path.exists(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))
        self.add_artifact(filename, ArtifactMode.CREATED)

        global_vars = {'global': {'ansible_vars': [], 'all_servers': []}}
        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')
        service_view = CloudModel.get(self._cloud_internal, 'service_view')
        service_view = service_view['by_region']
        servers = CloudModel.get(self._cloud_internal, 'servers')
        ring_specifications = CloudModel.get(self._cloud_internal,
                                             'ring-specifications', [])
        pass_through = CloudModel.get(self._cloud_internal, 'pass_through')
        cloud_name = CloudDescription.get_cloud_name(self.cloud_desc)
        ntp_servers = self.cloud_desc['ntp-servers']

        if ntp_servers:
            global_vars['global']['ntp_servers'] = ntp_servers

        #
        # Add a list of all vips
        #
        vips = set()
        for cp_name, cp in control_planes.iteritems():
            for ep_name, ep_data in cp['endpoints'].iteritems():
                for role, role_data in ep_data.iteritems():
                    if role not in ['internal', 'admin']:
                        continue
                    for data in role_data:
                        access = data.get('access', {})
                        if 'hostname' in access:
                            vips.add(data['access']['hostname'])
                        for host_data in access.get('members', []):
                            vips.add(host_data['hostname'])

        if ring_specifications:
            ring_specifications = DataTransformer(
                ring_specifications).all_output('-', '_')
            global_vars['global']['all_ring_specifications'] =\
                ring_specifications
        else:
            global_vars['global']['all_ring_specifications'] = []

        if pass_through:
            global_vars['global']['pass_through'] = pass_through['global']

        global_vars['global']['vips'] = sorted(vips)

        global_vars['topology'] = {
            'cloud_name': cloud_name,
            'control_planes': []
        }
        for cp_name in sorted(service_view):
            cp = service_view[cp_name]
            cp_data = {'name': cp_name, 'services': []}
            for service_name in sorted(cp):
                components = cp[service_name]
                service_data = {'name': service_name, 'components': []}

                for component_name in sorted(components):
                    hosts = components[component_name]
                    component_data = {
                        'name': component_name,
                        'hosts': sorted(hosts)
                    }
                    service_data['components'].append(component_data)

                cp_data['services'].append(service_data)

            global_vars['topology']['control_planes'].append(cp_data)

        #
        # Include disk details of all servers for Swift
        #
        for server in servers:
            if server['state'] == ServerState.ALLOCATED:
                disk_model_out = DataTransformer(
                    server['disk-model']).all_output('-', '_')
                server_info = {
                    'name': server['hostname'],
                    'rack': server.get('rack', None),
                    'region': server.get('region', None),
                    'disk_model': disk_model_out
                }
                global_vars['global']['all_servers'].append(server_info)

                network_names = []
                for if_name, if_data in server['interfaces'].iteritems():
                    for net_name, net_data in if_data['networks'].iteritems():
                        if 'hostname' in net_data:
                            network_names.append(net_data['hostname'])
                server_info['network_names'] = network_names

        with open(filename, 'w') as fp:
            yaml.dump(global_vars, fp, default_flow_style=False, indent=4)