Ejemplo n.º 1
0
    def apply_network_template(cls, instance, template):
        if template is None:
            instance.network_template = None
            return

        template_body = template["adv_net_template"]
        # Get the correct nic_mapping for this node so we can
        # dynamically replace any interface references in any
        # template for this node.
        from nailgun.objects import NodeGroup

        node_group = NodeGroup.get_by_uid(instance.group_id).name
        if node_group not in template_body:
            node_group = "default"

        node_name = cls.get_slave_name(instance)
        nic_mapping = template_body[node_group]["nic_mapping"]
        if node_name not in nic_mapping:
            node_name = "default"

        nic_mapping = nic_mapping[node_name]

        # Replace interface references and re-parse JSON
        template_object = NetworkTemplate(jsonutils.dumps(template_body))
        node_template = template_object.safe_substitute(nic_mapping)
        parsed_template = jsonutils.loads(node_template)

        output = parsed_template[node_group]
        output["templates"] = output.pop("network_scheme")
        output["roles"] = {}
        output["endpoints"] = {}
        for v in output["templates"].values():
            for endpoint in v["endpoints"]:
                output["endpoints"][endpoint] = {}
            for role, ep in v["roles"].items():
                output["roles"][role] = ep

        instance.network_template = output
        db().flush()

        if instance.cluster:
            nm = Cluster.get_network_manager(instance.cluster)
            nm.assign_networks_by_template(instance)
Ejemplo n.º 2
0
    def apply_network_template(cls, instance, template):
        if template is None:
            instance.network_template = None
            return

        template_body = template['adv_net_template']
        # Get the correct nic_mapping for this node so we can
        # dynamically replace any interface references in any
        # template for this node.
        from nailgun.objects import NodeGroup
        node_group = NodeGroup.get_by_uid(instance.group_id).name
        if node_group not in template_body:
            node_group = 'default'

        node_name = cls.get_slave_name(instance)
        nic_mapping = template_body[node_group]['nic_mapping']
        if node_name not in nic_mapping:
            node_name = 'default'

        nic_mapping = nic_mapping[node_name]

        # Replace interface references and re-parse JSON
        template_object = NetworkTemplate(jsonutils.dumps(template_body))
        node_template = template_object.safe_substitute(nic_mapping)
        parsed_template = jsonutils.loads(node_template)

        output = parsed_template[node_group]
        output['templates'] = output.pop('network_scheme')
        output['roles'] = {}
        output['endpoints'] = {}
        for v in output['templates'].values():
            for endpoint in v['endpoints']:
                output['endpoints'][endpoint] = {}
            for role, ep in v['roles'].items():
                output['roles'][role] = ep

        instance.network_template = output
        db().flush()

        if instance.cluster:
            nm = Cluster.get_network_manager(instance.cluster)
            nm.assign_networks_by_template(instance)
Ejemplo n.º 3
0
    def apply_network_template(cls, instance, template):
        if template is None:
            instance.network_template = None
            return

        template_body = template['adv_net_template']
        # Get the correct nic_mapping for this node so we can
        # dynamically replace any interface references in any
        # template for this node.
        from nailgun.objects import NodeGroup
        node_group = NodeGroup.get_by_uid(instance.group_id).name
        if node_group not in template_body:
            node_group = 'default'

        node_name = cls.get_slave_name(instance)
        nic_mapping = template_body[node_group]['nic_mapping']
        if node_name not in nic_mapping:
            node_name = 'default'

        nic_mapping = nic_mapping[node_name]

        # Replace interface references and re-parse JSON
        template_object = NetworkTemplate(jsonutils.dumps(template_body))
        node_template = template_object.safe_substitute(nic_mapping)
        parsed_template = jsonutils.loads(node_template)

        output = parsed_template[node_group]
        output['templates'] = output.pop('network_scheme')
        output['roles'] = {}
        output['endpoints'] = {}
        for v in output['templates'].values():
            for endpoint in v['endpoints']:
                output['endpoints'][endpoint] = {}
            for role, ep in v['roles'].items():
                output['roles'][role] = ep

        instance.network_template = output
Ejemplo n.º 4
0
 def get_controllers_node_group(cls, cluster):
     from nailgun.objects import NodeGroup
     group_id = cls.get_controllers_group_id(cluster)
     return NodeGroup.get_by_uid(group_id)
Ejemplo n.º 5
0
 def get_controllers_node_group(cls, cluster):
     from nailgun.objects import NodeGroup
     group_id = cls.get_controllers_group_id(cluster)
     return NodeGroup.get_by_uid(group_id)