Are there Python3 libraries for the net commands and etc?

John Mulligan phlogistonjohn at asynchrono.us
Mon Mar 28 20:06:55 UTC 2022


On Monday, March 28, 2022 3:44:46 PM EDT Richard Sharpe wrote:
> On Mon, Mar 28, 2022 at 12:44 PM John Mulligan
> 
> <phlogistonjohn at asynchrono.us> wrote:
> > On Monday, March 28, 2022 12:11:18 PM EDT Jeremy Allison via
> > samba-technical> 
> > wrote:
> > > On Sun, Mar 27, 2022 at 09:21:38AM -0700, Richard Sharpe via
> > > samba-technical> 
> > wrote:
> > > >Hi folks,
> > > >
> > > >A lot of system management scripts these days are implemented in
> > > >Python and I am sick of using popen and system in python to run Samba
> > > >commands and then grub through the output to figure out what I need.
> > > >
> > > >Are there any Python3 libraries that provide the functionality of the
> > > >net commands?
> > > 
> > > I don't think so. The only python SMB stuff I'm aware of is:
> > > 
> > > https://pysmb.readthedocs.io/en/latest/
> > > 
> > > I think only Samba does the management stuff. However,
> > > most of our management stuff is drivable directly from
> > > python, as that's how we do much of the testing.
> > > 
> > > Talk to David Mulder from SuSE or some of the Catalyst
> > > Team as they know much more about this than I.
> > 
> > There's also https://github.com/hamano/pysmbc that I used in past
> > projects. It uses libsmbclient, rather than being pure python.
> > 
> > However, I do think Richard Sharpe meant management stuff. I am also very
> > interested in doing less fork/exec/parse and make more use of samba
> > library
> > bindings for our `sambacc` project. Personally, I keep meaning to spend
> > some time digging around in the samba-tool code. Since there's some
> > overlap there with `net` around things like domain join, even for
> > non-AD-DC servers, I think there *are* some existing libs to do a lot of
> > these actions. However, the documentation is missing/not obvious. One of
> > my big stumbling blocks when I see a package/api that seems to be
> > something I want there's often a lack of clarity around how to make use
> > of it due to stuff like undocumented arguments & some magic numeric
> > constants, etc. However, its been some months since I last looked so
> > things may have improved too... so take this with a grain of salt.
> > 
> > There was also an effort to add JSON to some of the commands. If smbstatus
> > and/ or other commands had JSON output we don't have to do low-level
> > parsing of output, even if we still need to fork/exec/read. My team was
> > interested in this but we didn't have sufficient bandwidth to actively
> > pursue it ourselves. However, a teammate alerted me to a new MR on the
> > subject earlier today:
> > https://gitlab.com/samba-team/samba/-/merge_requests/2449
> > 
> > Anyway, I just wanted to reply to say that Richard isn't the only person
> > interested in this kind of thing. :-)
> 
> To be more specific, here is what I am interested in:
> 
> A python (3) library that provides things like:


You motivated me to look a bit. Note I have zero idea if any of this works or 
works for a domain member server (vs. a DC server). I am just looking around 
in the sources:

> 
> smb_mgmt_net_ads_join/smb_mgmt_net_ads_leave

samba.netcmd.domain.cmd_domain_join

samba.netcmd.domain.cmd_domain_leave

(Where samba.netcmd.domain modules are imported first. The sources are in 
python/samba/netcmd/domain.py the samba tree)


> smb_mgmt_net_ads_status

Unlike the above two, nothing jumped out at me immediately for this one.

> smb_mgmt_net_conf_list
> smb_mgmt_net_conf_setparm
> 

I also want these, along with a `net conf import` api equivalent. :-)
I have not seen a wrapper for these, but I may need to look deeper.

> and every thing else :-)

Of course!  :-D







More information about the samba-technical mailing list