当前位置: 首页>>代码示例>>Python>>正文


Python NetworkManager.create_network_groups方法代码示例

本文整理汇总了Python中nailgun.network.manager.NetworkManager.create_network_groups方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.create_network_groups方法的具体用法?Python NetworkManager.create_network_groups怎么用?Python NetworkManager.create_network_groups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nailgun.network.manager.NetworkManager的用法示例。


在下文中一共展示了NetworkManager.create_network_groups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: POST

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import create_network_groups [as 别名]
    def POST(self):
        """
        :returns: JSONized Cluster object.
        :http: * 201 (cluster successfully created)
               * 400 (invalid cluster data specified)
               * 409 (cluster with such parameters already exists)
        """
        # It's used for cluster creating only.
        data = self.checked_data()

        cluster = Cluster()
        cluster.release = db().query(Release).get(data["release"])
        # TODO: use fields
        for field in ('name', 'mode', 'net_manager'):
            if data.get(field):
                setattr(cluster, field, data.get(field))
        db().add(cluster)
        db().commit()
        attributes = Attributes(
            editable=cluster.release.attributes_metadata.get("editable"),
            generated=cluster.release.attributes_metadata.get("generated"),
            cluster=cluster
        )
        attributes.generate_fields()

        netmanager = NetworkManager()
        try:
            netmanager.create_network_groups(cluster.id)

            cluster.add_pending_changes("attributes")
            cluster.add_pending_changes("networks")

            if 'nodes' in data and data['nodes']:
                nodes = db().query(Node).filter(
                    Node.id.in_(data['nodes'])
                ).all()
                map(cluster.nodes.append, nodes)
                db().commit()
                for node in nodes:
                    netmanager.allow_network_assignment_to_all_interfaces(
                        node.id
                    )
                    netmanager.assign_networks_to_main_interface(node.id)

            raise web.webapi.created(json.dumps(
                ClusterHandler.render(cluster),
                indent=4
            ))
        except (
            errors.OutOfVLANs,
            errors.OutOfIPs,
            errors.NoSuitableCIDR
        ) as e:
            # Cluster was created in this request,
            # so we no need to use ClusterDeletionManager.
            # All relations wiil be cascade deleted automaticly.
            # TODO: investigate transactions
            db().delete(cluster)

            raise web.badrequest(e.message)
开发者ID:mydaisy2,项目名称:fuelweb,代码行数:62,代码来源:cluster.py

示例2: POST

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import create_network_groups [as 别名]
    def POST(self):
        # It's used for cluster creating only.
        data = self.validator.validate(web.data())

        cluster = Cluster()
        cluster.release = self.db.query(Release).get(data["release"])
        # TODO: use fields
        for field in ('name', 'type', 'mode', 'net_manager'):
            if data.get(field):
                setattr(cluster, field, data.get(field))
        self.db.add(cluster)
        self.db.commit()

        attributes = Attributes(
            editable=cluster.release.attributes_metadata.get("editable"),
            generated=cluster.release.attributes_metadata.get("generated"),
            cluster=cluster
        )
        attributes.generate_fields()

        netmanager = NetworkManager()
        netmanager.create_network_groups(cluster.id)

        cluster.add_pending_changes("attributes")
        cluster.add_pending_changes("networks")

        if 'nodes' in data and data['nodes']:
            nodes = self.db.query(Node).filter(
                Node.id.in_(data['nodes'])
            ).all()
            map(cluster.nodes.append, nodes)
            for node in nodes:
                self.allow_network_assignment_to_all_interfaces(node)
                self.assign_networks_to_main_interface(node)
            self.db.commit()

        raise web.webapi.created(json.dumps(
            ClusterHandler.render(cluster),
            indent=4
        ))
开发者ID:akolinko,项目名称:product,代码行数:42,代码来源:cluster.py


注:本文中的nailgun.network.manager.NetworkManager.create_network_groups方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。