Beispiel #1
0
 def get_type(e_id):
     entity = Entity(self._db)
     try:
         entity.find(e_id)
         return six.text_type(co.EntityType(entity.entity_type))
     except Cerebrum.Errors.NotFoundError:
         return None
Beispiel #2
0
    def populate(self, subnet, description, vlan=None):
        """Populate subnet instance's attributes."""
        Entity.populate(self, self.const.entity_dns_ipv6_subnet)
        # If __in_db is present, it must be True; calling populate on
        # an object where __in_db is present and False is very likely
        # a programming error.
        #
        # If __in_db in not present, we'll set it to False.
        try:
            if not self.__in_db:
                raise RuntimeError("populate() called multiple times.")
        except AttributeError:
            self.__in_db = False

        self.subnet_ip, subnet_mask = subnet.split('/')
        self.subnet_mask = int(subnet_mask)
        self.subnet_ip = IPv6Utils.explode(self.subnet_ip)

        self.ip_min, self.ip_max = IPv6Calc.ip_range_by_netmask(
            self.subnet_ip, self.subnet_mask)
        self.description = description
        self.vlan = vlan
        self.name_prefix = ''

        # TODO: Fix this
        res_net_size = cereconf.DEFAULT_RESERVED_BY_IPv6_NET_SIZE
        max_res = max(res_net_size.values())
        self.no_of_reserved_adr = res_net_size.get(self.subnet_mask, max_res)
        self.calculate_reserved_addresses()
Beispiel #3
0
    def populate(self, subnet, description, vlan=None):
        """Populate subnet instance's attributes."""
        Entity.populate(self, self.const.entity_dns_ipv6_subnet)
        # If __in_db is present, it must be True; calling populate on
        # an object where __in_db is present and False is very likely
        # a programming error.
        #
        # If __in_db in not present, we'll set it to False.
        try:
            if not self.__in_db:
                raise RuntimeError("populate() called multiple times.")
        except AttributeError:
            self.__in_db = False

        self.subnet_ip, subnet_mask = subnet.split('/')
        self.subnet_mask = int(subnet_mask)
        self.subnet_ip = IPv6Utils.explode(self.subnet_ip)

        self.ip_min, self.ip_max = IPv6Calc.ip_range_by_netmask(
            self.subnet_ip, self.subnet_mask)
        self.description = description
        self.vlan = vlan

        # TODO: Fix this
        max_res = max(cereconf.DEFAULT_RESERVED_BY_IPv6_NET_SIZE.values())
        self.no_of_reserved_adr = cereconf.DEFAULT_RESERVED_BY_IPv6_NET_SIZE.get(
            self.subnet_mask, max_res)
        self.calculate_reserved_addresses()
Beispiel #4
0
 def populate(self, dns_owner_id, hinfo, name=None, ttl=None, parent=None):
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_host)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     for k in locals().keys():
         if k != 'self':
             setattr(self, k, locals()[k])
Beispiel #5
0
 def populate(self, dns_owner_id, hinfo, name=None, ttl=None, parent=None):
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_host)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     for k in locals().keys():
         if k != 'self':
             setattr(self, k, locals()[k])
Beispiel #6
0
 def populate(self, dns_owner_id, ip_number_id, name=None, ttl=None, mac=None, parent=None):
     """Set either dns_owner_id or name"""
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_a_record)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     for k in locals().keys():
         if k != "self":
             setattr(self, k, locals()[k])
Beispiel #7
0
 def populate(self, zone, name, mx_set_id=None, parent=None):
     """zone may either be a number or a DnsZone constant"""
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_owner)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     self.name = name
     self.mx_set_id = mx_set_id
     self.zone = zone
Beispiel #8
0
 def populate(self, zone, name, mx_set_id=None, parent=None):
     """zone may either be a number or a DnsZone constant"""
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_owner)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     self.name = name
     self.mx_set_id = mx_set_id
     self.zone = zone
