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 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 sorted(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 _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, 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(InternalModelGenerator, self).__init__(2.0, instructions, models, controllers, 'internal-model-2.0') LOG.info('%s()' % KenLog.fcn()) self.cloud_desc = self._models['CloudDescription']['cloud']
def __init__(self, instructions, models, controllers): super(NetworkTagGenerator, self).__init__(2.0, instructions, models, controllers, 'network-tag-generator-2.0') LOG.info('%s()' % KenLog.fcn()) self.cloud_desc = self._models['CloudDescription']['cloud']
def generate(self): LOG.info('%s()' % KenLog.fcn()) self._action = KenLog.fcn() cloud_internal = CloudModel.internal(self._models['CloudModel']) self.services = CloudModel.get(cloud_internal, 'services', []) control_planes = CloudModel.get(cloud_internal, 'control-planes') components = CloudModel.get(cloud_internal, 'components') # Resolve the service data relationships. for cp_name, cp in control_planes.iteritems(): for comp_name, comp_data in cp.get('components', []).iteritems(): provider = components[comp_name] provider_service = self.services.get(provider['service'], {}) self._set_provided_data(provider, provider_service, comp_data, cp, control_planes)
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 self._ipsets = {} self._ip_version = 0 LOG.info('%s()' % KenLog.fcn())
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 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 validate(self): LOG.info('%s()' % KenLog.fcn()) version = float(self.version()) input = self._create_content(version, "nic-device-families") # Nic device families are optional if not input: return True self._valid = self.validate_schema(input, "nic_device_family") if self._valid: nic_dev_families = input['nic-device-families'] self._validate_names(nic_dev_families) 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: components = self._get_dict_from_config_value( version, 'service-components') network_groups = input['network-groups'] self._validate_names(network_groups) self._validate_unique_hash_prefix(network_groups) self._validate_components(network_groups, components) LOG.info('%s()' % KenLog.fcn()) return self._valid
def migrate(self, model_name, model): LOG.info('%s()' % KenLog.fcn()) print('Migrating the "%s" model with the "%s" migrator...' % (model_name, self._slug)) if 'ring-specifications' in model['2.0']: self._migrate_ring_to_config(model) return model
def _generate_default_network_mtu(self, network_groups): LOG.info('%s()' % KenLog.fcn()) for net_group in network_groups.values(): explicit_mtu = 'mtu' in net_group mtu = net_group.get('mtu', DEFAULT_MTU) for net in net_group.get('networks', []): net['mtu'] = mtu net['explicit_mtu'] = explicit_mtu
def generate(self): LOG.info('%s()' % KenLog.fcn()) self._action = KenLog.fcn() cloud_version = CloudModel.version(self._models['CloudModel'], self._version) cloud_internal = CloudModel.internal(self._models['CloudModel']) networks = {} network_groups = {} for group in CloudModel.get(cloud_version, 'network-groups'): network_groups[group['name']] = group network_groups[group['name']]['networks'] = [] for net in CloudModel.get(cloud_version, 'networks'): networks[net['name']] = net # add networks into their respective network groups for net_name, net in networks.iteritems(): if net.get('network-group', None): network_groups[net['network-group']]['networks'].append(net) # Inject a network group for each provider network, so we can support # routes to them for config_data in CloudModel.get(cloud_version, 'configuration-data', []): if 'neutron' in config_data.get('services', []): for net in config_data.get('data', {}).get('neutron_provider_networks', []): provider_net = { 'name': net['name'], 'cidr': net['cidr'], 'network-group': net['name'], 'neutron_network': True } group = {'name': net['name'], 'networks': [provider_net]} networks[net['name']] = provider_net network_groups[net['name']] = group self._generate_default_network_mtu(network_groups) CloudModel.put(cloud_internal, 'networks', networks) CloudModel.put(cloud_internal, 'network-groups', network_groups)
def generate(self): LOG.info('%s()' % KenLog.fcn()) cloud_internal = CloudModel.internal(self._models['CloudModel']) # Control Planes control_planes = CloudModel.get(cloud_internal, 'control-planes') # Network Groups network_groups = CloudModel.get(cloud_internal, 'network-groups') # components components = CloudModel.get(cloud_internal, 'components') # services services = CloudModel.get(cloud_internal, 'services') # # Find which tags have been deprecated or replaced # replaced_tags = {} deprecated_tags = {} for component_name, component in components.iteritems(): for comp_tag in component.get('network-tags', []): for alias in comp_tag.get('aliases', []): replaced_tags[alias] = comp_tag['name'] if 'deprecated' in comp_tag: deprecated_tags[comp_tag['name']] = comp_tag['deprecated'] # In previous versions of Ardana OpenStack, any tags defined on a network group are # treated as applying to all control planes netgroup_tags = self._get_netgroup_tags(network_groups) # Process the tags for each cluster / resource group tag_found = {} for cp_name, cp in control_planes.iteritems(): cp_components = set() for cluster in cp['clusters']: for comp_name in cluster['service-components']: cp_components.add(comp_name) for r in cp.get('resources', []): for comp_name in r['service-components']: cp_components.add(comp_name) cp['network-tags'] = self._process_network_tags( cp['config-data-network-tags'], netgroup_tags, cp_components, components, services, replaced_tags, deprecated_tags, tag_found) self._validate_network_tags(cp_name, cp['network-tags'], cp['neutron-provider-nets']) for tag_name, found in tag_found.iteritems(): if not found: msg = ("Tag '%s' is not defined by any service" % tag_name) self.add_warning(msg)
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 __init__(self, instructions): LOG.info('%s()' % KenLog.fcn()) self._instructions = instructions self.prefix = 'ans' self.suffix = '.pw' self._temp_files = [] self._pw_file = self._create_temp_file() self._create_password_file() self._temp_files.append(self._pw_file[1])
def validate(self): LOG.info('%s()' % KenLog.fcn()) version = float(self.version()) input = self._create_content(version, "control-planes") if input: valid = self.validate_schema(input, "control-plane") if valid: self._check_for_unique_cp_names(input['control-planes']) components = self._get_dict_from_config_value(version, 'service-components') components_by_mnemonic = {} for c_name, c_data in components.iteritems(): components_by_mnemonic[c_data['mnemonic']] = c_data configuration_data = self._get_config_value(version, 'configuration-data') if not configuration_data: configuration_data = [] regions = self._get_config_value(version, 'regions') if not regions: regions = [] self._check_regions(regions, input['control-planes']) for cp in input['control-planes']: self._check_deprecations(cp) self._expand_components(cp) self._add_required_components(cp, components) self._check_and_expand_regions(cp, regions, components) self._check_for_unique_names(cp) self._check_allocation_policy(cp) self._check_components(cp, components) self._check_containers(cp, components, components_by_mnemonic) self._check_warnings(cp, components) self._check_configuration_data(cp, configuration_data, components) self._check_only_one_instance(input['control-planes'], components) self._check_uses_from(input['control-planes'], components) LOG.info('%s()' % KenLog.fcn()) return valid
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
def __init__(self, instructions, models, controllers): super(PrivateDataMetaDataBuilder, self).__init__(2.0, instructions, models, controllers, 'private-data-meta-data-2.0') LOG.info('%s()' % KenLog.fcn()) self.cloud_desc = self._models['CloudDescription']['cloud'] self._file_path = ArdanaPaths.get_output_path(self._instructions, self.cloud_desc) self._version = self._instructions['model_version'] self._version = Version.normalize(self._version) self._meta_data = {}
def build(self): LOG.info('%s()' % KenLog.fcn()) control_planes = CloudModel.get(self._cloud_internal, 'control-planes') for cp_name, cp in control_planes.iteritems(): cert_data = cp['lb-cert-data'] for lb_provider, certs in cert_data.iteritems(): for cert_name, cert_details in certs.iteritems(): self._write_cert_req_info(cert_name, cert_details)
def explain(self): LOG.info('%s()' % KenLog.fcn()) fp = self._get_explainer_file() message = self._get_title() message += self._get_overrides() fp.write('%s' % message) self._close_explainer_file(fp)
def validate(self): LOG.info('%s()' % KenLog.fcn()) version = float(self.version()) input = self._create_content(version, "regions") if input: self._valid = self.validate_schema(input, "region") if self._valid: regions = input['regions'] # Map each component to its service services = self._get_dict_from_config_value(version, 'services') self._check_names(regions) for region in regions: self._check_services(region, services) 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 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
def build(self): LOG.info('%s()' % KenLog.fcn()) self._remove_cp_None() self._check_persistent_state_consistency() if len(self._errors) > 0: return len(self._errors) == 0 self._update_old_private_data() self._load_password_change() self._remove_non_scoped_private_data() self._load_cloud_variable_names() self._write_password_change() self._write_persistent_state()
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 __init__(self, instructions, models, controllers): super(SequenceNumberVariable, self).__init__(2.0, instructions, models, controllers, 'sequence-number-2.0') self._models = models if 'variables' not in self._models: self._models['variables'] = {} if 'sequence-number-2.0' not in self._models['variables']: self._models['variables']['sequence-number-2.0'] = {} self._current_value = self._models['variables']['sequence-number-2.0'] LOG.info('%s()' % KenLog.fcn())