def generate(self):
        LOG.info('%s()' % KenLog.fcn())

        self._action = KenLog.fcn()
        cloud_internal = CloudModel.internal(self._models['CloudModel'])

        control_planes = CloudModel.get(cloud_internal, 'control-planes', {})
        # If we have an error in an earlier generator we may not have
        # control_planes in the internal model
        if not control_planes:
            return

        routes = {}
        for cp_name, cp in control_planes.iteritems():

            load_balancers = cp.get('load-balancers', {})

            for cluster in cp['clusters']:
                for server in cluster.get('servers', []):
                    self._add_routes_from_server(cp, server, load_balancers,
                                                 routes)

            for r_name, r in cp.get('resources', {}).iteritems():
                for server in r.get('servers', []):
                    self._add_routes_from_server(cp, server, load_balancers,
                                                 routes)

        #
        default_routes = {}
        # Warn about any routes using the "default" route
        for src_net, net_routes in routes.iteritems():
            for dest_net, route_data in net_routes.iteritems():
                if route_data['default']:
                    hosts = set()
                    if src_net not in default_routes:
                        default_routes[src_net] = []
                    for src, src_data in route_data['used_by'].iteritems():
                        for dest, host_list in src_data.iteritems():
                            for host in host_list:
                                hosts.add(host)
                    default_routes[src_net].append({
                        'net': dest_net,
                        'hosts': hosts
                    })

        if default_routes:
            msg = (
                "Default routing used between networks\n"
                "The following networks are using a 'default' route rule. To remove this warning\n"
                "either add an explict route in the source network group or force the network to\n"
                "attach in the interface model used by the servers.\n")
            for src in sorted(default_routes):
                dest_list = default_routes[src]
                for dest_data in dest_list:
                    msg += "  %s to %s\n" % (src, dest_data['net'])
                    for host in sorted(dest_data['hosts']):
                        msg += "    %s\n" % (host)
            self.add_warning(msg)

        CloudModel.put(cloud_internal, 'routes', routes)
    def _calculate(self):
        LOG.info('%s()' % KenLog.fcn())

        value = self._current_value
        self._current_value += 1
        LOG.debug('%s() -> %s' % (KenLog.fcn(), value))
        return value
    def validate(self):
        LOG.info("%s()" % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "servers")
        schema_valid = self.validate_schema(input, "server")
        if schema_valid:
            servers = input.get("servers", [])
            baremetal = {}
            try:
                baremetal = self._create_content(version, "baremetal")["baremetal"][0]
            except TypeError:
                try:
                    # baremetal_networks is still suppoted for backwards compatibility
                    baremetal = self._create_content(version, "baremetal_network")["baremetal_network"][0]
                except TypeError:
                    # Possible to have servers with no baremetal section if not using
                    # cobbler to deploy
                    pass

            nic_mappings = self._get_dict_from_config_value(version, "nic-mappings")
            iface_models = self._get_dict_from_config_value(version, "interface-models")
            server_roles = self._get_dict_from_config_value(version, "server-roles")
            server_groups = self._get_dict_from_config_value(version, "server-groups")

            if baremetal:
                self._validate_baremetal_net(baremetal)
            self._validate_unique_ids(servers)
            self._validate_ip_addresses(servers)
            self._validate_mac_addresses(servers)
            self._validate_server_groups(servers, server_groups)
            self._validate_net_devices(servers, nic_mappings, server_roles, iface_models)

        LOG.info("%s()" % KenLog.fcn())
        return self._valid
