Exemplo n.º 1
0
    def __check_interfaces_correctness(cls, node):
        """Check that
        * interface list in meta field is not empty
        * at least one interface has ip which
          includes to admin subnet. It can happens in
          case if agent was running, but network
          interfaces were not configured yet.
        """
        if not node.meta:
            raise errors.InvalidInterfacesInfo(
                u'Meta field for node "%s" is empty' % node.full_name)
        if not node.meta.get('interfaces'):
            raise errors.InvalidInterfacesInfo(
                u'Cannot find interfaces field "%s" in meta' % node.full_name)

        interfaces = node.meta['interfaces']
        admin_interface = None
        for interface in interfaces:
            ip_addr = interface.get('ip')
            if cls.is_ip_belongs_to_admin_subnet(ip_addr):
                # Interface was founded
                admin_interface = interface
                break

        if not admin_interface:
            raise errors.InvalidInterfacesInfo(
                u'Cannot find interface with ip which '
                'includes to admin subnet "%s"' % node.full_name)
Exemplo n.º 2
0
    def _validate_data(cls, interfaces):
        if not isinstance(interfaces, list):
            raise errors.InvalidInterfacesInfo(
                "Meta.interfaces should be list",
                log_message=True
            )

        return interfaces
Exemplo n.º 3
0
    def validate_update(cls, interfaces):
        interfaces = cls._validate_data(interfaces)

        for nic in interfaces:
            if not isinstance(nic, dict):
                raise errors.InvalidInterfacesInfo(
                    "Interface in meta.interfaces must be dict",
                    log_message=True)

        return interfaces
Exemplo n.º 4
0
    def check_interfaces_correctness(cls, node):
        """Check that
        * interface list in meta field is not empty
        * at least one interface has ip which
          includes to admin subnet. It can happens in
          case if agent was running, but network
          interfaces were not configured yet.
        * there're no networks assigned to removed interface
        """
        if not node.meta:
            raise errors.InvalidInterfacesInfo(
                u'Meta field for node "%s" is empty' % node.full_name)
        if not node.meta.get('interfaces'):
            raise errors.InvalidInterfacesInfo(
                u'Cannot find interfaces field "%s" in meta' % node.full_name)

        interfaces = node.meta['interfaces']
        admin_interface = None
        for interface in interfaces:
            ip_addr = interface.get('ip')
            if cls.is_ip_belongs_to_admin_subnet(ip_addr):
                # Interface was founded
                admin_interface = interface
                break
            elif interface['mac'].lower() == node.mac:
                admin_interface = interface
                break

        if not admin_interface:
            raise errors.InvalidInterfacesInfo(
                u'Cannot find interface with ip which '
                'includes to admin subnet "%s"' % node.full_name)

        # raise exception if an interface is about to remove,
        # but has assigned network and it's already deployed
        interfaces = [i['name'] for i in interfaces]
        for iface in node.nic_interfaces:
            if iface.name not in interfaces and iface.assigned_networks_list:
                raise errors.InvalidInterfacesInfo(
                    u'Could not remove interface "{0}", since it is assigned '
                    u'to one or more networks'.format(iface.name)
                )
Exemplo n.º 5
0
 def validate_create(cls, meta):
     cls._validate_data(meta)
     if 'interfaces' in meta:
         meta['interfaces'] = MetaInterfacesValidator.validate_create(
             meta['interfaces'])
     else:
         raise errors.InvalidInterfacesInfo(
             "Failed to discover node: "
             "invalid interfaces info",
             log_message=True)
     return meta