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 _get_services(self): svc_controller = self._controllers['Service'] message = '' cp_index = 1 for elem_cp in self._models['CloudModel']['control-planes']: if not ControlPlane.is_active(elem_cp): cp_index += 1 continue t_index = 1 for elem_t in elem_cp['tiers']: if not Tier.is_active(elem_t): t_index += 1 continue num_services = len(elem_t['members']['vip']['services']) message += 'In the %s tier of the %s control plane (%s), ' \ 'the following %s defined:\n' % \ (ordinal(t_index), ordinal(cp_index), elem_cp['type'], pluralize(num_services, 'service is', 'services are')) services = sorted(elem_t['members']['1']['services']) for elem_s in services: mnemonic = svc_controller.name_to_mnemonic(elem_s['name']) name = svc_controller.mnemonic_to_name(elem_s['name']) message += ' %s (%s)\n' % (mnemonic, name) message += '\n' if 'vip' in elem_t['members']: services = sorted(elem_t['members']['vip']['services']) num_services = len(services) message += ' with VIP access to %s:\n' % (pluralize( num_services, 'this service', 'these services')) for elem_s in services: mnemonic = svc_controller.name_to_mnemonic( elem_s['name']) name = svc_controller.mnemonic_to_name(elem_s['name']) message += ' %s (%s)\n' % (mnemonic, name) message += '\n' t_index += 1 cp_index += 1 return message
def is_resource_node_active(cloud_model, elem_s): control_planes = CloudModel.control_planes(cloud_model) control_plane = ResourceNode.get_control_plane_id(elem_s) node_type = ResourceNode.get_type(elem_s) for elem_cp in control_planes: cp_name = ControlPlane.get_name(elem_cp) if cp_name.lower() != control_plane.lower(): continue if not ResourceNode.is_active(elem_cp, node_type, elem_s): return False return True
def _determine_height_for_resource_nodes(self, elem_cp): LOG.info('%s(elem_cp="%s")' % (KenLog.fcn(), ControlPlane.get_name(elem_cp))) height = 0 for nt, elem_rn in six.iteritems(elem_cp['resource-nodes']): if not elem_rn: continue height += self._determine_height_for_resource_node( elem_cp, nt, elem_rn) if height: height += (self._padding_y * 2) height += 1 # Separation return height
def _determine_height_for_resource_node(self, elem_cp, node_type, elem_rn): LOG.info('%s(elem_cp="%s", node_type="%s", elem_rn="%s")' % (KenLog.fcn(), ControlPlane.get_name(elem_cp), node_type, ResourceNode.get_hostname(elem_rn))) num_rn_allocations = 0 allocations = self._get_resource_node_allocations(elem_cp, node_type) LOG.info('-------------------------------------') for k, v in six.iteritems(allocations): LOG.info(v) if 'start' in v and 'end' in v: num_rn_allocations += 1 LOG.info('------------------------------------- %d' % num_rn_allocations) height = self._padding_y height += len(ResourceNode.get_services(elem_rn)) height += 1 # Dashes height += num_rn_allocations height += self._padding_y return height
def _get_networks(self): svc_controller = self._controllers['Service'] message = '' networks = OrderedDict() for elem_cp in self._models['CloudModel']['control-planes']: if not ControlPlane.is_active(elem_cp): continue for elem_t in elem_cp['tiers']: if not Tier.is_active(elem_t): continue for elem_s in elem_t['services']: for elem_nr in elem_s['network_refs']: if elem_nr not in networks: networks[elem_nr] = [] if elem_s['name'] not in networks[elem_nr]: networks[elem_nr].append(elem_s['name']) for n, services in six.iteritems(networks): sservices = sorted(services) message += 'The following %s connected to the "%s" ' \ 'traffic group:\n' % ( pluralize(len(sservices), 'service ' 'is', 'services are'), n) for elem_s in sservices: mnemonic = svc_controller.name_to_mnemonic(elem_s) name = svc_controller.mnemonic_to_name(elem_s) message += ' %s (%s)\n' % (mnemonic, name) message += '\n and are accessed with the following:\n' for elem_cp in self._models['CloudModel']['control-planes']: if not ControlPlane.is_active(elem_cp): continue cp_type = ControlPlane.get_name(elem_cp) addresses = [] for nt, elem_nt in six.iteritems(elem_cp['network-topology']): if nt.lower() != n.lower(): continue for t, elem_t in six.iteritems(elem_nt): for m, elem_m in six.iteritems(elem_t): addr = cp_type if m.lower() == 'vip': addr += ' for VIP access on the ' \ '%s tier: ' % \ ordinal(int(t)) else: addr += ' on the '\ '%s member of the %s tier: ' % \ (ordinal(int(m)), ordinal(int(t))) addr += elem_m['ip-address'] addresses.append(addr) sorted_addresses = sorted(addresses) for elem_a in sorted_addresses: message += ' %s\n' % elem_a message += '\n' return message
def _get_structure(self): nt_controller = self._controllers['NodeType'] path = self._instructions['cloud_input_path'] name, nickname = CloudNameController.get_cloud_names(path) if nickname and (len(nickname) > 0): message = 'The "%s" cloud was created with a nickname of "%s" ' % ( name, nickname) else: message = 'The "%s" cloud was created with no nickname ' % name num_cp = len(self._models['CloudModel']['control-planes']) message += 'and "%d" defined control %s.\n\n' % \ (num_cp, pluralize(num_cp, 'plane', 'planes')) cp_index = 1 for elem_cp in self._models['CloudModel']['control-planes']: if not ControlPlane.is_active(elem_cp): continue cp_type = ControlPlane.get_name(elem_cp) num_tiers = ControlPlane.get_active_tier_count(elem_cp) str_tiers = pluralize(num_tiers, 'tier', 'tiers') message += 'The %s control plane is a "%s" (%s) and has "%d" ' \ '%s.\n' % (ordinal(cp_index), cp_type, elem_cp['type'], num_tiers, str_tiers) t_index = 1 for elem_t in elem_cp['tiers']: if not Tier.is_active(elem_t): continue mc = Tier.get_active_member_count(elem_t) if mc == 1: message += 'The %s tier in this control plane is not ' \ 'clustered.' % ordinal(t_index) else: message += 'The %s tier in this control plane is ' \ 'clustered, having "%s" %s in the cluster.' % \ (ordinal(t_index), mc, pluralize(mc, 'member', 'members')) message += '\n' t_index += 1 if ('resource-nodes' not in elem_cp or elem_cp['resource-nodes'] == {}): message += 'There are no resource nodes defined in this ' \ 'control plane.\n' else: for rn, elem_rn in six.iteritems(elem_cp['resource-nodes']): count = elem_rn['count'] node_type = nt_controller.get(rn) fn_singular = node_type.friendly_name fn_plural = node_type.friendly_name + 's' message += 'There %s %s %s (%s) ' \ 'defined in this control plane.\n' % ( pluralize(count, 'is', 'are'), count, pluralize(count, fn_singular, fn_plural), rn) message += '\n' cp_index += 1 return message
def _render_control_planes(self, fp): LOG.info('%s()' % KenLog.fcn()) svc_controller = self._controllers['Service'] res_controller = self._controllers['Resource'] es_resource = res_controller.resource('external-service') cloud_model = self._models['CloudModel'] for elem_cp in self._models['CloudModel']['control-planes']: if not ControlPlane.is_active(elem_cp): continue (cp_w, cp_h) = self._determine_size_for_control_plane(elem_cp) cp_box = Box(cp_w, cp_h) cp_type = elem_cp['type'] if elem_cp['type'].lower() == 'rcp': cp_type = '%s%s' % (elem_cp['type'], elem_cp['id']) cp_type_name = ControlPlane.get_name(elem_cp) title = '%s (%s, Region: %s)' % (cp_type.upper(), cp_type_name, elem_cp['region-name']) cp_box.set_title(title) tier_y = 2 tot_box_w = 0 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) t_box = Box(t_w, t_h) if tot_box_w == 0: tot_box_w = t_w title = 'T%d (Service Tier)' % int(elem_t['id']) t_box.set_title(title) cp_box.add_layer(t_box, 2, tier_y) tier_y += t_h + (self._padding_y / 2) member_x = 2 for m, elem_m in six.iteritems(elem_t['members']): if not Member.is_active(elem_m): continue if m.lower() == 'vip': continue (m_w, m_h) = self._determine_size_for_member( elem_cp, elem_t, elem_m) m_box = Box(m_w, m_h) title = 'M%s (Member)' % m m_box.set_title(title) t_box.add_layer(m_box, member_x, 2) member_x += (self._member_width + self._padding_x) service_y = 2 for elem_s in Member.get_services(elem_m): svc_name = svc_controller.service_output( elem_s['name']) if not es_resource.is_external(cloud_model, svc_name): m_box.add_string_centered(svc_name, service_y) else: ext_string = '%s (ext)' % svc_name ex, ey = m_box.get_centered_pos( svc_name, service_y) m_box.add_string_absolute(ext_string, ex, ey) service_y += 1 tm_networks = self._get_tier_member_networks( elem_cp, elem_t) if len(tm_networks) > 0: m_box.add_string_centered('-------', service_y) service_y += 1 for k, v in six.iteritems(tm_networks): text = '%s - %s' % (k, v[m][-14:]) m_box.add_string_centered(text, service_y) service_y += 1 cp_y = tier_y cp_y = self._render_resource_nodes(cp_box, cp_y, elem_cp, tot_box_w) self._render_control_plane_networks(cp_box, cp_y, elem_cp, tot_box_w) cp_box.display(fp)