def create_network(self,
                       net_view_name,
                       cidr,
                       nameservers=None,
                       members=None,
                       gateway_ip=None,
                       dhcp_trel_ip=None,
                       network_extattrs=None):
        """Create NIOS Network."""

        # NIOS does not allow to set Dhcp options for IPv6 over WAPI,
        # so limit options usage with IPv4 only
        ipv4 = ib_utils.determine_ip_version(cidr) == 4

        options = []
        if nameservers:
            options.append(
                obj.DhcpOption(name='domain-name-servers',
                               value=",".join(nameservers)))
        if ipv4 and gateway_ip:
            options.append(obj.DhcpOption(name='routers', value=gateway_ip))
        if ipv4 and dhcp_trel_ip:
            options.append(
                obj.DhcpOption(name='dhcp-server-identifier',
                               num=54,
                               value=dhcp_trel_ip))
        return obj.Network.create(self.connector,
                                  network_view=net_view_name,
                                  cidr=cidr,
                                  members=members,
                                  options=options,
                                  extattrs=network_extattrs,
                                  check_if_exists=False)
Beispiel #2
0
 def create(cls, ip=None, mac=None, **kwargs):
     if ip is None:
         raise ValueError
     if ib_utils.determine_ip_version(ip) == 6:
         return IPv6(ip=ip, duid=ib_utils.generate_duid(mac), **kwargs)
     else:
         return IPv4(ip=ip, mac=mac, **kwargs)
    def create_network(self, net_view_name, cidr, nameservers=None,
                       members=None, gateway_ip=None, dhcp_trel_ip=None,
                       network_extattrs=None):
        """Create NIOS Network."""

        # NIOS does not allow to set Dhcp options for IPv6 over WAPI,
        # so limit options usage with IPv4 only
        ipv4 = ib_utils.determine_ip_version(cidr) == 4

        options = []
        if nameservers:
            options.append(obj.DhcpOption(name='domain-name-servers',
                                          value=",".join(nameservers)))
        if ipv4 and gateway_ip:
            options.append(obj.DhcpOption(name='routers',
                                          value=gateway_ip))
        if ipv4 and dhcp_trel_ip:
            options.append(obj.DhcpOption(name='dhcp-server-identifier',
                                          num=54,
                                          value=dhcp_trel_ip))
        return obj.Network.create(self.connector,
                                  network_view=net_view_name,
                                  cidr=cidr,
                                  members=members,
                                  options=options,
                                  extattrs=network_extattrs,
                                  check_if_exists=False)
Beispiel #4
0
 def create(cls, ip=None, mac=None, **kwargs):
     if ip is None:
         raise ValueError
     if ib_utils.determine_ip_version(ip) == 6:
         return IPv6(ip=ip, duid=ib_utils.generate_duid(mac),
                     **kwargs)
     else:
         return IPv4(ip=ip, mac=mac, **kwargs)
Beispiel #5
0
 def ip(self, ip):
     # AnyMember represents both ipv4 and ipv6 objects, so don't need
     # versioned object for that. Just set v4 or v6 field additionally
     # to setting shadow 'ip' field itself.
     # So once dict is generated by to_dict only versioned ip field
     # to be shown.
     if ib_utils.determine_ip_version(ip) == 6:
         self.ipv6addr = ip
     else:
         self.ipv4addr = ip
Beispiel #6
0
 def ip(self, ip):
     # AnyMember represents both ipv4 and ipv6 objects, so don't need
     # versioned object for that. Just set v4 or v6 field additionally
     # to setting shadow 'ip' field itself.
     # So once dict is generated by to_dict only versioned ip field
     # to be shown.
     self._ip = ip
     if ib_utils.determine_ip_version(ip) == 6:
         self.ipv6addr = ip
     else:
         self.ipv4addr = ip
Beispiel #7
0
    def get_class_from_args(cls, kwargs):
        # skip processing if cls already versioned class
        if cls._ip_version:
            return cls

        for field in ['ip', 'cidr', 'start_ip', 'ip_address']:
            if field in kwargs:
                if ib_utils.determine_ip_version(kwargs[field]) == 6:
                    return cls.get_v6_class()
                else:
                    return cls.get_v4_class()
        # fallback to IPv4 object if find nothing
        return cls.get_v4_class()
    def get_class_from_args(cls, kwargs):
        # skip processing if cls already versioned class
        if cls._ip_version:
            return cls

        for field in ['ip', 'cidr', 'start_ip', 'ip_address']:
            if field in kwargs:
                if ib_utils.determine_ip_version(kwargs[field]) == 6:
                    return cls.get_v6_class()
                else:
                    return cls.get_v4_class()
        # fallback to IPv4 object if find nothing
        return cls.get_v4_class()
    def unbind_name_from_record_a(self, dns_view, ip, name, unbind_list):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in unbind_list) or
                (not is_ipv4 and 'record:aaaa' in unbind_list)):
            a_record = obj.ARecordBase.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            a_record.delete()

        if 'record:ptr' in unbind_list:
            ptr_record = obj.PtrRecord.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            ptr_record.delete()
Beispiel #10
0
    def unbind_name_from_record_a(self, dns_view, ip, name, unbind_list):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in unbind_list)
                or (not is_ipv4 and 'record:aaaa' in unbind_list)):
            a_record = obj.ARecordBase.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            a_record.delete()

        if 'record:ptr' in unbind_list:
            ptr_record = obj.PtrRecord.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            ptr_record.delete()
