package se.kth.karamel.common.util.settings; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by Alberto on 2015-05-14. */ public enum NovaSetting { NOVA_DEFAULT_FLAVOR("default flavor here!"), NOVA_DEFAULT_REGION("default region here!"), NOVA_DEFAULT_IMAGE("default image here!"), NOVA_DEFAULT_USERNAME("default username here!"), NOVA_DEFAULT_ENDPOINT("default endpoint here!"), NOVA_ACCOUNT_ID_KEY("nova.account.id"), NOVA_ACCOUNT_ENDPOINT("nova.account.endpoint"), NOVA_REGION("nova.region"), NOVA_NETWORKID("nova.networkId"), NOVA_ACCESSKEY_KEY("nova.access.key"), NOVA_KEYPAIR_NAME_KEY("nova.keypair.name"), NOVA_RETRY_INTERVAL("5000"), NOVA_MAX_FORK_VMS_PER_REQUEST("50"); private static final Map<String, NovaSetting> lookup = new HashMap<String, NovaSetting>(); static { for (NovaSetting s : EnumSet.allOf(NovaSetting.class)) lookup.put(s.getParameter(), s); } private String parameter; private NovaSetting(String parameter) { this.parameter = parameter; } public static NovaSetting get(String parameter) { return lookup.get(parameter); } public static final String NOVA_UNIQUE_GROUP_NAME(String clusterName, String groupName) { return (SystemSetting.USER_NAME.getParameter() + "-" + clusterName + "-" + groupName).toLowerCase(); } public static final String NOVA_KEYPAIR_NAME(String clusterName, String region) { return (SystemSetting.USER_NAME.getParameter() + "-" + clusterName).toLowerCase(); } public static final String NOVA_UNIQUE_GROUP_DESCRIPTION(String clusterName, String groupName) { return NOVA_UNIQUE_GROUP_NAME(clusterName, groupName) + "generated by karamel nova launcher"; } public static final List<String> NOVA_UNIQUE_VM_NAMES(String clusterName, String groupName, int size) { List<String> names = new ArrayList<>(); for (int i = 1; i <= size; i++) { names.add(NOVA_UNIQUE_GROUP_NAME(clusterName, groupName) + "-" + i); } return names; } public String getParameter() { return parameter; } }