Exemplo n.º 1
0
 def build_subnet(self, raw=False):
     self.update_network()
     statements = self.networkav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     options = self.networkav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     ranges = self.range_set.filter(range_type=DYNAMIC, dhcp_enabled=True)
     if self.ip_type == IP_TYPE_4:
         build_str = "\nsubnet {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     else:
         build_str = "\nsubnet6 {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     if not raw:
         build_str += "\t# Network statements\n"
         build_str += join_dhcp_args(statements)
         build_str += "\t# Network options\n"
         build_str += join_dhcp_args(options)
         if self.dhcpd_raw_include:
             build_str += "\t# Raw network options\n"
             build_str += join_dhcp_args(self.dhcpd_raw_include.split("\n"))
     for range_ in ranges:
         build_str += range_.build_range()
     build_str += "}\n"
     return build_str
Exemplo n.º 2
0
    def build_workgroup(self):
        from cyder.cydhcp.interface.static_intr.models import StaticInterface
        from cyder.cydhcp.interface.dynamic_intr.models import DynamicInterface
        build_str = ""
        dynamic_clients = DynamicInterface.objects.filter(
            workgroup=self, dhcp_enabled=True)
        static_clients = StaticInterface.objects.filter(
            workgroup=self, dhcp_enabled=True)
        #if not (static_clients or dynamic_clients):
            #return build_str
        build_str += "group {{ #{0}\n".format(self.name)
        statements = self.workgroupav_set.filter(
            attribute__attribute_type=ATTRIBUTE_STATEMENT)
        options = list(self.workgroupav_set.filter(
            attribute__attribute_type=ATTRIBUTE_OPTION))

        def is_host_option(option):
            return any(x in option.value for x in ['%h', '%i', '%m', '%6m'])

        host_options = filter(is_host_option, options)
        for x in host_options:
            options.remove(x)

        build_str += "\t# Workgroup Options\n"
        if options:
            build_str += join_dhcp_args(options)
        build_str += "\t# Workgroup Statements\n"
        if statements:
            build_str += join_dhcp_args(statements)
        build_str += "\t# Static Hosts in Workgroup\n"
        for client in chain(dynamic_clients, static_clients):
            build_str += client.build_host(host_options)
        build_str += "}\n"
        return build_str
Exemplo n.º 3
0
 def build_subnet(self, raw=False):
     self.update_network()
     statements = self.networkav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     options = self.networkav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     ranges = self.range_set.filter(range_type=DYNAMIC, dhcp_enabled=True)
     if self.ip_type == IP_TYPE_4:
         build_str = "\nsubnet {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     else:
         build_str = "\nsubnet6 {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     if not raw:
         build_str += "\t# Network statements\n"
         build_str += join_dhcp_args(statements)
         build_str += "\t# Network options\n"
         build_str += join_dhcp_args(options)
         if self.dhcpd_raw_include:
             build_str += "\t# Raw network options\n"
             build_str += join_dhcp_args(self.dhcpd_raw_include.split("\n"))
     for range_ in ranges:
         build_str += range_.build_range()
     build_str += "}\n"
     return build_str
Exemplo n.º 4
0
 def build_host(self):
     build_str = "\thost {0} {{\n".format(self.get_fqdn())
     build_str += "\t\thardware ethernet {0};\n".format(self.mac)
     options = self.dynamicintrkeyvalue_set.filter(is_option=True)
     statements = self.dynamicintrkeyvalue_set.filter(is_statement=True)
     if options:
         build_str += "\t\t# Host Options\n"
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += "\t\t# Host Statemets\n"
         build_str += join_dhcp_args(statements, depth=2)
     build_str += "\t}\n\n"
     return build_str
Exemplo n.º 5
0
 def build_host(self, options=()):
     build_str = "\thost {0} {{\n".format(self.get_fqdn())
     build_str += "\t\thardware ethernet {0};\n".format(self.mac)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     build_str += "\t}\n"
     return build_str
Exemplo n.º 6
0
 def build_host(self):
     build_str = '\thost {0} {{\n'.format(self.fqdn)
     build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
     if self.ip_type == IP_TYPE_6:
         build_str += '\t\tfixed-address6 {0};\n'.format(self.ip_str)
     else:
         build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
     options = self.staticintrkeyvalue_set.filter(is_option=True)
     statements = self.staticintrkeyvalue_set.filter(is_statement=True)
     if options:
         build_str += '\t\t# Host Options\n'
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += '\t\t# Host Statements\n'
         build_str += join_dhcp_args(statements, depth=2)
     build_str += '\t}\n\n'
     return build_str
Exemplo n.º 7
0
 def build_host(self, options=()):
     build_str = "\thost {0} {{\n".format(self.get_fqdn())
     build_str += "\t\thardware ethernet {0};\n".format(self.mac)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     options = self.dynamicinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     statements = self.dynamicinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     if options:
         build_str += "\t\t# Host Options\n"
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += "\t\t# Host Statemets\n"
         build_str += join_dhcp_args(statements, depth=2)
     build_str += "\t}\n"
     return build_str
Exemplo n.º 8
0
 def build_host(self, options=()):
     build_str = "\thost {0} {{\n".format(self.get_fqdn())
     build_str += "\t\thardware ethernet {0};\n".format(self.mac)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     options = self.dynamicinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     statements = self.dynamicinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     if options:
         build_str += "\t\t# Host Options\n"
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += "\t\t# Host Statemets\n"
         build_str += join_dhcp_args(statements, depth=2)
     build_str += "\t}\n"
     return build_str
