Sounds cool, you have it up anywhere (gihub/bitbucket/googlecode/etc)? goose
On Thu, Nov 18, 2010 at 10:04:26PM +0000, Michael Gliwinski wrote: > Hello fab(ulous) people! > > I've been using Fabric for a while now but am new to the list. I'm just > catching up with archives and I've noticed that the question of loading roles > from external sources sometimes pops up. > > I have this class which I use in my fabfiles that I thought could be useful > to > some, and if it would, I can submit a patch to put it in contrib or even > directly in fabric.state. > > Basically, the class inherits from the builtin dict and behaves like a normal > dictionary with additional option to load data from external source. A list > of sources can be passed to load_from method and the first available (i.e. > first one which returns without raising exception) will be used. > > A source can be a local path to file, a URL or a callable which should return > a mapping of roles to host lists. > > In my implementation data from file or URL is expected to be in YAML format, > but since this would mean additional dependency I can change it to something > else. > > In any case the source_loader attribute can also be reassigned to a custom > function that loads other formats. > > For example, given a file 'roles.yml' with contents: 'foo: [bar, baz]\n': > > >>> r = RoleDefs() > >>> r.load_from(['nonexistent.yml', 'roles.yml']) > >>> r['foo'] > ['bar', 'baz'] > > The source is loaded "lazily" - only when the first missing key is accessed > which means an instance of RoleDefs can be assigned to env.roledefs without > causing delay on every fab invocation. > > My usecase for this is that I usually export the roles (or access them > directly) from Spacewalk/Cobbler, but sometimes e.g. when I'm working over > VPN > I have to connect through SSH tunnels (port redirs) through a gateway, so I > have a local file with some roles redefined in terms of those redirections. > > Anyways, if you're interested I can do something about getting that into > Fabric. Let me know sure. > > Thanks for the great work! > > Michael > > > -- > Michael Gliwinski > Henderson Group Information Services > 9-11 Hightown Avenue, Newtownabby, BT36 4RT > Phone: 028 9034 3319 > > -- > Michael Gliwinski > Henderson Group Information Services > 9-11 Hightown Avenue, Newtownabby, BT36 4RT > Phone: 028 9034 3319 > > ********************************************************************************************** > The information in this email is confidential and may be legally privileged. > It is intended solely for the addressee and access to the email by anyone > else is unauthorised. > If you are not the intended recipient, any disclosure, copying, distribution > or any action taken or omitted to be taken in reliance on it, is prohibited > and may be unlawful. > When addressed to our clients, any opinions or advice contained in this > e-mail are subject to the terms and conditions expressed in the governing > client engagement leter or contract. > If you have received this email in error please notify > [email protected] > > John Henderson (Holdings) Ltd > Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern > Ireland, BT36 4RT. > Registered in Northern Ireland > Registration Number NI010588 > Vat No.: 814 6399 12 > ********************************************************************************* > > > _______________________________________________ > Fab-user mailing list > [email protected] > http://lists.nongnu.org/mailman/listinfo/fab-user ---end quoted text--- _______________________________________________ Fab-user mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/fab-user
