コード例 #1
0
    def _determine_height_for_resource_nodes(self, elem_r):
        LOG.info('%s()' % KenLog.fcn())

        height = 0

        for elem_rn in ControlPlane.resources(elem_r):
            height_s = 0
            for elem_s in ResourceNode.servers(elem_rn):
                h = self._determine_height_for_resource_node(
                    elem_r, elem_rn, elem_s)
                if h > height_s:
                    height_s = h

            height += height_s
            height += 1
            height += self._padding_y
            height += 1

        return height
コード例 #2
0
    def _determine_height_for_resource_nodes(self, elem_r):
        LOG.info('%s()' % KenLog.fcn())

        height = 0

        for elem_rn in ControlPlane.resources(elem_r):
            height_s = 0
            for elem_s in ResourceNode.servers(elem_rn):
                h = self._determine_height_for_resource_node(
                    elem_r, elem_rn, elem_s)
                if h > height_s:
                    height_s = h

            height += height_s
            height += 1
            height += self._padding_y
            height += 1

        return height
コード例 #3
0
    def _render_resource_nodes(self, r_box, r_y, elem_r, w):
        LOG.info('%s()' % KenLog.fcn())

        for elem_rn in ControlPlane.resources(elem_r):

            # Build a list of server types by AZ and role
            server_types = {}
            AZs = set()
            for elem_s in ResourceNode.servers(elem_rn):
                role = ResourceNode.server_role(elem_s)
                if role not in server_types:
                    rn_h = self._determine_height_for_resource_node(
                        elem_r, elem_rn, elem_s)
                    server_types[role] = {'height': rn_h, 'zones': {}}
                AZ = ResourceNode.failure_zone(elem_s)
                AZs.add(AZ)
                if AZ not in server_types[role]['zones']:
                    server_types[role]['zones'][AZ] = {
                        'server': elem_s,
                        'count': 1
                    }
                else:
                    server_types[role]['zones'][AZ]['count'] += 1

            # Work out how height we're going to be
            res_h = 1
            for role, data in server_types.iteritems():
                res_h += data['height'] + self._padding_y
            res_w = len(AZs) * (self._server_width + self._padding_x)

            res_box = Box(res_w, res_h)
            res_box.set_title(ResourceNode.name(elem_rn))
            r_box.add_layer(res_box, 2, r_y)
            r_y += res_h + 1

            res_x = 2
            res_y = 2
            for roles, data in server_types.iteritems():
                for AZ in sorted(data['zones']):
                    elem_s = data['zones'][AZ]['server']
                    w = self._server_width - self._padding_x
                    rn_h = self._determine_height_for_resource_node(
                        elem_r, elem_rn, elem_s)
                    rn_box = Box(w, rn_h)

                    res_box.add_layer(rn_box, res_x, res_y)
                    res_x += (self._server_width + self._padding_x)

                    name = ResourceNode.name(elem_rn)

                    title = '%s (%s) (%s servers)' % (
                        role, AZ, data['zones'][AZ]['count'])
                    rn_box.set_title(title)

                    service_y = 2
                    services = Server.services(elem_s)
                    for elem_c in sorted(services):
                        rn_box.add_string_absolute(elem_c, 2, service_y)
                        service_y += 1
                        for elem_comp in sorted(services[elem_c]):
                            rn_box.add_string_absolute(elem_comp, 4, service_y)
                            service_y += 1

                    service_y += 1
                    sep = "-" * w
                    rn_box.add_string_absolute(sep, 2, service_y)
                    service_y += 2

                    interfaces = Server.interfaces(elem_s)
                    routes = Server.routes(elem_s)
                    for i in sorted(interfaces):
                        elem_i = interfaces[i]
                        device = elem_i['device']['name']
                        if 'bond-data' in elem_i:
                            device += " ("
                            first = True
                            for bond_dev in elem_i['bond-data'].get(
                                    'devices', []):
                                if not first:
                                    device += ", "
                                first = False
                                device += "%s" % bond_dev['name']
                            device += ")"
                        rn_box.add_string_absolute(device, 2, service_y)
                        service_y += 1
                        networks = Interface.networks(elem_i)
                        for n in sorted(networks):
                            elem_n = networks[n]
                            name = Network.name(elem_n)
                            if 'addr' in elem_n:
                                name += " (%s)" % elem_n['cidr']
                            rn_box.add_string_absolute(name, 4, service_y)
                            service_y += 1

                            net_routes = routes.get(n, {})
                            for r in sorted(net_routes):
                                elem_route = net_routes[r]
                                r_name = "-> %s " % r
                                if elem_route['default']:
                                    r_name += "(default)"
                                rn_box.add_string_absolute(
                                    r_name, 6, service_y)
                                service_y += 1

        return r_y