Beispiel #9
0
    def populate(self, subnet, description, vlan=None):
        """Populate subnet instance's attributes.

        @type subnet: string
        @param subnet: A string that represents the subnet. Example:
            10.0.0.0/16. The last '.0' is not required, e.g. 10.0.0/16.

        @type description: string
        @param description: Something that describes the given subnet. It is
            free text, but local policies might use this in a parsable format
            to describe the usage of the given subnet.

        @type vlan: int
        @param vlan: A number that represents what VLAN the subnet corresponds
            to.

        """
        Entity.populate(self, self.const.entity_dns_subnet)
        # If __in_db is present, it must be True; calling populate on
        # an object where __in_db is present and False is very likely
        # a programming error.
        #
        # If __in_db in not present, we'll set it to False.
        try:
            if not self.__in_db:
                raise RuntimeError("populate() called multiple times.")
        except AttributeError:
            self.__in_db = False

        self.subnet_ip, subnet_mask = subnet.split('/')
        self.subnet_mask = int(subnet_mask)
        if len(self.subnet_ip.split('.')) == 3:
            self.subnet_ip = self.subnet_ip + ".0"

        (self.ip_min,
         self.ip_max) = IPCalc().ip_range_by_netmask(self.subnet_ip,
                                                     self.subnet_mask)
        self.description = description
        self.vlan = vlan
        self.name_prefix = ''

        max_res = max(cereconf.DEFAULT_RESERVED_BY_NET_SIZE.values())
        self.no_of_reserved_adr = cereconf.DEFAULT_RESERVED_BY_NET_SIZE.get(
            self.subnet_mask, max_res)
        self.calculate_reserved_addresses()
Beispiel #10
0
    def populate(self, subnet, description, vlan=None):
        """Populate subnet instance's attributes.

        @type subnet: string
        @param subnet: A string that represents the subnet. Example:
            10.0.0.0/16. The last '.0' is not required, e.g. 10.0.0/16.

        @type description: string
        @param description: Something that describes the given subnet. It is
            free text, but local policies might use this in a parsable format to
            describe the usage of the given subnet.

        @type vlan: int
        @param vlan: A number that represents what VLAN the subnet corresponds
            to.

        """
        Entity.populate(self, self.const.entity_dns_subnet)
        # If __in_db is present, it must be True; calling populate on
        # an object where __in_db is present and False is very likely
        # a programming error.
        #
        # If __in_db in not present, we'll set it to False.
        try:
            if not self.__in_db:
                raise RuntimeError("populate() called multiple times.")
        except AttributeError:
            self.__in_db = False

        self.subnet_ip, subnet_mask = subnet.split('/')
        self.subnet_mask = int(subnet_mask)
        if len(self.subnet_ip.split('.')) == 3:
            self.subnet_ip = self.subnet_ip + ".0"

        self.ip_min, self.ip_max = IPCalc().ip_range_by_netmask(self.subnet_ip,
                                                                self.subnet_mask)
        self.description = description
        self.vlan = vlan

        max_res = max(cereconf.DEFAULT_RESERVED_BY_NET_SIZE.values())
        self.no_of_reserved_adr = cereconf.DEFAULT_RESERVED_BY_NET_SIZE.get(
            self.subnet_mask, max_res)
        self.calculate_reserved_addresses()
Beispiel #11
0
 def populate(self,
              dns_owner_id,
              ip_number_id,
              name=None,
              ttl=None,
              mac=None,
              parent=None):
     """Set either dns_owner_id or name"""
     if parent is not None:
         self.__xerox__(parent)
     else:
         Entity.populate(self, self.const.entity_dns_a_record)
     try:
         if not self.__in_db:
             raise RuntimeError, "populate() called multiple times."
     except AttributeError:
         self.__in_db = False
     for k in locals().keys():
         if k != 'self':
             setattr(self, k, locals()[k])
Beispiel #12
0
 def get_owner(self):
     """Return the owner object of the proper type."""
     ent = Entity(self._db)
     ent.find(self.owner_entity_id)
     if ent.entity_type == self.const.entity_voip_service:
         result = VoipService(self._db)
         result.find(self.owner_entity_id)
         return result
     ent.clear()
     return ent.get_subclassed_object(self.owner_entity_id)
Beispiel #13
0
def test_get_subclassed_object(database, factory, Entity, entity_type):
    from Cerebrum.Entity import Entity as BaseEntity

    if Entity == BaseEntity:
        pytest.skip("Cannot test subclassed object with base class")

    # patch class into factory class cache
    factory_name = 'e3dc9cb2d58bdbda'
    factory.class_cache[factory_name] = Entity
    factory.type_component_map[str(entity_type)] = factory_name

    # Make entity of entity_type
    base = BaseEntity(database)
    base.populate(entity_type)
    base.write_db()

    # test
    entity = base.get_subclassed_object()
    assert type(entity) != type(base)
    assert type(entity) == Entity