Пример #4
0
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "servers")
        schema_valid = self.validate_schema(input, "server")
        if schema_valid:
            servers = input.get('servers', [])
            baremetal = {}
            try:
                baremetal = self._create_content(version, 'baremetal')['baremetal'][0]
            except TypeError:
                try:
                    # baremetal_networks is still suppoted for backwards compatibility
                    baremetal = self._create_content(version, 'baremetal_network')['baremetal_network'][0]
                except TypeError:
                    # Possible to have servers with no baremetal section if not using
                    # cobbler to deploy
                    pass

            nic_mappings = self._get_dict_from_config_value(version, 'nic-mappings')
            iface_models = self._get_dict_from_config_value(version, 'interface-models')
            server_roles = self._get_dict_from_config_value(version, 'server-roles')
            server_groups = self._get_dict_from_config_value(version, 'server-groups')

            if baremetal:
                self._validate_baremetal_net(baremetal)
            self._validate_unique_ids(servers)
            self._validate_ip_addresses(servers)
            self._validate_mac_addresses(servers)
            self._validate_server_groups(servers, server_groups)
            self._validate_net_devices(servers, nic_mappings, server_roles, iface_models)

        LOG.info('%s()' % KenLog.fcn())
        return self._valid
Пример #5
0
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "pass-through")
        if input:
            return self.validate_schema(input, "pass_through")
        LOG.info('%s()' % KenLog.fcn())
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "pass-through")
        if input:
            return self.validate_schema(input, "pass_through")
        LOG.info('%s()' % KenLog.fcn())
Пример #7
0
 def _generate_ring_specifications_info(self):
     LOG.info('%s()' % KenLog.fcn())
     self._action = KenLog.fcn()
     cloud_version = CloudModel.version(self._models['CloudModel'],
                                        self._version)
     ring_specifications_config = CloudModel.get(cloud_version,
                                                 'ring-specifications', [])
     cloud_internal = CloudModel.internal(self._models['CloudModel'])
     CloudModel.put(cloud_internal, 'ring-specifications',
                    ring_specifications_config)
 def _generate_ring_specifications_info(self):
     LOG.info('%s()' % KenLog.fcn())
     self._action = KenLog.fcn()
     cloud_version = CloudModel.version(
         self._models['CloudModel'], self._version)
     ring_specifications_config = CloudModel.get(
         cloud_version, 'ring-specifications', [])
     cloud_internal = CloudModel.internal(self._models['CloudModel'])
     CloudModel.put(cloud_internal,
                    'ring-specifications',
                    ring_specifications_config)
    def generate(self):
        LOG.info('%s()' % KenLog.fcn())

        self._action = KenLog.fcn()
        cloud_internal = CloudModel.internal(self._models['CloudModel'])

        control_planes = CloudModel.get(cloud_internal, 'control-planes', {})
        # If we have an error in an earlier generator we may not have
        # control_planes in the internal model
        if not control_planes:
            return

        routes = {}
        for cp_name, cp in control_planes.iteritems():

            load_balancers = cp.get('load-balancers', {})

            for cluster in cp['clusters']:
                for server in cluster.get('servers', []):
                    self._add_routes_from_server(cp, server, load_balancers, routes)

            for r_name, r in cp.get('resources', {}).iteritems():
                for server in r.get('servers', []):
                    self._add_routes_from_server(cp, server, load_balancers, routes)

        #
        default_routes = {}
        # Warn about any routes using the "default" route
        for src_net, net_routes in routes.iteritems():
            for dest_net, route_data in net_routes.iteritems():
                if route_data['default']:
                    hosts = set()
                    if src_net not in default_routes:
                        default_routes[src_net] = []
                    for src, src_data in route_data['used_by'].iteritems():
                        for dest, host_list in src_data.iteritems():
                            for host in host_list:
                                hosts.add(host)
                    default_routes[src_net].append({'net': dest_net, 'hosts': hosts})

        if default_routes:
            msg = ("Default routing used between networks\n"
                   "The following networks are using a 'default' route rule. To remove this warning\n"
                   "either add an explict route in the source network group or force the network to\n"
                   "attach in the interface model used by the servers.\n")
            for src in sorted(default_routes):
                dest_list = default_routes[src]
                for dest_data in dest_list:
                    msg += "  %s to %s\n" % (src, dest_data['net'])
                    for host in sorted(dest_data['hosts']):
                        msg += "    %s\n" % (host)
            self.add_warning(msg)

        CloudModel.put(cloud_internal, 'routes', routes)
    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)
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        servers = CloudModel.get(self._cloud_internal, 'servers')
        server_info = {}

        for server in servers:
            server_info[server['id']] = {}
            data = server_info[server['id']]
            data['state'] = server['state']

            if server['state'] == ServerState.ALLOCATED:

                data['hostname'] = server['hostname']
                data['failure-zone'] = server['failure-zone']

                net_info = {}
                for if_name, if_data in server['interfaces'].iteritems():
                    net_info[if_name] = {}
                    for net_name, net_data in if_data['networks'].iteritems():
                        net_info[if_name][net_name] = \
                            {'addr': net_data.get('addr'),
                             'vlan-id': net_data.get('vlanid'),
                             'tagged-vlan': net_data.get('tagged-vlan', True)}
                data['net_data'] = net_info

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

        with open(filename, 'w') as fp:
            yaml.dump(server_info, fp, default_flow_style=False, indent=4)
Пример #12
0
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        if 'encryption_key' in self._instructions:
            path = self._instructions['cloud_input_path']
            status, messages = CPSecurity.validate(
                path, self._instructions['encryption_key'])

            if not status:
                message = 'The Encryption Key does not meet the following ' \
                          'requirement(s):\n#       %s' % \
                          '\n#       '.join(messages)
                self.add_error(message)
                return False

            score, msg = CPSecurity.calculate_complexity(
                self._instructions['encryption_key'])

            print('\n\nThe encryption key has a complexity score of %d ('
                  '%s)\n\n' % (score, msg))

        if ('previous_encryption_key' in self._instructions
                and 'encryption_key' in self._instructions):
            if (self._instructions['encryption_key'] ==
                    self._instructions['previous_encryption_key']):
                message = 'The New Encryption Key and the Previous ' \
                          'Encryption Key must be different.'
                self.add_error(message)
                return False

        return True
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        if 'encryption_key' in self._instructions:
            path = self._instructions['cloud_input_path']
            status, messages = CPSecurity.validate(
                path, self._instructions['encryption_key'])

            if not status:
                message = 'The Encryption Key does not meet the following ' \
                          'requirement(s):\n#       %s' % \
                          '\n#       '.join(messages)
                self.add_error(message)
                return False

            score, msg = CPSecurity.calculate_complexity(
                self._instructions['encryption_key'])

            print('\n\nThe encryption key has a complexity score of %d ('
                  '%s)\n\n' % (score, msg))

        if ('previous_encryption_key' in self._instructions and
                'encryption_key' in self._instructions):
            if (self._instructions['encryption_key'] ==
                    self._instructions['previous_encryption_key']):
                message = 'The New Encryption Key and the Previous ' \
                          'Encryption Key must be different.'
                self.add_error(message)
                return False

        return True
    def finalize(self):
        LOG.info('%s()' % KenLog.fcn())

        allocated_addresses = CloudModel.get(self._cloud_internal,
                                             'address_allocations', {})
        host_aliases = CloudModel.get(self._cloud_internal, 'host_aliases', {})

        address_data = {}
        for group_name, group in allocated_addresses.iteritems():
            if group_name not in address_data:
                address_data[group_name] = {}
            for network_name, network in group.iteritems():
                if network_name not in address_data[group_name]:
                    address_data[group_name][network_name] = {}
                for addr in sorted(network):
                    aliases = host_aliases.get(group_name, {}).get(
                        network_name, {}).get(addr, [])
                    address_data[group_name][network_name][addr] = []
                    for name in aliases:
                        address_data[group_name][network_name][addr].append(name)

        filename = os.path.join(self._file_path, 'address_info.yml')
        self.add_artifact(filename, ArtifactMode.CREATED)
        with open(filename, 'w') as fp:
            yaml.dump(address_data, fp, default_flow_style=False, indent=4)
    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]))