Beispiel #11
0
    def bind_name_with_record_a(self, dns_view, ip, name, bind_list, extattrs):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in bind_list)
                or (not is_ipv4 and 'record:aaaa' in bind_list)):
            obj.ARecordBase.create(self.connector,
                                   view=dns_view,
                                   ip=ip,
                                   name=name,
                                   extattrs=extattrs)

        if 'record:ptr' in bind_list:
            obj.PtrRecord.create(self.connector,
                                 view=dns_view,
                                 ip=ip,
                                 ptrdname=name,
                                 extattrs=extattrs)
    def bind_name_with_record_a(self, dns_view, ip, name, bind_list,
                                extattrs):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in bind_list) or
                (not is_ipv4 and 'record:aaaa' in bind_list)):
            obj.ARecordBase.create(self.connector,
                                   view=dns_view,
                                   ip=ip,
                                   name=name,
                                   extattrs=extattrs)

        if 'record:ptr' in bind_list:
            obj.PtrRecord.create(self.connector,
                                 view=dns_view,
                                 ip=ip,
                                 ptrdname=name,
                                 extattrs=extattrs)
Beispiel #13
0
    def create_network(self,
                       net_view_name,
                       cidr,
                       nameservers=None,
                       members=None,
                       gateway_ip=None,
                       dhcp_trel_ip=None,
                       network_extattrs=None):
        """Create NIOS Network and prepare DHCP options.

        Some DHCP options are valid for IPv4 only, so just skip processing
        them for IPv6 case.

        :param net_view_name: network view name
        :param cidr: network to allocate, example '172.23.23.0/24'
        :param nameservers: list of name servers hosts/ip
        :param members: list of objects.AnyMember objects that are expected
            to serve dhcp for created network
        :param gateway_ip: gateway ip for the network (valid for IPv4 only)
        :param dhcp_trel_ip: ip address of dhcp relay (valid for IPv4 only)
        :param network_extattrs: extensible attributes for network (instance of
            objects.EA)
        :returns: created network (instance of objects.Network)
        """
        ipv4 = ib_utils.determine_ip_version(cidr) == 4

        options = []
        if nameservers:
            options.append(
                obj.DhcpOption(name='domain-name-servers',
                               value=",".join(nameservers)))
        if ipv4 and gateway_ip:
            options.append(obj.DhcpOption(name='routers', value=gateway_ip))
        if ipv4 and dhcp_trel_ip:
            options.append(
                obj.DhcpOption(name='dhcp-server-identifier',
                               num=54,
                               value=dhcp_trel_ip))
        return obj.Network.create(self.connector,
                                  network_view=net_view_name,
                                  cidr=cidr,
                                  members=members,
                                  options=options,
                                  extattrs=network_extattrs,
                                  check_if_exists=False)
Beispiel #14
0
    def unbind_name_from_record_a(self, dns_view, ip, name, unbind_list):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in unbind_list)
                or (not is_ipv4 and 'record:aaaa' in unbind_list)):
            a_record = obj.ARecordBase.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            if a_record:
                self.delete_objects_associated_with_a_record(
                    a_record.name, a_record.view, unbind_list)
                a_record.delete()

        if 'record:ptr' in unbind_list:
            ptr_record = obj.PtrRecord.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              ptrdname=name)
            if ptr_record:
                ptr_record.delete()
    def unbind_name_from_record_a(self, dns_view, ip, name, unbind_list):
        is_ipv4 = ib_utils.determine_ip_version(ip) == 4
        if ((is_ipv4 and 'record:a' in unbind_list) or
                (not is_ipv4 and 'record:aaaa' in unbind_list)):
            a_record = obj.ARecordBase.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              name=name)
            if a_record:
                self.delete_objects_associated_with_a_record(a_record.name,
                                                             a_record.view,
                                                             unbind_list)
                a_record.delete()

        if 'record:ptr' in unbind_list:
            ptr_record = obj.PtrRecord.search(self.connector,
                                              view=dns_view,
                                              ip=ip,
                                              ptrdname=name)
            if ptr_record:
                ptr_record.delete()
    def create_network(self, net_view_name, cidr, nameservers=None,
                       members=None, gateway_ip=None, dhcp_trel_ip=None,
                       network_extattrs=None):
        """Create NIOS Network and prepare DHCP options.

        Some DHCP options are valid for IPv4 only, so just skip processing
        them for IPv6 case.

        :param net_view_name: network view name
        :param cidr: network to allocate, example '172.23.23.0/24'
        :param nameservers: list of name servers hosts/ip
        :param members: list of objects.AnyMember objects that are expected
            to serve dhcp for created network
        :param gateway_ip: gateway ip for the network (valid for IPv4 only)
        :param dhcp_trel_ip: ip address of dhcp relay (valid for IPv4 only)
        :param network_extattrs: extensible attributes for network (instance of
            objects.EA)
        :returns: created network (instance of objects.Network)
        """
        ipv4 = ib_utils.determine_ip_version(cidr) == 4

        options = []
        if nameservers:
            options.append(obj.DhcpOption(name='domain-name-servers',
                                          value=",".join(nameservers)))
        if ipv4 and gateway_ip:
            options.append(obj.DhcpOption(name='routers',
                                          value=gateway_ip))
        if ipv4 and dhcp_trel_ip:
            options.append(obj.DhcpOption(name='dhcp-server-identifier',
                                          num=54,
                                          value=dhcp_trel_ip))
        return obj.Network.create(self.connector,
                                  network_view=net_view_name,
                                  cidr=cidr,
                                  members=members,
                                  options=options,
                                  extattrs=network_extattrs,
                                  check_if_exists=False)
Beispiel #17
0
 def __init__(self, address, next_available_ip):
     self.ip_version = ib_utils.determine_ip_version(address)
     self.next_available_ip = next_available_ip
Beispiel #18
0
 def __init__(self, address, next_available_ip):
     self.ip_version = ib_utils.determine_ip_version(address)
     self.next_available_ip = next_available_ip