*
* Helper methods for parsing autoscale JSON
*/
public class ParseHelper {
public static ImmutableMap<String, Object> buildLaunchConfigurationRequestMap(Map<String, Object> postParams) {
LaunchConfiguration launchConfigurationRequest = (LaunchConfiguration) postParams.get("launchConfiguration");
ImmutableMap.Builder<String, Object> launchConfigurationMapBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, Object> argsBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, Object> serverBuilder = ImmutableMap.builder();
ImmutableList.Builder<Map<String, String>> networksBuilder = ImmutableList.builder();
for (String networkId : launchConfigurationRequest.getNetworks()) {
Map<String, String> network = Maps.newHashMap();
network.put("uuid", networkId);
networksBuilder.add(network);
}
serverBuilder.put("name", launchConfigurationRequest.getServerName());
serverBuilder.put("imageRef", launchConfigurationRequest.getServerImageRef());
serverBuilder.put("flavorRef", launchConfigurationRequest.getServerFlavorRef());
serverBuilder.put("OS-DCF:diskConfig", launchConfigurationRequest.getServerDiskConfig());
serverBuilder.put("metadata", launchConfigurationRequest.getServerMetadata());
serverBuilder.put("personality", launchConfigurationRequest.getPersonalities());
serverBuilder.put("networks", networksBuilder.build());
argsBuilder.put("loadBalancers", launchConfigurationRequest.getLoadBalancers());
argsBuilder.put("server", serverBuilder.build());
launchConfigurationMapBuilder.put("type", launchConfigurationRequest.getType().toString());
launchConfigurationMapBuilder.put("args", argsBuilder.build());
return launchConfigurationMapBuilder.build();
}