s3:vfs:gpfs: remove all writing uses of stat_ex.vfs_private from vfs_gpfs.
[Samba.git] / python / samba / hostconfig.py
bloba66fbc231301ca4b22267c1b70c589eab7181765
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Local host configuration."""
20 from samdb import SamDB
22 class Hostconfig(object):
23 """Aggregate object that contains all information about the configuration
24 of a Samba host."""
26 def __init__(self, lp):
27 self.lp = lp
29 def get_shares(self):
30 return SharesContainer(self.lp)
32 def get_samdb(self, session_info, credentials):
33 """Access the SamDB host.
35 :param session_info: Session info to use
36 :param credentials: Credentials to access the SamDB with
37 """
38 return SamDB(url=self.lp.samdb_url(),
39 session_info=session_info, credentials=credentials,
40 lp=self.lp)
43 # TODO: Rather than accessing Loadparm directly here, we should really
44 # have bindings to the param/shares.c and use those.
47 class SharesContainer(object):
48 """A shares container."""
50 def __init__(self, lp):
51 self._lp = lp
53 def __getitem__(self, name):
54 if name == "global":
55 # [global] is not a share
56 raise KeyError
57 return Share(self._lp[name])
59 def __len__(self):
60 if "global" in self._lp.services():
61 return len(self._lp)-1
62 return len(self._lp)
64 def keys(self):
65 return [name for name in self._lp.services() if name != "global"]
67 def __iter__(self):
68 return iter(self.keys())
71 class Share(object):
72 """A file share."""
74 def __init__(self, service):
75 self._service = service
77 def __getitem__(self, name):
78 return self._service[name]
80 def __setitem__(self, name, value):
81 self._service[name] = value