コード例 #1
0
ファイル: manager.py プロジェクト: loles/fuelweb
 def __add_new_interface(self, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     self.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().commit()
     node.interfaces.append(interface)
コード例 #2
0
 def __add_new_interface(self, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     self.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().commit()
     node.interfaces.append(interface)
コード例 #3
0
ファイル: base.py プロジェクト: tleontovich/fuelweb
    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        node = self.db.query(Node).get(node_id)
        ng_ids = [
            ng.id
            for ng in self.network_manager.get_all_cluster_networkgroups(node)
        ]
        allowed_networks = list(
            self.db.query(NetworkGroup).filter(NetworkGroup.id.in_(ng_ids)))

        for i in xrange(count):
            nic_dict = {
                'node_id': node_id,
                'name': 'eth{0}'.format(i),
                'mac': self._generate_random_mac(),
                'current_speed': 100,
                'max_speed': 1000,
                'allowed_networks': allowed_networks,
                'assigned_networks': allowed_networks
            }

            interface = NodeNICInterface()
            for k, v in nic_dict.iteritems():
                setattr(interface, k, v)

            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)

        return interfaces
コード例 #4
0
    def _add_interfaces_to_node(self, node, count=1):
        interfaces = []
        nic_utils = NICUtils()
        allowed_networks = nic_utils.get_all_cluster_networkgroups(node)

        for i in xrange(count):
            nic_dict = {
                'node_id': node.id,
                'name': 'eth{0}'.format(i),
                'mac': self._generate_random_mac(),
                'current_speed': 100,
                'max_speed': 1000,
                'allowed_networks': allowed_networks,
                'assigned_networks': allowed_networks
            }

            interface = NodeNICInterface()
            for k, v in nic_dict.iteritems():
                setattr(interface, k, v)

            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)

        return interfaces
コード例 #5
0
ファイル: topology.py プロジェクト: akolinko/product
 def get_nics_from_meta(self, node):
     nics = []
     if node.meta and node.meta.get('interfaces'):
         for i in node.meta['interfaces']:
             if 'name' not in i or 'mac' not in i:
                 logger.debug('Some node NIC interface in "meta" doesn\'t'
                              ' have name or mac')
                 continue
             nic = NodeNICInterface()
             nic.node_id = node.id
             for key in ('name', 'mac', 'current_speed', 'max_speed'):
                 if key in i:
                     setattr(nic, key, i[key])
             # Skip duplicated interfaces.
             if filter(lambda k: k.mac == nic.mac, nics):
                 logger.debug('Duplicated interface with MAC %r for node %r'
                              ' (id: %s)',
                              nic.mac, node.name, node.id)
                 continue
             nics.append(nic)
     return nics
コード例 #6
0
 def get_nics_from_meta(self, node):
     nics = []
     if node.meta and node.meta.get('interfaces'):
         for i in node.meta['interfaces']:
             if 'name' not in i or 'mac' not in i:
                 logger.debug('Some node NIC interface in "meta" doesn\'t'
                              ' have name or mac')
                 continue
             nic = NodeNICInterface()
             nic.node_id = node.id
             for key in ('name', 'mac', 'current_speed', 'max_speed'):
                 if key in i:
                     setattr(nic, key, i[key])
             # Skip duplicated interfaces.
             if filter(lambda k: k.mac == nic.mac, nics):
                 logger.debug(
                     'Duplicated interface with MAC %r for node %r'
                     ' (id: %s)', nic.mac, node.name, node.id)
                 continue
             nics.append(nic)
     return nics
コード例 #7
0
ファイル: base.py プロジェクト: adanin/fuel-web
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(
                mac=interface.get('mac'),
                name=interface.get('name'),
                ip_addr=interface.get('ip'),
                netmask=interface.get('netmask'))

            self.db.add(interface)
            node.interfaces.append(interface)

        # If node in a cluster then add
        # allowed_networks for all interfaces
        # and assigned_networks for first interface
        if node.cluster_id:
            ng_ids = [ng.id for ng in
                      self.network_manager.get_all_cluster_networkgroups(node)]
            allowed_networks = list(self.db.query(NetworkGroup).filter(
                NetworkGroup.id.in_(ng_ids)))

            for interface in node.interfaces:
                interface.allowed_networks = allowed_networks

            node.interfaces[0].assigned_networks = allowed_networks

        self.db.commit()
        # At least one interface should have
        # same ip as mac in meta
        if node.interfaces and not \
           filter(lambda i: node.mac == i.mac, node.interfaces):

            node.interfaces[0].mac = node.mac
            self.db.commit()
コード例 #8
0
    def update_interfaces_info(self, node):
        if not "interfaces" in node.meta:
            raise Exception("No interfaces metadata specified for node")

        for interface in node.meta["interfaces"]:
            nicInterface = NodeNICInterface()
            nicInterface.node_id = node.id
            nicInterface.name = interface["name"]
            nicInterface.mac = interface["mac"]
            if "max_speed" in interface:
                nicInterface.max_speed = interface["max_speed"]
            if "current_speed" in interface:
                nicInterface.current_speed = interface["current_speed"]
            self.db.add(nicInterface)
            self.db.commit()
            node.interfaces.append(nicInterface)
コード例 #9
0
ファイル: manager.py プロジェクト: akolinko/product
    def update_interfaces_info(self, node):
        if not "interfaces" in node.meta:
            raise Exception("No interfaces metadata specified for node")

        for interface in node.meta["interfaces"]:
            nicInterface = NodeNICInterface()
            nicInterface.node_id = node.id
            nicInterface.name = interface["name"]
            nicInterface.mac = interface["mac"]
            if "max_speed" in interface:
                nicInterface.max_speed = interface["max_speed"]
            if "current_speed" in interface:
                nicInterface.current_speed = interface["current_speed"]
            self.db.add(nicInterface)
            self.db.commit()
            node.interfaces.append(nicInterface)
コード例 #10
0
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(mac=interface.get('mac'),
                                         name=interface.get('name'),
                                         ip_addr=interface.get('ip'),
                                         netmask=interface.get('netmask'))

            self.db.add(interface)
            node.interfaces.append(interface)

        # If node in a cluster then add
        # allowed_networks for all interfaces
        # and assigned_networks for first interface
        if node.cluster_id:
            ng_ids = [
                ng.id for ng in
                self.network_manager.get_all_cluster_networkgroups(node)
            ]
            allowed_networks = list(
                self.db.query(NetworkGroup).filter(
                    NetworkGroup.id.in_(ng_ids)))

            for interface in node.interfaces:
                interface.allowed_networks = allowed_networks

            node.interfaces[0].assigned_networks = allowed_networks

        self.db.commit()
        # At least one interface should have
        # same ip as mac in meta
        if node.interfaces and not \
           filter(lambda i: node.mac == i.mac, node.interfaces):

            node.interfaces[0].mac = node.mac
            self.db.commit()