Пример #16
0
    def _determine_size_for_control_plane(self, elem_cp):
        LOG.info('%s(elem_cp="%s")' % (
            KenLog.fcn(), ControlPlane.get_name(elem_cp)))

        width = 0
        height = self._padding_y

        for elem_t in elem_cp['tiers']:
            if not Tier.is_active_or_empty(elem_t):
                continue

            (t_w, t_h) = self._determine_size_for_tier(elem_cp, elem_t)

            if t_w > width:
                width = t_w

            height += t_h

        width += (self._padding_x * 2)
        height += (self._padding_y * 2)

        height += self._determine_height_for_resource_nodes(elem_cp)
        height += self._determine_height_for_cp_networks(elem_cp)

        return width, height
    def __init__(self, instructions, models, controllers):
        super(RandomPasswordVariable, self).__init__(
            2.0, instructions, models, controllers,
            'random-password-2.0')
        LOG.info('%s()' % KenLog.fcn())

        random.seed()
    def __init__(self, instructions, models, controllers):
        super(RandomPasswordVariable,
              self).__init__(2.0, instructions, models, controllers,
                             'random-password-2.0')
        LOG.info('%s()' % KenLog.fcn())

        random.seed()
Пример #19
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)
Пример #20
0
    def _determine_height_for_cp_networks(self, elem_cp):
        LOG.info('%s()' % KenLog.fcn())

        height = 0

        interfaces = dict()

        nt = elem_cp['network-topology']

        for k, v in six.iteritems(nt):
            (intf, vlan_tag) = self._get_interface_info(elem_cp['type'], k)
            index = '%s-%s' % (intf, vlan_tag)

            if index not in interfaces:
                interfaces[index] = dict()
                interfaces[index]['interface'] = intf
                interfaces[index]['vlan-tag'] = vlan_tag
                interfaces[index]['mnemonics'] = []

            if k not in interfaces[index]['mnemonics']:
                interfaces[index]['mnemonics'].append(k)

        for k, v in six.iteritems(interfaces):
            height += self._determine_height_for_cp_interface(v)
            height += 1  # Separation

        return height
 def __init__(self, instructions, config_files):
     super(NetworksValidator, self).__init__(
         2.0, instructions, config_files,
         'networks-2.0')
     self._valid = False
     self._valid_cidr = True
     LOG.info('%s()' % KenLog.fcn())
Пример #22
0
    def _determine_height_for_cp_interface(self, intf):
        LOG.info('%s()' % KenLog.fcn())

        height = self._padding_y
        height += len(intf['mnemonics'])
        height += self._padding_y

        return height
    def __init__(self, instructions, models, controllers):
        super(SequenceNumberVariable,
              self).__init__(2.0, instructions, models, controllers,
                             'sequence-number-2.0')

        self._current_value = None

        LOG.info('%s()' % KenLog.fcn())
    def checkpoint(self):
        LOG.info('%s()' % KenLog.fcn())

        path = self._instructions['cloud_input_path']
        cloud_name, nickname = CloudNameController.get_cloud_names(path)
        self.prepare_filesystem(cloud_name, 'config')

        return self._checkpoint()
    def checkpoint(self):
        LOG.info('%s()' % KenLog.fcn())

        path = self._instructions['cloud_input_path']
        cloud_name, nickname = CloudNameController.get_cloud_names(path)
        self.prepare_filesystem(cloud_name, 'persistent_state')

        return self._checkpoint()
Пример #26
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)
Пример #27
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        file_name = '%s/CloudDiagram.txt' % self._file_path
        self.add_artifact(file_name, ArtifactMode.CREATED)
        fp = open(file_name, 'w')

        self._render_control_planes(fp)

        fp.close()
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, 'ring-specifications')
        if input:
            return self.validate_schema(input, 'ring_specifications')
        else:
            return True
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, 'ring-specifications')
        if input:
            return self.validate_schema(input, 'ring_specifications')
        else:
            return True
