RE: python-cephclient for Mgr/RESTful plugin

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

 



Thanks Jianpeng. It works to change ceph config value with "request" in RESTful plugin.

-----Original Message-----
From: Ma, Jianpeng 
Sent: Friday, January 18, 2019 2:22 PM
To: Liu, Changcheng <changcheng.liu@xxxxxxxxx>; Boris Ranto <branto@xxxxxxxxxx>
Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
Subject: RE: python-cephclient for Mgr/RESTful plugin

Hi Changcheng:
    Using those command: json={'prefix':'config get', 'who': 'mon.xx'} can get result like CLI: ceph config get mon.xxx.
   I from mon.xxx log to know the request command how to write. So you can us this method .
    Hope this method can help you.

Thanks!
Jianpeng

> -----Original Message-----
> From: ceph-devel-owner@xxxxxxxxxxxxxxx [mailto:ceph-devel- 
> owner@xxxxxxxxxxxxxxx] On Behalf Of Liu, Changcheng
> Sent: Friday, January 18, 2019 1:23 PM
> To: Boris Ranto <branto@xxxxxxxxxx>
> Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> Subject: RE: python-cephclient for Mgr/RESTful plugin
> 
> Thanks Boris. It helps me a lot.
> Currently, I'm checking all the endpoint implemented in ceph-rest-api 
> and going to replace them with "request" in RESTful plugin.
> I'm wondering whether RESTful "request" could config ceph cluster. 
> I'll check them one by one.
> 
> -----Original Message-----
> From: ceph-devel-owner@xxxxxxxxxxxxxxx [mailto:ceph-devel- 
> owner@xxxxxxxxxxxxxxx] On Behalf Of Boris Ranto
> Sent: Thursday, January 17, 2019 9:21 PM
> To: Liu, Changcheng <changcheng.liu@xxxxxxxxx>
> Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> Subject: Re: python-cephclient for Mgr/RESTful plugin
> 
> Hi,
> 
> yes, you are right that there is no 'df' endpoint (*). However, the 
> ceph-rest- api is supposed to be superseded by the /request endpoint 
> that allows you to schedule any monitor command (you are mostly on 
> your own if you do and you will need to dig a bit into the ceph 
> internals though). The 'df' monitor command is defined, here:
> 
> https://github.com/ceph/ceph/blob/master/src/mon/MonCommands.h#L21
> 5
> 
> i.e. it is defined as
> 
> COMMAND("df name=detail,type=CephChoices,strings=detail,req=false", \ 
> "show cluster free space stats", "mon", "r")
> 
> From its definition you know that the command prefix is 'df' and the 
> command takes an optional argument 'detail' that can take a string 
> value 'detail' (sadly, only this value is supported for the 'df'
> command but generally, these can be set as "strings=a|b|c" and you can 
> use any of the several values).
> 
> This translates to the following series of python commands (if you 
> omit the 'detail' optional argument, you will get less detailed
> output) :
> 
> >>> import requests
> >>> _auth = ('admin', '...')
> >>> result = requests.post('https://node2:8003/request?wait=1',
> >>> json={'prefix': 'df', 'detail': 'detail'}, auth=_auth, 
> >>> verify=False)
> 
> Since I added 'wait=1' to the requests url, I can safely assume that 
> the returned request has already finished (the default is to return 
> the request as soon as it is scheduled, you would need to poll the 
> /request/<id> endpoint to see if the request has already finished).
> Afterwards, you can parse the returned json:
> 
> >>> result.json()
> {u'waiting': [], u'has_failed': False, u'state': u'success',
> u'is_waiting': False, u'running': [], u'failed': [], u'finished':
> [{u'outb': u'GLOBAL:\n    SIZE        AVAIL       RAW USED     %RAW
> USED     OBJECTS \n    27.0GiB     26.6GiB       327MiB          1.18
>         14 \nPOOLS:\n    NAME                    ID     QUOTA OBJECTS
>    QUOTA BYTES     USED        %USED     MAX AVAIL     OBJECTS
> DIRTY     READ     WRITE     RAW USED \n    .rgw.root               1
>     N/A               N/A             1.09KiB         0       8.43GiB
>          4         4       0B        4B      3.26KiB \n
> default.rgw.control     2      N/A               N/A
> 0B         0       8.43GiB           8         8       0B        0B
>        0B \n    default.rgw.meta        3      N/A               N/A
>              385B         0       8.43GiB           2         2
> 50B       27B      1.13KiB \n    default.rgw.log         4      N/A
>            N/A                  0B         0       8.43GiB           0
>         0       0B        0B           0B \n', u'outs': u'',
> u'command': u'df detail=detail'}], u'is_finished': True, u'id':
> u'140213198704912'}
> 
> You can see here, that you got a request in a finished state that did 
> not fail and it has scheduled a signle monior command ('df'). Its 
> output ('outb') is what you are looking for -- depending on the 
> monitor command and the state of the request 'outb' or 'outs' can be 
> populated. Afterwards, you can get the output from the request this way (if it did not fail):
> 
> >>> print result.json()['finished'][0]['outb']
> GLOBAL:
>     SIZE        AVAIL       RAW USED     %RAW USED     OBJECTS
>     27.0GiB     26.6GiB       327MiB          1.18          14
> POOLS:
>     NAME                    ID     QUOTA OBJECTS     QUOTA BYTES
> USED        %USED     MAX AVAIL     OBJECTS     DIRTY     READ
> WRITE     RAW USED
>     .rgw.root               1      N/A               N/A
> 1.09KiB         0       8.43GiB           4         4       0B
> 4B      3.26KiB
>     default.rgw.control     2      N/A               N/A
>    0B         0       8.43GiB           8         8       0B        0B
>           0B
>     default.rgw.meta        3      N/A               N/A
>  385B         0       8.43GiB           2         2      50B       27B
>      1.13KiB
>     default.rgw.log         4      N/A               N/A
>    0B         0       8.43GiB           0         0       0B        0B
>           0B
> 
> Here, you are accessing the returned json data, looking at the 
> scheduled commands that have been 'finished', checking the 'outb' of 
> the only scheduled monitor command ([0]).
> 
> Hope it helps,
> Boris
> 
> On Thu, Jan 17, 2019 at 8:28 AM Liu, Changcheng 
> <changcheng.liu@xxxxxxxxx> wrote:
> >
> > Hi Boris,
> >      I've created key for admin user and could use the 
> > username:password to
> access to RESTful plugin now.
> >      There's some interface of ceph-rest-api doesn't exist on 
> > RESTful plugin,
> such as:
> >         ceph-rest-api: http://host-name:port/api/v0.1/df
> >      It's used to get df result on ceph.
> >      How to get the same/similar result in RESTful plugin? There's no "df"
> endpoint in RESTful plugin which only include below endpoints:
> >          /config/cluster: GET
> >          /config/osd: GET, PATCH
> >          /crush/rule: GET
> >          /mon: GET
> >          /osd: GET
> >         /pool: GET, POST
> >         /pool/<arg>: DELETE, GET, PATCH
> >          /request: DELETE, GET, POST
> >         /request/<arg>: DELETE, GET
> >         /server: GET
> >      How to set <arg> for pool & request endpoint? Is there any good
> reference?
> >
> > B.R.
> > Changcheng
> >
> >
> > -----Original Message-----
> > From: Liu, Changcheng
> > Sent: Wednesday, January 16, 2019 10:53 PM
> > To: Boris Ranto <branto@xxxxxxxxxx>
> > Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> > Subject: RE: python-cephclient for Mgr/RESTful plugin
> >
> > Thanks Boris. I'll use the (user, pwd) to do further work.
> >
> > -----Original Message-----
> > From: Boris Ranto [mailto:branto@xxxxxxxxxx]
> > Sent: Wednesday, January 16, 2019 9:45 PM
> > To: Liu, Changcheng <changcheng.liu@xxxxxxxxx>
> > Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> > Subject: Re: python-cephclient for Mgr/RESTful plugin
> >
> > Most of the endpoints in the restful module are authenticated (the 
> > only
> exception being the root '/' endpoint). This is by design to forbid 
> access to unauthorized personnel. That means that you always need to 
> send an authenticated request.
> >
> > You can simplify this by storing the (user, pwd) tuple in a tuple 
> > and passing
> the tuple to the request or writing a simple wrapper function that 
> would do that for you.
> >
> > Alternatively, you should be able to employ cookies (afaik, that is 
> > what a
> browser does when you authenticate) for this sort of thing but it is 
> probably easier to achieve this by the wrapper or stored tuple in Python.
> >
> > -boris
> >
> > On Wed, Jan 16, 2019 at 1:20 PM Liu, Changcheng
> <changcheng.liu@xxxxxxxxx> wrote:
> > >
> > > Hi Boris,
> > >      I've read below file:
> > >          1) 
> > > http://docs.ceph.com/docs/master/mgr/restful/#the-request-
> endpoint
> > >          2)
> https://github.com/ceph/ceph/blob/master/qa/workunits/rest/test_mgr_re
> s
> t_api.py
> > >      Do you know how to avoid input password to RESTful plugin to
> execute monitor commands?
> > >      I must give user-“admin” and password 
> > > "24b21975-640e-4880-9334-
> 3fa22c3ab409" to access to RESTful plugin. I want to access to it 
> directly without giving these info.
> > > [wrsroot@controller-0 usr(keystone_admin)]$ ceph mgr services {
> > >     "restful": "https://controller-0:5001/";
> > > }
> > > [wrsroot@controller-0 usr(keystone_admin)]$ ceph restful list-keys {
> > >   "admin": "24b21975-640e-4880-9334-3fa22c3ab409"
> > > }
> > >
> > > B.R.
> > > Changcheng
> > >
> > > -----Original Message-----
> > > From: ceph-devel-owner@xxxxxxxxxxxxxxx 
> > > [mailto:ceph-devel-owner@xxxxxxxxxxxxxxx] On Behalf Of Boris Ranto
> > > Sent: Wednesday, January 16, 2019 7:20 PM
> > > To: Liu, Changcheng <changcheng.liu@xxxxxxxxx>
> > > Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> > > Subject: Re: python-cephclient for Mgr/RESTful plugin
> > >
> > > Glad to hear that :)
> > >
> > > Also, if you are looking into a higher coverage by the restful 
> > > module, I
> recommend looking into the /request endpoint as documented, here:
> > >
> > > http://docs.ceph.com/docs/master/mgr/restful/#the-request-endpoint
> > >
> > > That should allow you to schedule any monitor command but you will
> need to parse everything yourself and the backwards compatibility is 
> not guaranteed there.
> > >
> > > -boris
> > >
> > > On Wed, Jan 16, 2019 at 7:18 AM Liu, Changcheng
> <changcheng.liu@xxxxxxxxx> wrote:
> > > >
> > > > Thanks Boris. It's very helpful.
> > > >
> > > > -----Original Message-----
> > > > From: Boris Ranto [mailto:branto@xxxxxxxxxx]
> > > > Sent: Wednesday, January 16, 2019 12:16 AM
> > > > To: Liu, Changcheng <changcheng.liu@xxxxxxxxx>
> > > > Cc: ceph-devel <ceph-devel@xxxxxxxxxxxxxxx>
> > > > Subject: Re: python-cephclient for Mgr/RESTful plugin
> > > >
> > > > I am not aware of any such wrapper but you can look at the qa
> workunit for the restful module for the tips on how to use it from Python:
> > > >
> > > > https://github.com/ceph/ceph/blob/master/qa/workunits/rest/test_
> > > > mg
> > > > r_
> > > > re
> > > > st_api.py
> > > >
> > > > -boris
> > > >
> > > > On Mon, Jan 14, 2019 at 8:01 AM Liu, Changcheng
> <changcheng.liu@xxxxxxxxx> wrote:
> > > > >
> > > > > Hi all,
> > > > >    In Jewel version, there's python-cephclient as below to operate
> > > > >    ceph-rest-api:
> > > > >    https://github.com/dmsimard/python-cephclient
> > > > >
> > > > >    Does any one know whether there's some similar module to make it
> > > > >    convenient to call Mgr/RESTful plugin in Mimic version?
> > > > >
> > > > > B.R.
> > > > > Changcheng
> > >




[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux