Problem with Nova REST API format
Hi all,
In a Java application I'm using Openstack's REST APIs to manage my Openstack instance, but I'm having a problem with one of Nova's APIs. The API is
/v2/{tenant_id}/servers/detail
which is documented here.
The documentation states it should return something like
{
"servers": [
{
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"private": [
{
"addr": "192.168.0.3",
"version": 4
}
]
},
...
}
This means that in the example the VM is connected to a network named private
through a NIC with address 192.168.0.3
.
If I try to consume the same API using my instance of (Havana) Openstack I get the following JSON result
{
"servers": [
{
"status": "ACTIVE",
"addresses": {
"MyDemo_network": [
{
"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:24:92:1e",
"version": 4,
"addr": "192.168.6.2",
"OS-EXT-IPS:type": "fixed"
}
]
},
...
}
As you can see, I connected the VM instance to a network named MyDemo_network
.
In my Java application I use jsonschema2pojo to generate the POJOs (Java classes) in which the JSON data is to be copied. The POJOs generated with the documented JSON is as follows (I'm omitting annotations and other non important code for the sake of clarity)
//NovaGetServersResponse.java
public class NovaGetServersResponse {
private List<Server> servers = new ArrayList<Server>();
...
}
//Server.java
public class Server {
private Addresses addresses;
...
}
// Addresses.java
public class Addresses {
private List<Private> private = new ArrayList<Private>();
...
}
The JSON returned with my Nova instance, instead, is serialized in a class with this structure
//NovaGetServersResponse.java
public class NovaGetServersResponse {
private List<Server> servers = new ArrayList<Server>();
...
}
//Server.java
public class Server {
private Addresses addresses;
...
}
// Addresses.java
public class Addresses {
private List<MyDemoNetwork> myDemoNetwork = new ArrayList<MyDemoNetwork>();
....
}
As you can see if two different VMs are connected to different networks they would require two different POJOs for the serialization. The problem is that with this class structure I cannot get the data of, for example, a VM which is connected to a network named "TheNetwork" because is would lack the TheNetwork theNetwork
field in its class.
I must be able to get the data of different VMs on different Nova instances so I cannot build a class for each VM.
My suggestion is to change the JSON format to the following
{
"server": {
"accessIPv4": "",
"accessIPv6": "",
"address": [
{
"networkName": "private"
"NIC": [
{
"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:d2:1d:0c",
"version": 4,
"addr": "192.168.6.2",
"OS-EXT-IPS:type": "fixed"
}
]
},
]
...
}
}
This way the Server
POJO would have a List<Address> address
list and the network's name would become a POJO field value (instead of a class name). This way this class would fit the information of any VM.
What do you think about that? Can this API change be accomplished?
Thank you
Giulio