Пример #30
0
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, "network-groups")
        self._valid = self.validate_schema(input, "network_group")
        if self._valid:
            network_groups = input['network-groups']
            self._validate_names(network_groups)
            self._validate_lb_roles(network_groups)
            self._validate_lb_external_name(network_groups)
            self._validate_provider_physnet_given(network_groups)
            self._validate_provider_physnet_same_in_netgroup(network_groups)
            self._validate_physnet_unique_among_netgroups(network_groups)
            self._validate_vlan_ranges_in_tags(network_groups)
            self._validate_vxlan_ranges_in_tags(network_groups)
        LOG.info('%s()' % KenLog.fcn())
        return self._valid
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, "network-groups")
        self._valid = self.validate_schema(input, "network_group")
        if self._valid:
            network_groups = input['network-groups']
            self._validate_names(network_groups)
            self._validate_lb_roles(network_groups)
            self._validate_lb_external_name(network_groups)
            self._validate_provider_physnet_given(network_groups)
            self._validate_provider_physnet_same_in_netgroup(network_groups)
            self._validate_physnet_unique_among_netgroups(network_groups)
            self._validate_vlan_ranges_in_tags(network_groups)
            self._validate_vxlan_ranges_in_tags(network_groups)
        LOG.info('%s()' % KenLog.fcn())
        return self._valid
    def validate(self):
        LOG.info("%s()" % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, "nic-mappings")
        # Nic mappings are optional
        if not input:
            return True

        self._valid = self.validate_schema(input, "nic_mapping")
        if self._valid:
            nic_mappings = input["nic-mappings"]
            self._validate_names(nic_mappings)
            for mapping in nic_mappings:
                self._validate_logical_names_and_addresses(mapping)

        LOG.info("%s()" % KenLog.fcn())
        return self._valid
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        file_name = '%s/CloudDiagram.txt' % self._file_path
        self.add_artifact(file_name, ArtifactMode.CREATED)
        fp = open(file_name, 'w')

        self._render_control_planes(fp)

        fp.close()
    def finalize(self):
        LOG.info('%s()' % KenLog.fcn())

        service_view = CloudModel.get(self._cloud_internal, 'service_view', {})

        filename = os.path.join(self._file_path, 'service_info.yml')
        self.add_artifact(filename, ArtifactMode.CREATED)

        with open(filename, 'w') as fp:
            yaml.dump(service_view.get('by_region', {}), fp, default_flow_style=False, indent=4)
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, "nic-mappings")
        # Nic mappings are optional
        if not input:
            return True

        self._valid = self.validate_schema(input, "nic_mapping")
        if self._valid:
            nic_mappings = input['nic-mappings']
            self._validate_names(nic_mappings)
            for mapping in nic_mappings:
                self._validate_logical_names_and_addresses(mapping)

        LOG.info('%s()' % KenLog.fcn())
        return self._valid
    def __init__(self, instructions, models, controllers):
        super(AnsEncryptArtifactsBuilder, self).__init__(
            1, instructions, models, controllers,
            'ans-encr-artifacts')

        LOG.info('%s()' % KenLog.fcn())

        cloud_config = controllers['CloudConfig']
        self._output_path = '%s/ansible' % cloud_config.get_output_path(models)
        self._modules = ['group_vars', 'host_vars']
        self._pw_file = tempfile.mkstemp(suffix='.pw', prefix='ans', text=True)
    def explain(self):
        LOG.info('%s()' % KenLog.fcn())

        fp = self._get_explainer_file()

        message = self._get_title()
        message += self._get_services()

        fp.write('%s' % message)

        self._close_explainer_file(fp)
    def __init__(self, instructions, models, controllers):
        super(AnsEncryptArtifactsBuilder,
              self).__init__(1, instructions, models, controllers,
                             'ans-encr-artifacts')

        LOG.info('%s()' % KenLog.fcn())

        cloud_config = controllers['CloudConfig']
        self._output_path = '%s/ansible' % cloud_config.get_output_path(models)
        self._modules = ['group_vars', 'host_vars']
        self._pw_file = tempfile.mkstemp(suffix='.pw', prefix='ans', text=True)
