API for managing from external application?



  • Hi,

    Is there any plans to include a REST API that you could access from any other application to automate the process.

    • Add new Machine
    • Automate tasks and monitor them


  • Yes, It will be part of the 1.3.0 release, hopefully in a few months. The web front end and application have been separated so you will have access to the full API after grabbing an oauth2 token.



  • I don't speak C# , but isn't there already such an API (at least partially) in [url=https://github.com/cdadmin/clonedeploy/tree/master/web/App_Code/Service/]web/App_Code/Service/[/url]?

    I also see some [code]curl[/code] command in the [url=https://github.com/cdadmin/clonedeploy/blob/master/web/private/clientscripts/cd_global_functions]web/private/clientscripts/cd_global_functions[/url] and friends, that seems to use such an API.

    If so, how blessed is that API (e.g. how likely it is to change). Please note that in lieu of any other API, we fall back to writing our own service that [url=https://forum.clonedeploy.org/430-remove-interactivity/p1#p2068]will access the underlying database[/url], which if will break, I guess, we get to keep both halves.

    If that API is really a thing, can you possibly post a usage example to save us some try/err iterations?

    We might need to supplement that API with database access, but every bit that might make our code more robust will be welcome.

    Thanks,
    Cheers,
    Chen.



  • (Partially) answering myself:

    There is indeed [i]some[/i] web API, for the benefit of the client scripts and it is invoked with the [code]curl[/code] command.

    A typical curl command looks like this:

    [code]
    curl --show-error --insecure
    --header "Authorization:$(echo -n $USER_TOKEN | base64)"
    --data $ARG1=$VAL1&$ARG2=$VAL2[...]
    "http://$CLONEDEPLOY_HOST/clonedeploy/service/client.asmx/$WEB_METHOD"
    --connect-timeout 10
    --stderr -
    [/code]

    The [code]$WEB_METHOD[/code]s can be found in [url=https://github.com/cdadmin/clonedeploy/blob/master/web/App_Code/Service/Client/Client.cs]web/App_Code/Service/Client/Client.cs[/url] and are decorated with [code][WebMethod][/code].

    The formal arguments of those methods becomes [code]$ARG1[/code], [code]$ARG2[/code], etc.

    Return values are rendered with:
    [code]
    HttpContext.Current.Response.Write(...)
    [/code]

    $USER_TOKEN should be found in the security settings of the C/D webapp.
    Methods that requires the [code]$USER_TOKEN[/code] starts with:
    [code]
    if (!Authorize()) return;
    [/code]

    The [code]http://$CLONEDEPLOY_HOST/clonedeploy/service/client.asmx/[/code] string can be found in the boot scripts in the C/D webapp as [code]web=...[/code].

    Unfortunately the entry points I really need for my testing automation are missing: namely I need to drive the schedule of a new deploy task for a given computer with a given image. The logic seem to be implemented in [url=https://github.com/cdadmin/clonedeploy/blob/master/web/App_Code/Service/ComputerController.cs]web/App_Code/Service/ComputerController.cs[/url] and [url=https://github.com/cdadmin/clonedeploy/blob/master/web/App_Code/Service/TaskController.cs]TaskController.cs[/url], but there seem to be no [code][WebMethod][/code] entry point for it.

    Am I correct in assuming that in some point such an API was in the planning but it was never realized?



  • Yes, that is mostly correct. The Computer and Task Controller's are functional, I believe. It's been awhile since I've test them. You should be able to view the examples at http://$CLONEDEPLOY_HOST/clonedeploy/apitest

    You can also see the API progress in the 1.3.0 branch.
    https://github.com/cdadmin/clonedeploy/tree/1.3.0-devel/CloneDeploy-App/Controllers