コード例 #4
0
    def _render_resource_nodes(self, r_box, r_y, elem_r, w):
        LOG.info('%s()' % KenLog.fcn())

        for elem_rn in ControlPlane.resources(elem_r):

            # Build a list of server types by AZ and role
            server_types = {}
            AZs = set()
            for elem_s in ResourceNode.servers(elem_rn):
                role = ResourceNode.server_role(elem_s)
                if role not in server_types:
                    rn_h = self._determine_height_for_resource_node(
                        elem_r, elem_rn, elem_s)
                    server_types[role] = {'height': rn_h,
                                          'zones': {}}
                AZ = ResourceNode.failure_zone(elem_s)
                AZs.add(AZ)
                if AZ not in server_types[role]['zones']:
                    server_types[role]['zones'][AZ] = {'server': elem_s,
                                                       'count': 1}
                else:
                    server_types[role]['zones'][AZ]['count'] += 1

            # Work out how height we're going to be
            res_h = 1
            for role, data in server_types.iteritems():
                res_h += data['height'] + self._padding_y
            res_w = len(AZs) * (self._server_width + self._padding_x)

            res_box = Box(res_w, res_h)
            res_box.set_title(ResourceNode.name(elem_rn))
            r_box.add_layer(res_box, 2, r_y)
            r_y += res_h + 1

            res_x = 2
            res_y = 2
            for roles, data in server_types.iteritems():
                for AZ in sorted(data['zones']):
                    elem_s = data['zones'][AZ]['server']
                    w = self._server_width - self._padding_x
                    rn_h = self._determine_height_for_resource_node(
                        elem_r, elem_rn, elem_s)
                    rn_box = Box(w, rn_h)

                    res_box.add_layer(rn_box, res_x, res_y)
                    res_x += (self._server_width + self._padding_x)

                    name = ResourceNode.name(elem_rn)

                    title = '%s (%s) (%s servers)' % (role, AZ, data['zones'][AZ]['count'])
                    rn_box.set_title(title)

                    service_y = 2
                    services = Server.services(elem_s)
                    for elem_c in sorted(services):
                        rn_box.add_string_absolute(elem_c, 2, service_y)
                        service_y += 1
                        for elem_comp in sorted(services[elem_c]):
                            rn_box.add_string_absolute(elem_comp, 4, service_y)
                            service_y += 1

                    service_y += 1
                    sep = "-" * w
                    rn_box.add_string_absolute(sep, 2, service_y)
                    service_y += 2

                    interfaces = Server.interfaces(elem_s)
                    routes = Server.routes(elem_s)
                    for i in sorted(interfaces):
                        elem_i = interfaces[i]
                        device = elem_i['device']['name']
                        if 'bond-data' in elem_i:
                            device += " ("
                            first = True
                            for bond_dev in elem_i['bond-data'].get('devices', []):
                                if not first:
                                    device += ", "
                                first = False
                                device += "%s" % bond_dev['name']
                            device += ")"
                        rn_box.add_string_absolute(device, 2, service_y)
                        service_y += 1
                        networks = Interface.networks(elem_i)
                        for n in sorted(networks):
                            elem_n = networks[n]
                            name = Network.name(elem_n)
                            if 'addr' in elem_n:
                                name += " (%s)" % elem_n['cidr']
                            rn_box.add_string_absolute(name, 4, service_y)
                            service_y += 1

                            net_routes = routes.get(n, {})
                            for r in sorted(net_routes):
                                elem_route = net_routes[r]
                                r_name = "-> %s " % r
                                if elem_route['default']:
                                    r_name += "(default)"
                                rn_box.add_string_absolute(r_name, 6, service_y)
                                service_y += 1

        return r_y