New GROUPS API and Groups CLI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi ML,

In last a few days i've been working on new pluggable groups api.
The public group code is now independent from the backend of the 
groups. Current code supports 2 backends :
  - Configuration file (the old one)
  - sqlite backend

The default groups backend is configuration file for now because
it is a little bit faster than sqlite backend.If you need to change
to sqlite backend what you need to do is go to : /etc/func/overlord.conf
and change:
  backend = sqlite
  group_db = /path/you/want


A new addition is groups cli, we will be able to control groups api
via cli with new stuff. Let see some cli examples :

(For testing purposes i added 100 test nonexisting minions range(100))
---------------------------------------------------------------------
Listing all of the current stuff
[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 1
         Host : 3
         Host : 2
         Host : 5
         Host : 4
-----------------------------------------------------------------------
Adding a new group :
[root@fedorabig func]# func "*" group --ag "newgr"
[root@fedorabig func]#

[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 1
         Host : 3
         Host : 2
         Host : 5
         Host : 4
Group : newgr
----------------------------------------------------------------------
Listing some of the groups by glob:
[root@fedorabig func]# func "*" group --lg "gr*"
GROUPS :
          ['group5']
[root@fedorabig func]#
-----------------------------------------------------------------------
Removing a group

[root@fedorabig func]# func "*" group --ag "tmpgr1"
[root@fedorabig func]# func "*" group --ag "tmpgr2"
[root@fedorabig func]# func "*" group --ag "tmpgr3"
[root@fedorabig func]# func "*" group --lg "*"
GROUPS :
          ['group5', 'newgr', 'tmpgr2', 'tmpgr3', 'tmpgr1']
[root@fedorabig func]# func "*" group --rg "tmpgr1"
[root@fedorabig func]# func "*" group --lg "*"
GROUPS :
          ['group5', 'newgr', 'tmpgr2', 'tmpgr3']
----------------------------------------------------------------------
Removing groups by globbing :
[root@fedorabig func]# func "*" group --rg "tmp*"
[root@fedorabig func]# func "*" group --lg "*"
GROUPS :
          ['group5', 'newgr']

----------------------------------------------------------------------
Adding hosts in group by globbing: (adding host from 0-9 in groups)

[root@fedorabig func]# func "*" group --ah "@group5:[0-9]"
[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 1
         Host : 0
         Host : 3
         Host : 2
         Host : 5
         Host : 4
         Host : 7
         Host : 6
         Host : 9
         Host : 8
Group : newgr


--------------------------------------------------------------------

Adding hosts in group by globbing with exclusion :

[root@fedorabig func]# func "*" group --e "@group:[1][2,4]" --ah "@group5:[1]
[0-5]"
[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 1
         Host : 0
         Host : 3
         Host : 2
         Host : 5
         Host : 4
         Host : 7
         Host : 6
         Host : 9
         Host : 8
         Host : 11
         Host : 10
         Host : 13
         Host : 15
Group : newgr

In above example we added all [1][0-5] and excluded [1][2,4] with that option
we dont need anymore the need of subgrouping, we subgroup on the fly :)

--------------------------------------------------------------------------
Listing hosts via globbing :

[root@fedorabig func]# func "*" group --lh "@group5"
['11', '10', '13', '15', '1', '0', '3', '2', '5', '4', '7', '6', '9', '8']
[root@fedorabig func]# func "*" group --lh "@group5:[1][0-5]"
['11', '10', '13', '15']

Example of exclusion :
[root@fedorabig func]# func "*" group --e "@group5:[1,3,5,7,9]" --lh 
"@group5:*"
['11', '10', '13', '15', '0', '2', '4', '6', '8']

--------------------------------------------------------------------------

Removing hosts from a group via globbing :
[root@fedorabig func]# func "*" group --rh "@group5:[1-5]"
[root@fedorabig func]# func "*" group --lh "@group5:*"
['11', '10', '13', '15', '0', '7', '6', '9', '8']

Removing hosts via exclusion:
[root@fedorabig func]# func "*" group --e "@group5:[0,2,4,6,8]" --rh 
"@group5:*"
[root@fedorabig func]# func "*" group --lh "@group5:*"
['0', '8', '6']

-------------------------------------------------------------------------------
You can also do the above operations on multiple groups at the same cli:

Adding on multiple groups :

[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 0
         Host : 6
         Host : 8
Group : newgr

[root@fedorabig func]# func "*" group --ah "@group5:[1][5-9];@newgr:[2][0-5]"
[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 0
         Host : 6
         Host : 8
         Host : 19
         Host : 18
         Host : 15
         Host : 17
         Host : 16
Group : newgr
         Host : 24
         Host : 25
         Host : 20
         Host : 21
         Host : 22
         Host : 23

Listing on multiple 

root@fedorabig func]# func "*" group --lh "@group5:[1][5-9];@newgr:[2][0-5]"
['24', '25', '23', '15', '21', '17', '16', '19', '18', '22', '20']

Removing on multiple:

[root@fedorabig func]# func "*" group --rh "@group5:[1][5-9];@newgr:[2][0-5]"
[root@fedorabig func]# func "*" group --la
Group : group5
         Host : 0
         Host : 6
         Host : 8
Group : newgr

You can also use the --exclude keyword when working on multiple groups,but you 
should be
sure that the number of operations match. If you work on 3 groups you should 
have 3 groups
on exclude parameter also.

------------------------------------------------------------------------------------------------
ADDING NEW BACKENDS : 

Adding new backends to groups shouldnt be hard what you need to do is just :
  -put a file in /func/overlord/group directory
  -extend the class /func/overlord/group/base.py BaseBackend and implement all 
of its methods
  -add your backend into choose_backend method in /func/overlord/group/base.py
  - add your backend into /test/unittests/test_groups_api.py if it passes all 
the tests you have a
  new backend :)

-------------------------------------------------------------------------------------------------

For those who may want to try new api : 
http://github.com/makkalot/func/tree/group

Comments,ideas ? 

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux