api doesn't return json when program=create-system

list-images, list-systems (and hopefully all the other programs) return json output when accessed via remote.cgi with json=1 set. create-system however does not, it returns one big text string:

"{\n \"status\" : \"success\",\n \"output\" : \"Copying system image files to host system ams2-xen-1-1.localdomain ..\n .. already in host cache\n\nStarting creation of Xen system ..\n.. creation started\n\nWaiting for creation to complete ..\n.. creation complete\n\nRemoving missing disks from fstab file ..\n.. done\n\nMounting new instance's filesystem ..\n.. mounted on /mnt/xen-cwtest\n\nConfiguring kernel for Xen instance ..\n.. setup to boot Xen system's kernel with PyGrub\n\nFixing GRUB configuration file ..\n.. done\n\nSetting root password ..\n.. done\n\nUpdating configuration files with hostname and IP address ..\n.. done\n\nUpdating network configuration files ..\n.. done\n\nModifying /etc/fstab file ..\n.. already done\n\nAllowing SSH logins by root ..\n.. already allowed\n\nSetting SSH server port ..\n.. done\n\nUn-mounting instance's filesystem ..\n.. done\n\nAdding DNS entry cwtest.ams2-cloudmin.anu.net. for IP address 1.2.3.4 ..\n.. done\n\nConfiguring Xen instance for VNC console access ..\n.. added on dynamic port\n\nStarting up new Xen instance ..\n.. done\n\nRegenerating SSH host keys ..\n.. done\n\nRefreshing status ..\n.. done (nowebmin)\n\nRefreshing status of host system ams2-xen-1-1.localdomain ..\n.. done (novirt)\n\nEnabling at hosting system boot ..\n.. done\n\nCreating console access user ..\n.. done\n\nCreation of Xen system cwtest.ams2-cloudmin.anu.net is complete\n\",\n \"command\" : \"create-system\"\n}\n\n" }

Would be very nice if status = success, command = create-system, and output = all the rest were structured json so we can read the result easily.

Status: 
Closed (works as designed)

Comments

Looks like delete-system is the same:

{\n \"status\" : \"success\",\n \"output\" : \"Deleting Xen system cwtest.ams2-cloudmin.anu.net ..\n.. deleted successfully\n\n\",\n \"command\" : \"delete-system\"\n}\n\n" }

Sorry for all the comments. Should have waited and condensed my report. Exit status is also omitted from the JSON output. When json=1 is omitted, the text response contains the exit status:

"Deleting Xen system cwtest.ams2-cloudmin.anu.net ..\n.. deleted successfully\n\n\nExit status: 0\n"

For commands like create-system and delete-system, the majority of their output isn't formatted into JSON.

However, you should still get the "success" field in the JSON-format object, which can be used to tell if the command failed or not. This is basically the same as the exit status - zero means success, non-zero means failure.

What other information are you looking to collect from those API commands?

Yes, I see now that Exit Status is changed to just 'status' in the JSON output. No problem. However, the output is still one long string, the 'status', 'command' and 'output' values are not JSON variables like they are with list-images, list-disks, list-systems etc.

I am using JSON::Parse successfully with the list-* commands, eg:

$ua = new LWP::UserAgent;
my $req = HTTP::Request->new( $api_method => $api_url );
$req->authorization_basic( $cloudmin_user, $cloudmin_pass );
$res = $ua->request($req);

if($res->is_error) {
$result = 'HTTP error!';
$status = "ERROR";
} else {
my $json = $res->decoded_content;
$perl = JSON::Parse::json_to_perl($json);
if( $perl->{'status'} eq 'success' ) {
$status = "OK";
$result = $perl->{'data'};
} else {
$status = $perl->{'status'};
$result = $perl->{'data'};
}
}

{ status => $status, message => $result };

This doesn't work with output from create-system, modify-system and delete-system

If you call the API with a wget command, what exactly does it output? Something like :

wget -O - -q "https://user:pass@host:10000/server-manager/remote.cgi?program=create-system&xxxx=1&json=1"

Sorry to waste your time Jamie. Must be my mistake. This output looks like JSON. Maybe time to quit for the night.

$ curl -k --user myuser:mypass "https://ams1-cloudmin.anu.net:10000/server-manager/remote.cgi?program=modify-limits&host=cw.anu.net&memory=768&json=1"
{
"status" : "success",
"output" : "Setting memory limit on Xen system cw.anu.net to 768 MB ..\n.. done\n\n",
"command" : "modify-limits"
}

Ok, I'll mark this bug as working as intended then :-)