Exemplo n.º 9
0
 def build_host(self):
     build_str = '\thost {0} {{\n'.format(self.fqdn)
     build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
     if self.ip_type == IP_TYPE_6:
         build_str += '\t\tfixed-address6 {0};\n'.format(self.ip_str)
     else:
         build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
     options = self.staticintrkeyvalue_set.filter(is_option=True)
     statements = self.staticintrkeyvalue_set.filter(is_statement=True)
     if options:
         build_str += '\t\t# Host Options\n'
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += '\t\t# Host Statements\n'
         build_str += join_dhcp_args(statements, depth=2)
     build_str += '\t}\n\n'
     return build_str
Exemplo n.º 10
0
 def build_workgroup(self):
     build_str = ""
     static_clients = self.staticinterface_set.all()
     dynamic_clients = self.dynamicinterface_set.all()
     if not (static_clients or dynamic_clients):
         return build_str
     build_str += "group {\n"
     statements = self.workgroupkeyvalue_set.filter(is_statement=True)
     options = self.workgroupkeyvalue_set.filter(is_option=True)
     build_str += "\t# Workgroup Options\n"
     build_str += join_dhcp_args(options)
     build_str += "\t# Workgroup Statements\n"
     build_str += join_dhcp_args(statements)
     build_str += "\t# Static Hosts in Workgorup\n"
     for client in chain(dynamic_clients, static_clients):
         build_str += client.build_host()
     build_str += "}\n"
     return build_str
Exemplo n.º 11
0
 def build_workgroup(self):
     build_str = ""
     static_clients = self.staticinterface_set.all()
     dynamic_clients = self.dynamicinterface_set.all()
     if not (static_clients or dynamic_clients):
         return build_str
     build_str += "group {\n"
     statements = self.workgroupkeyvalue_set.filter(is_statement=True)
     options = self.workgroupkeyvalue_set.filter(is_option=True)
     build_str += "\t# Workgroup Options\n"
     build_str += join_dhcp_args(options)
     build_str += "\t# Workgroup Statements\n"
     build_str += join_dhcp_args(statements)
     build_str += "\t# Static Hosts in Workgorup\n"
     for client in chain(dynamic_clients, static_clients):
         build_str += client.build_host()
     build_str += "}\n"
     return build_str
Exemplo n.º 12
0
 def build_host(self, options=None):
     build_str = '\thost {0} {{\n'.format(self.fqdn)
     build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
     if self.ip_type == IP_TYPE_6:
         build_str += '\t\tfixed-address6 {0};\n'.format(self.ip_str)
     else:
         build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     build_str += '\t}\n'
     return build_str
Exemplo n.º 13
0
 def build_host(self, options=None):
     build_str = '\thost {0} {{\n'.format(self.fqdn)
     build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
     if self.ip_type == IP_TYPE_6:
         build_str += '\t\tfixed-address6 {0};\n'.format(self.ip_str)
     else:
         build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     options = self.staticinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     statements = self.staticinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     if options:
         build_str += '\t\t# Host Options\n'
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += '\t\t# Host Statements\n'
         build_str += join_dhcp_args(statements, depth=2)
     build_str += '\t}\n'
     return build_str
Exemplo n.º 14
0
 def build_host(self, options=None):
     build_str = '\thost {0} {{\n'.format(self.fqdn)
     build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
     if self.ip_type == IP_TYPE_6:
         build_str += '\t\tfixed-address6 {0};\n'.format(self.ip_str)
     else:
         build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
     build_str += join_dhcp_args(map(self.format_host_option, options),
                                 depth=2)
     options = self.staticinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_OPTION)
     statements = self.staticinterfaceav_set.filter(
         attribute__attribute_type=ATTRIBUTE_STATEMENT)
     if options:
         build_str += '\t\t# Host Options\n'
         build_str += join_dhcp_args(options, depth=2)
     if statements:
         build_str += '\t\t# Host Statements\n'
         build_str += join_dhcp_args(statements, depth=2)
     build_str += '\t}\n'
     return build_str
Exemplo n.º 15
0
 def build_subnet(self, raw=False):
     self.update_network()
     statements = self.networkkeyvalue_set.filter(is_statement=True)
     options = self.networkkeyvalue_set.filter(is_option=True)
     ranges = self.range_set.all()
     if self.ip_type == IP_TYPE_4:
         build_str = "\nsubnet {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     else:
         build_str = "\nsubnet6 {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     if not raw:
         build_str += "\t# Network Statements\n"
         build_str += join_dhcp_args(statements)
         build_str += "\t# Network Options\n"
         build_str += join_dhcp_args(options)
         if self.dhcpd_raw_include:
             build_str += "\t# Raw Network Options\n"
             build_str += join_dhcp_args(self.dhcpd_raw_include.split("\n"))
     for range_ in ranges:
         build_str += range_.build_range()
     build_str += "}\n"
     return build_str
Exemplo n.º 16
0
 def build_subnet(self, raw=False):
     self.update_network()
     statements = self.networkkeyvalue_set.filter(is_statement=True)
     options = self.networkkeyvalue_set.filter(is_option=True)
     ranges = self.range_set.all()
     if self.ip_type == IP_TYPE_4:
         build_str = "\nsubnet {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     else:
         build_str = "\nsubnet6 {0} netmask {1} {{\n".format(
             self.network.network, self.network.netmask)
     if not raw:
         build_str += "\t# Network Statements\n"
         build_str += join_dhcp_args(statements)
         build_str += "\t# Network Options\n"
         build_str += join_dhcp_args(options)
         if self.dhcpd_raw_include:
             build_str += "\t# Raw Network Options\n"
             build_str += join_dhcp_args(self.dhcpd_raw_include.split("\n"))
     for range_ in ranges:
         build_str += range_.build_range()
     build_str += "}\n"
     return build_str