[racktables-users] Re: writing a restful API in php for Racktables

  • From: Ian Bettinger <ibettinger@xxxxxxxxx>
  • To: Alexey Andriyanov <alan@xxxxxxxxxx>
  • Date: Fri, 13 Jul 2012 13:05:16 -0700

Alexey,

Great thanks for the input.

> I, personally, do not see the need in http API at all: PHP CLI utility would
> be much more secure and easy-installable solution.

I see what you're saying: it's certainly simpler and easier to get
started, and works for many people. But a CLI app like that can only
be accessed locally on the machine hosting the web app.

If people would like to integrate Racktables with other systems at
their organizations, I think an API is going to be needed. The example
of Puppet has been brought up a few times: if you want Puppet or any
other external system to be able to say things like "tell me about
server foo," or "please update foo's IP address to ____" it's going to
have to happen over a web service API.

Anyway, again thanks for the help and advice. I'll keep working on
this and let everyone know when there's an alpha version ready
(shouldn't take terribly long). If it's useful enough, I hope we can
eventually add it to the project trunk as an official part of the
application.

Thanks,
Ian




On Fri, Jul 13, 2012 at 12:30 PM, Alexey Andriyanov <alan@xxxxxxxxxx> wrote:
> Hello, Ian.
>
> Your approach is quite good, you just develop a totally separate web
> application which even does not need to be placed into the same http tree as
> racktables' index.php.
> You just set '$script_mode = TRUE;' to turn off http authorization (if you
> wish to), and include the init.php file by its full or relative path.
>
> You do not need to include pre-init.php before init.php as far as you do not
> use the 'fast' mode without establishing a DB connection.
>
> I, personally, do not see the need in http API at all: PHP CLI utility would
> be much more secure and easy-installable solution.
> It could be looked like this:
>
> <?php
>
> $script_mode = TRUE;
> require '/path/to/init.php';
>
> switch ($_SERVER['argv'][1])
> {
>   case  '--get_8021q':
>     echo json_encode (getVLANDomainStats());
>     break;
> //  ... other options
> }
>
> ?>
>
> This is the way I automate tasks in my installation.
>
> 13.07.2012 20:41, Ian Bettinger пишет:
>
>> Thanks for the input. I've taken a first stab at a skeleton version of
>> the api.php file, adding just a couple of methods for now.
>>
>> Can you take a look and see if this approach makes sense to you? I'm
>> not totally familiar with RT's coding style, how you organize things,
>> etc, so let me know what needs to change and I'll incorporate it going
>> forward.
>
>
>

Other related posts: