Giter Site home page Giter Site logo

egberts / iscpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from utamid/iscpy_modified

0.0 1.0 4.0 1.09 MB

iscpy python3 library. Read and write to ISC-styled configuration file (DHCP, BIND)

License: Other

Python 78.45% Red 21.55%
iscpy python3 configuration-file bind9 isc-dhcp-server isc-dhcp config bind python parser parser-library dns isc

iscpy's Introduction

python3-iscpy

iscpy Python3 library. Reads and writes ISC-syled configuration files such as ISC BIND8/BIND9 and ISC-DHCP server/client. Additional features such as adding zone and write to file

Usage

ParseISCString(isc_string)

Returns parsed bind config file in python dictionary format(ISC dictionary) and keys without childkeys e.g. include

AddZone(json_zone, isc_dict)

Adding zone. Input is in json string. Returns ISC dictionary with added zone. This method doesn't include writing to output file

WriteToFile(isc_dict, isc_specialkeys, filename)

Write ISC dictionary to a file

iscpy's People

Contributors

utamid avatar egberts avatar ali-heidari avatar

Watchers

 avatar

iscpy's Issues

iscpy_core and submodule 'dns'

During the port from Python2 to Python3 using futurize utitlity (from future Python package, I got the following error after build and install:

Assumes python3 selected on Debian (via update-alternatives utility):

git clone https://github.com/egberts/iscpy
cd iscpy
python setup.py build
python setup.py install --user
cd test
~/iscpy$ python named_importer_lib_regtest.py 

Result is:

Traceback (most recent call last):
  File "named_importer_lib_regtest.py", line 46, in <module>
    import iscpy
  File "/home/steve/.local/lib/python3.5/site-packages/iscpy-1.8-py3.5.egg/iscpy/__init__.py", line 38, in <module>
    from iscpy_core.core import *
ImportError: No module named 'iscpy_core'

File in question is: iscpy/init.py
Module in question is: iscpy/iscpy/iscpy_core
Original Python2 statement in question:

from iscpy_core.core import *
import iscpy_dns.named_importer_lib as dns

New Python3 statement (as futurize recommended)

from __future__ import absolute_import
from .iscpy_core.core import *
from . import iscpy_dns.named_importer_lib as dns

Parser returns last 2 entries

I have dhcp_static.conf which has 118 IP assigments and i want to parse with python. This file will be included in dhcpd.conf file.

dhcp_static.conf

host host_0 {
  hardware ethernet 18:DB:F2:5E:00:00;
  fixed-address 10.12.24.81;
}
host host_1 {
  hardware ethernet D4:AE:52:BD:00:00;
  fixed-address 10.12.42.1;
}

... (many more) ...

host host_118 {
  hardware ethernet DC:A6:32:B7:00:00;
  fixed-address 10.12.67.22;
}

assigments.py (my script)

import os, types, iscpy

NAMED_FILE = 'dhcp_static.conf'

named_file = open(NAMED_FILE).read()
# print("named_file:",named_file)

isc_arr = iscpy.ParseISCString(named_file)
print(isc_arr)

Result:

$ python assigments.py 
[{'host host_117': {'hardware': 'ethernet 18:DB:F2:5E:00:00', 'fixed-address': '10.12.24.81'}}, {'host host_118': {'hardware': 'ethernet DC:A6:32:B7:00:00', 'fixed-address': '10.12.67.22'}}]

If i uncomment printing named_file then i see whole file. So it means that the problem lies in parser.

Additional info:

$ python --version
Python 3.8.10
$ pip freeze
certifi==2021.10.8
charset-normalizer==2.0.10
idna==3.3
iscpy==1.8
openssh-wrapper==0.4
proxmoxer==1.2.0
requests==2.27.1
urllib3==1.26.8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.