コード例 #1
0
ファイル: ipaddress.py プロジェクト: jpwarren/docgen
    def configure_from_node(self, node, defaults, parent):
        XMLConfigurable.configure_from_node(self, node, defaults, parent)

        # If I have a vlan_number set, my VLAN is the vlan
        # my parent has that has the same vlan number
        if self.vlan_number is not None:
            self.vlan_number = int(self.vlan_number)
            log.debug("vlan number: %s, %s", self.vlan_number, parent.site.get_vlans() )
            self.vlan = [x for x in parent.site.get_vlans() if x.number == self.vlan_number][0]
        else:
            # The vlan I belong to is my parent's VLAN
            self.vlan = parent.get_vlan()
            pass
        
        if self.vlan is None:
            raise KeyError("No VLAN defined for parent of IP address %s" % self.ip)

        # If this is a service IP, it must have a vlan number defined
        if self.type == 'service':
            if self.vlan_number is None:
                raise KeyError("Service IP address '%s' defined with no vlan_number attribute." % self.ip)
                pass
            pass

        # if the netmask isn't set, make it the same as the first
        # network in the vlan the IP is in.
        if self.netmask is None:
            try:
                network = self.vlan.get_networks()[0]
            except IndexError:
                raise IndexError("VLAN %s has no networks defined" % self.vlan.number)
            self.netmask = network.netmask
コード例 #2
0
ファイル: ipaddress.py プロジェクト: jpwarren/docgen
 def configure_optional_attributes(self, node, defaults):
     XMLConfigurable.configure_optional_attributes(self, node, defaults)
     if self.type is None:
         self.type = 'primary'
         pass
     
     if self.type not in self.known_types:
         raise ValueError("IPaddress type '%s' is not a valid type" % self.type)
コード例 #3
0
ファイル: export.py プロジェクト: jpwarren/docgen
    def configure_optional_attributes(self, node, defaults):
        XMLConfigurable.configure_optional_attributes(self, node, defaults)

        # Type defaults to 'rw' if a default isn't set and it isn't manually set
        if self.type is None:
            try:
                self.type = defaults.get('export', 'default_export_type')
            except (NoSectionError, NoOptionError):
                self.type = 'rw'
                pass
            pass
コード例 #4
0
ファイル: export.py プロジェクト: jpwarren/docgen
    def configure_optional_attributes(self, node, defaults):
        XMLConfigurable.configure_optional_attributes(self, node, defaults)

        # Type defaults to 'rw' if a default isn't set and it isn't manually set
        if self.type is None:
            try:
                self.type = defaults.get('export', 'default_export_type')
            except (NoSectionError, NoOptionError):
                self.type = 'rw'
                pass
            pass
コード例 #5
0
ファイル: netinterface.py プロジェクト: jpwarren/docgen
    def configure_optional_attributes(self, node, defaults):
        XMLConfigurable.configure_optional_attributes(self, node, defaults)

        if self.mode is None:
            self.mode = 'passive'
            pass

        # Figure out the VLANs this interface should be in.
        # If one isn't defined, put it in the first VLAN for
        # the site the parent is in with the same type
        vlan_nums = node.findall('vlan_number')

        if len(vlan_nums) == 0:
            log.debug("site vlans: %s", self.parent.get_site().get_vlans())
            log.debug("my type: %s", self.type)
            self.vlans = [
                vlan for vlan in self.parent.get_site().get_vlans()
                if vlan.type == 'project'
            ]

        else:
            self.vlans = []
            for vlan_num in vlan_nums:
                self.vlans.extend([
                    vlan for vlan in self.parent.get_site().get_vlans()
                    if vlan.number == int(vlan_num.text)
                ])
                pass
            pass

        if self.mtu is not None:
            self.mtu = int(self.mtu)
        else:
            # If the MTU isn't set on the interface, try to use
            # the mtu for the VLAN it's in, if one is defined
            try:
                vlan = self.vlans[0]
                mtu = int(vlan.mtu)
            except IndexError:
                # Use the default mtu
                mtu = defaults.getint('vlan', 'default_mtu')
                pass
            pass
コード例 #6
0
ファイル: netinterface.py プロジェクト: jpwarren/docgen
    def configure_optional_attributes(self, node, defaults):
        XMLConfigurable.configure_optional_attributes(self, node, defaults)

        if self.mode is None:
            self.mode = 'passive'
            pass

        # Figure out the VLANs this interface should be in.
        # If one isn't defined, put it in the first VLAN for
        # the site the parent is in with the same type
        vlan_nums = node.findall('vlan_number')

        if len(vlan_nums) == 0:
            log.debug("site vlans: %s", self.parent.get_site().get_vlans())
            log.debug("my type: %s", self.type)
            self.vlans = [ vlan for vlan in self.parent.get_site().get_vlans() if vlan.type == 'project' ]

        else:
            self.vlans = []
            for vlan_num in vlan_nums:
                self.vlans.extend([ vlan for vlan in self.parent.get_site().get_vlans() if vlan.number == int(vlan_num.text) ])
                pass
            pass
        
        if self.mtu is not None:
            self.mtu = int(self.mtu)
        else:
            # If the MTU isn't set on the interface, try to use
            # the mtu for the VLAN it's in, if one is defined
            try:
                vlan = self.vlans[0]
                mtu = int(vlan.mtu)
            except IndexError:
                # Use the default mtu
                mtu = defaults.getint('vlan', 'default_mtu')
                pass
            pass
コード例 #7
0
ファイル: ipaddress.py プロジェクト: jpwarren/docgen
 def configure_mandatory_attributes(self, node, defaults):
     XMLConfigurable.configure_mandatory_attributes(self, node, defaults)
コード例 #8
0
ファイル: vlan.py プロジェクト: jpwarren/docgen
 def configure_optional_attributes(self, node, defaults):
     XMLConfigurable.configure_optional_attributes(self, node, defaults)
     if self.mtu is None:
         self.mtu = defaults.get('vlan', 'default_mtu')
     self.mtu = int(self.mtu)
コード例 #9
0
ファイル: vlan.py プロジェクト: jpwarren/docgen
 def configure_from_node(self, node, defaults, site):
     self.site = site
     XMLConfigurable.configure_from_node(self, node, defaults, site)