Пример #39
0
    def _get_interface_info(self, cp_type, mnemonic):
        LOG.info('%s()' % KenLog.fcn())

        (intf, vlan_tag) = self._get_interface_info_for_network(
            cp_type, mnemonic)

        if not intf or not vlan_tag:
            (intf, vlan_tag) = self._get_interface_info_for_network(
                'GLOBAL', mnemonic)

        return intf, vlan_tag
Пример #40
0
    def migrate(self, model_name, model):
        LOG.info('%s()' % KenLog.fcn())
        print('Migrating the "%s" model with the "%s" migrator...' %
              (model_name, self._slug))

        for cp in model['2.0']['control-planes']:
            if 'resource-nodes' in cp:
                cp['resources'] = cp['resource-nodes']
                del cp['resource-nodes']

        return model
Пример #41
0
    def __init__(self, instructions, models, controllers):
        super(DiagramBuilder, self).__init__(
            1, instructions, models, controllers,
            'diagram')

        LOG.info('%s()' % KenLog.fcn())

        self._padding_x = 2
        self._padding_y = 2
        self._member_width = 50
        self._line_width = 136
    def explain(self):
        LOG.info('%s()' % KenLog.fcn())

        fp = self._get_explainer_file()

        message = self._get_title()
        message += self._get_networks()

        fp.write('%s' % message)

        self._close_explainer_file(fp)
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        control_planes = CloudModel.get(self._cloud_internal, 'control-planes')

        net_info = {}

        # Service IPs
        for cp_name, cp in control_planes.iteritems():
            for cluster in cp['clusters']:
                if 'service-ips' in cluster:
                    if 'service_ips' not in net_info:
                        net_info['service_ips'] = {}

                    for name, net_data in cluster['service-ips'].iteritems():
                        if name not in net_info['service_ips']:
                            net_info['service_ips'][name] = []
                        for net_name, data in net_data.iteritems():
                            info = {
                                'control_plane': cp_name,
                                'cluster': cluster['name'],
                                'network': net_name,
                                'hosts': data.get('hosts', []),
                                'cluster_ip': data.get('cluster-ip', {})
                            }
                        net_info['service_ips'][name].append(info)

            if 'resources' in cp:
                for res_name, resources in cp['resources'].iteritems():
                    if 'service-ips' in resources:
                        if 'service_ips' not in net_info:
                            net_info['service_ips'] = {}

                        for name, net_data in resources[
                                'service-ips'].iteritems():
                            if name not in net_info['service_ips']:
                                net_info['service_ips'][name] = []
                            for net_name, data in net_data.iteritems():
                                info = {
                                    'control_plane': cp_name,
                                    'cluster': res_name,
                                    'network': net_name,
                                    'hosts': data.get('hosts', []),
                                    'cluster_ip': data.get('cluster-ip', {})
                                }
                                net_info['service_ips'][name].append(info)

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

        with open(filename, 'w') as fp:
            yaml.dump(net_info, fp, default_flow_style=False, indent=4)
    def migrate(self, model_name, model):
        LOG.info('%s()' % KenLog.fcn())
        print('Migrating the "%s" model with the "%s" migrator...' % (
            model_name, self._slug))

        for cp in model['2.0']['control-planes']:
            if 'resource-nodes' in cp:
                cp['resources'] = cp['resource-nodes']
                del cp['resource-nodes']

        return model
Пример #45
0
    def generate(self):
        LOG.info('%s()' % KenLog.fcn())

        self._action = KenLog.fcn()
        cloud_internal = CloudModel.internal(self._models['CloudModel'])

        components = CloudModel.get(cloud_internal, 'components', [])
        # If we have an error in an earlier generator we may not have
        # components in the internal model
        if not components:
            return
        components_by_mnemonic = CloudModel.get(cloud_internal, 'components_by_mnemonic')
        control_planes = CloudModel.get(cloud_internal, 'control-planes')

        for cp_name, cp in control_planes.iteritems():
            for comp_name, comp_data in cp.get('components', []).iteritems():
                comp_data['consumes'] = self._get_consumes(comp_name,
                                                           components,
                                                           components_by_mnemonic,
                                                           cp)
    def validate(self):
        LOG.info("%s()" % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "networks")
        self._valid = self.validate_schema(input, "network")

        if self._valid:
            networks = input.get("networks", [])
            self._validate_names(networks)
            for net in networks:
                self._validate_vlans(net)
                self._validate_cidr(net)
                self._validate_vxlan_net_has_cidr(net)
            if self._valid_cidr:
                self._validate_no_cidr_overlap(networks)
            self._validate_gateways(networks)

        LOG.info("%s()" % KenLog.fcn())
        return self._valid
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())
        version = float(self.version())

        input = self._create_content(version, "networks")
        self._valid = self.validate_schema(input, "network")

        if self._valid:
            networks = input.get('networks', [])
            self._validate_names(networks)
            for net in networks:
                self._validate_vlans(net)
                self._validate_cidr(net)
                self._validate_vxlan_net_has_cidr(net)
            if self._valid_cidr:
                self._validate_no_cidr_overlap(networks)
            self._validate_gateways(networks)

        LOG.info('%s()' % KenLog.fcn())
        return self._valid
Пример #48
0
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        routes = CloudModel.get(self._cloud_internal, 'routes')

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

        with open(filename, 'w') as fp:
            yaml.dump(routes, fp, default_flow_style=False, indent=4)
    def migrate(self, model_name, model):
        LOG.info("%s()" % KenLog.fcn())
        return model
        print ('Migrating the "%s" model with the "%s" migrator...' % (model_name, self._slug))

        if model_name == "CloudArchitecture":
            return self._migrate_cloud_architecture(model)

        if model_name == "Regions":
            return self._migrate_regions(model)

        return model
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        firewall_settings = CloudModel.get(self._cloud_internal,
                                           'firewall_settings')
        print(firewall_settings)
        cloud_firewall = CloudModel.get(self._cloud_internal, 'cloud-firewall')

        # Convert from per server to per network
        firewall = {}
        for server_name, data in cloud_firewall.iteritems():
            for addr, rules in data.get('rules', {}).iteritems():
                for rule in rules:
                    net_group = rule['chain']
                    component = rule['component']
                    if net_group not in firewall:
                        firewall[net_group] = {}
                    min_port = rule['port-range-min']
                    max_port = rule['port-range-max']
                    if min_port == max_port:
                        port = str(min_port)
                    else:
                        port = "%s:%s" % (min_port, max_port)

                    if port not in firewall[net_group]:
                        firewall[net_group][port] = {
                            'port': port,
                            'protocol': rule['protocol'],
                            'components': [],
                            'addresses': []
                        }
                    if component not in firewall[net_group][port][
                            'components']:
                        firewall[net_group][port]['components'].append(
                            component)
                    if addr not in firewall[net_group][port]['addresses']:
                        firewall[net_group][port]['addresses'].append(addr)

        # rebuild  get a list with the ports sorted
        sorted_firewall = {}
        for net_grp, data in firewall.iteritems():
            sorted_firewall[net_grp] = []
            for port in sorted(data, key=lambda x: int(x.split(":")[0])):
                sorted_firewall[net_grp].append(data[port])

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

        with open(filename, 'w') as fp:
            yaml.dump(sorted_firewall, fp, default_flow_style=False, indent=4)
    def build(self):
        LOG.info('%s()' % KenLog.fcn())

        routes = CloudModel.get(self._cloud_internal, 'routes')

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

        with open(filename, 'w') as fp:
            yaml.dump(routes, fp, default_flow_style=False, indent=4)
    def validate(self):
        LOG.info('%s()' % KenLog.fcn())

        version = float(self.version())

        input = self._create_content(version, "server-roles")
        self._valid = self.validate_schema(input, "server_role")

        if self._valid:
            server_roles = input['server-roles']
            self._validate_names(server_roles)

        return self._valid