org.cobbler.Profile - java examples

Here are the examples of the java api org.cobbler.Profile taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

46 Examples 7

19 View Complete Implementation : KickstartData.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Gets the Registration Type (i.e. the code that determines if
 * the ks script needs to generate a reactivation key or not)
 * @param user the user object needed to load the profile from cobbler
 * @return the registration type
 */
public RegistrationType getRegistrationType(User user) {
    Profile prof = getCobblerObject(null);
    if (prof == null) {
        return RegistrationType.getDefault();
    }
    return RegistrationType.find((String) prof.getKsMeta().get(RegistrationType.COBBLER_VAR));
}

19 View Complete Implementation : KickstartFactory.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
private static String getKickstartTemplatePath(KickstartData ksdata, Profile p) {
    String path = ksdata.getCobblerFileName();
    if (p != null && p.getKickstart() != null) {
        path = p.getKickstart();
    }
    return path;
}

19 View Complete Implementation : KickstartRawData.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * the actual raw data asa string. ....
 * @return the raw data
 */
public String getData() {
    if (this.data == null) {
        Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()), this.getCobblerId());
        if (prof == null) {
            return "";
        }
        this.data = FileUtils.readStringFromFile(prof.getKickstart());
    }
    return this.data;
}

19 View Complete Implementation : CobblerProfileCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Validate url in kickstart and kickstart meta. Filesystem paths are not correct,
 * translate it.
 * @param profile The profile to check
 */
public void validateUrl(Profile profile) {
    Map meta = profile.getKsMeta();
    String urlToCheck = ksData.getTree().getBasePath();
    if (!urlToCheck.startsWith("/")) {
        urlToCheck = "/" + urlToCheck;
    }
    Object cobblerMediaVariable = meta.get(KickstartUrlHelper.COBBLER_MEDIA_VARIABLE);
    if (ksData.getUrl().equals(urlToCheck)) {
        ksData.getCommand("url").setArguments("--url " + ksData.getTree().getAbsolutePath());
        if (urlToCheck.equals(cobblerMediaVariable)) {
            meta.remove(KickstartUrlHelper.COBBLER_MEDIA_VARIABLE);
        }
        profile.setKsMeta(meta);
    }
}

19 View Complete Implementation : CobblerProfileCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
protected void updateCobblerFields(Profile profile) {
    if (getDistroForKickstart() != null) {
        profile.setDistro(getDistroForKickstart());
    }
    if (kernelOptions != null) {
        profile.setKernelOptions(kernelOptions);
    }
    if (postKernelOptions != null) {
        profile.setKernelOptionsPost(postKernelOptions);
    }
    // redhat_management_key
    KickstartSession ksession = KickstartFactory.lookupDefaultKickstartSessionForKickstartData(this.ksData);
    if (ksession != null) {
        ActivationKey key = ActivationKeyFactory.lookupByKickstartSession(ksession);
        StringBuffer keystring = new StringBuffer();
        keystring.append(key.getKey());
        if (this.ksData.getDefaultRegTokens() != null) {
            log.debug("Adding replacedociated activation keys.");
            Iterator i = this.ksData.getDefaultRegTokens().iterator();
            while (i.hasNext()) {
                ActivationKey akey = ActivationKeyFactory.lookupByToken((Token) i.next());
                keystring.append(",");
                keystring.append(akey.getKey());
            }
        }
        log.debug("Setting setRedHatManagementKey to: " + keystring);
        profile.setRedHatManagementKey(keystring.toString());
    } else {
        log.warn("We could not find a default kickstart session for this ksdata: " + ksData.getLabel());
    }
    Map meta = profile.getKsMeta();
    meta.put("org", this.ksData.getOrg().getId());
    profile.setKsMeta(meta);
    // Check for para_host
    if (ksData.getKickstartDefaults().getVirtualizationType().getLabel().equals(KickstartVirtualizationType.PARA_HOST)) {
        profile.setVirtType(KickstartVirtualizationType.XEN_PARAVIRT);
    } else // If we're using NONE, use KVM fully virt
    if (ksData.getKickstartDefaults().getVirtualizationType().getLabel().equals(KickstartVirtualizationType.NONE)) {
        profile.setVirtType(KickstartVirtualizationType.KVM_FULLYVIRT);
    } else {
        profile.setVirtType(ksData.getKickstartDefaults().getVirtualizationType().getLabel());
    }
    profile.setEnableMenu(ksData.getActive());
    profile.save();
}

19 View Complete Implementation : CobblerProfileCreateCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Save the Cobbler profile to cobbler.
 * @return ValidatorError if there was a problem
 */
public ValidatorError store() {
    CobblerConnection con = getCobblerConnection();
    Distro distro = getDistroForKickstart();
    if (distro == null) {
        return new ValidatorError("kickstart.cobbler.profile.invalidvirt");
    }
    Profile prof = Profile.create(con, CobblerCommand.makeCobblerName(this.ksData), distro);
    Map<String, String> meta = new HashMap<String, String>();
    meta.put("org", ksData.getOrg().getId().toString());
    prof.setKsMeta(meta);
    KickstartFactory.saveKickstartData(this.ksData);
    prof.setVirtBridge(this.ksData.getDefaultVirtBridge());
    prof.setVirtCpus(ConfigDefaults.get().getDefaultVirtCpus());
    prof.setVirtRam(ConfigDefaults.get().getDefaultVirtMemorySize(this.ksData));
    prof.setVirtFileSize(ConfigDefaults.get().getDefaultVirtDiskSize());
    prof.setKickstart(this.ksData.buildCobblerFileName());
    prof.save();
    updateCobblerFields(prof);
    invokeCobblerUpdate();
    ksData.setCobblerId(prof.getUid());
    return null;
}

19 View Complete Implementation : CobblerProfileDeleteCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * {@inheritDoc}
 */
@Override
public ValidatorError store() {
    // No need to delete if it doesnt exist in cobbler
    Profile profile = ksData.getCobblerObject(user);
    if (profile == null) {
        log.warn("No cobbler profile replacedociated with this Profile.");
        return null;
    }
    if (!profile.remove()) {
        return new ValidatorError("cobbler.profile.remove_failed");
    }
    invokeCobblerUpdate();
    return null;
}

19 View Complete Implementation : CobblerProfileEditCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * {@inheritDoc}
 */
public ValidatorError store() {
    if (StringUtils.isBlank(ksData.getCobblerId())) {
        return new CobblerProfileCreateCommand(ksData, user).store();
    }
    Profile prof = Profile.lookupById(getCobblerConnection(), ksData.getCobblerId());
    validateUrl(prof);
    if (prof != null) {
        String cobName = makeCobblerName(ksData);
        String cobFileName = ksData.buildCobblerFileName();
        if (!cobName.equals(prof.getName()) || !cobFileName.equals(ksData.getCobblerFileName()) || !(new File(cobFileName)).exists()) {
            // delete current cfg file
            KickstartFactory.removeKickstartTemplatePath(ksData);
            // create new cfg file
            KickstartFactory.saveKickstartData(ksData);
            // change ks profile name
            prof.setName(cobName);
            // change ks profile cfg path
            prof.setKickstart(cobFileName);
        }
        updateCobblerFields(prof);
    }
    return null;
}

19 View Complete Implementation : KickstartUrlHelper.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Get the cobbler profile url
 * @param data the kickstart data
 * @return the url
 */
public static String getCobblerProfileUrl(KickstartData data) {
    Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getAutomatedConnection(), data.getCobblerId());
    return "http://" + ConfigDefaults.get().getCobblerHost() + COBBLER_URL_BASE_PATH + prof.getName();
}

19 View Complete Implementation : SSMScheduleCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
private ValidatorError scheduleSystem(Long sid) {
    KickstartData uniqueKs = ksdata;
    String profileId = "";
    if (isIpBasedKs) {
        Server ser = SystemManager.lookupByIdAndUser(sid, user);
        uniqueKs = KickstartManager.getInstance().findProfileForServersNetwork(ser);
    }
    if (uniqueKs == null && !isCobblerOnly) {
        // an IP Range was not found for the ip address of this system
        // and no org default was set.  In the future maybe we should handle this
        // but for now, we'll just move on
        return new ValidatorError("no.kickstart.profiles");
    }
    KickstartScheduleCommand com;
    if (isCobblerOnly) {
        com = KickstartScheduleCommand.createCobblerScheduleCommand(sid, cobblerProfileName, user, scheduleDate, null);
        Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerProfileName);
        profileId = prof.getId();
    } else {
        com = new KickstartScheduleCommand(sid, uniqueKs, user, scheduleDate, null);
        if (useIpv6Gateway()) {
            com.setIpv6Gateway();
        }
        profileId = uniqueKs.getCobblerId();
    }
    com.setKernelOptions(ScheduleKickstartWizardAction.parseKernelOptions(customKernelParams, kernelParamType, profileId, false, user));
    com.setPostKernelOptions(ScheduleKickstartWizardAction.parseKernelOptions(customPostKernelParams, postKernelParamType, profileId, true, user));
    com.setProfileType(profileType);
    com.setProfileId(packageProfileId);
    com.setServerProfileId(serverProfileId);
    com.setProxy(proxy);
    com.setNetworkDevice(networkType, networkInterface);
    if (proxy == null) {
        com.setKickstartServerName(ConfigDefaults.get().getCobblerHost());
    } else {
        com.setKickstartServerName(proxy.getHostname());
    }
    ValidatorError error = com.store();
    if (error == null) {
        this.scheduledActions.add(com.getScheduledAction());
    }
    return error;
}

19 View Complete Implementation : SystemRecordTest.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Sets up a connection and system.
 * @throws Exception in case anything goes wrong
 */
@SuppressWarnings("rawtypes")
public void setUp() throws Exception {
    super.setUp();
    connection = CobblerXMLRPCHelper.getConnection(user.getLogin());
    Distro distro = new Distro.Builder().setName("test-distro").setKernel("kernel").setInitrd("initrd").setKsmeta(new HashMap<String, Object>()).setBreed("redhat").setOsVersion("rhel6").setArch("x86_64").build(connection);
    Profile profile = Profile.create(connection, "test-profile", distro);
    system = SystemRecord.create(connection, "test-system", profile);
}

19 View Complete Implementation : SsmKSScheduleActionTest.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Tests a corner condition in which an existing kickstart is present.
 * @throws Exception if something goes wrong
 */
public void testCreateSystemRecordsWithExistingKickstart() throws Exception {
    CobblerConnection connection = CobblerXMLRPCHelper.getConnection(user.getLogin());
    KickstartData kickstartData = KickstartDataTest.createKickstartWithProfile(user);
    KickstartIpTest.addIpRangesToKickstart(kickstartData);
    Distro distro = new Distro.Builder().setName("test-distro").setKernel("kernel").setInitrd("initrd").setKsmeta(new HashMap<String, Object>()).build(connection);
    Profile profile = Profile.create(connection, "test-profile", distro);
    Server server = ServerTestUtils.createTestSystem(user);
    // this is comprised in ranges added by addIpRangesToKickstart()
    NetworkInterfaceTest.createTestNetworkInterface(server, "server1", "192.168.2.2", "deadbeef");
    KickstartScheduleCommand command = KickstartScheduleCommandTest.scheduleAKickstart(server, kickstartData);
    command.setScheduleDate(new Date());
    ValidatorError ve = command.store();
    ServerTestUtils.addServersToSsm(user, server.getId());
    String listUniqueName = TagHelper.generateUniqueName(ListHelper.LIST);
    addRequestParameter("ip", "true");
    addRequestParameter("list_" + listUniqueName + "_radio", profile.getId());
    addSubmitted();
    addDispatchCall(SsmKSScheduleAction.CREATE_RECORDS_BUTTON);
    setRequestPathInfo("/systems/ssm/kickstart/ScheduleByIp");
    request.setMethod(HttpServletRequestSimulator.POST);
    actionPerform();
    replacedertEquals(302, getMockResponse().getStatusCode());
    SystemRecord record = SystemRecord.lookupById(connection, server.getCobblerId());
    replacedertNotNull(record);
    replacedertNotSame(profile.getId(), record.getProfile().getId());
}

19 View Complete Implementation : SsmKSScheduleActionTest.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Tests creating Cobbler system records with a chosen profile from SSM.
 * @throws Exception if something goes wrong
 */
public void testCreateSystemRecordsByProfile() throws Exception {
    CobblerConnection connection = CobblerXMLRPCHelper.getConnection(user.getLogin());
    Distro distro = new Distro.Builder().setName("test-distro").setKernel("kernel").setInitrd("initrd").setKsmeta(new HashMap<String, Object>()).build(connection);
    Profile profile = Profile.create(connection, "test-profile", distro);
    Server server1 = ServerTestUtils.createTestSystem(user);
    Server server2 = ServerTestUtils.createTestSystem(user);
    ServerTestUtils.addServersToSsm(user, server1.getId());
    ServerTestUtils.addServersToSsm(user, server2.getId());
    String listUniqueName = TagHelper.generateUniqueName(ListHelper.LIST);
    addRequestParameter("list_" + listUniqueName + "_radio", profile.getId());
    addSubmitted();
    addDispatchCall(SsmKSScheduleAction.CREATE_RECORDS_BUTTON);
    setRequestPathInfo("/systems/ssm/kickstart/ScheduleByProfile");
    request.setMethod(HttpServletRequestSimulator.POST);
    actionPerform();
    replacedertEquals(302, getMockResponse().getStatusCode());
    SystemRecord record1 = SystemRecord.lookupById(connection, server1.getCobblerId());
    replacedertNotNull(record1);
    replacedertEquals(profile.getId(), record1.getProfile().getId());
    SystemRecord record2 = SystemRecord.lookupById(connection, server2.getCobblerId());
    replacedertNotNull(record2);
    replacedertEquals(profile.getId(), record1.getProfile().getId());
}

19 View Complete Implementation : SsmKSScheduleActionTest.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Tests creating Cobbler system records by IP range from SSM.
 * @throws Exception if something goes wrong
 */
public void testCreateSystemRecordsByIp() throws Exception {
    CobblerConnection connection = CobblerXMLRPCHelper.getConnection(user.getLogin());
    KickstartData kickstartData = KickstartDataTest.createKickstartWithProfile(user);
    KickstartIpTest.addIpRangesToKickstart(kickstartData);
    Profile profile = Profile.lookupById(connection, kickstartData.getCobblerId());
    Server server1 = ServerTestUtils.createTestSystem(user);
    // this is comprised in ranges added by addIpRangesToKickstart()
    NetworkInterfaceTest.createTestNetworkInterface(server1, "server1", "192.168.2.2", "deadbeef");
    Server server2 = ServerTestUtils.createTestSystem(user);
    // this is not comprised in ranges added by addIpRangesToKickstart()
    NetworkInterfaceTest.createTestNetworkInterface(server2, "server2", "192.178.2.2", "deadbeef");
    ServerTestUtils.addServersToSsm(user, server1.getId());
    ServerTestUtils.addServersToSsm(user, server2.getId());
    String listUniqueName = TagHelper.generateUniqueName(ListHelper.LIST);
    addRequestParameter("ip", "true");
    addRequestParameter("list_" + listUniqueName + "_radio", profile.getId());
    addSubmitted();
    addDispatchCall(SsmKSScheduleAction.CREATE_RECORDS_BUTTON);
    setRequestPathInfo("/systems/ssm/kickstart/ScheduleByIp");
    request.setMethod(HttpServletRequestSimulator.POST);
    actionPerform();
    replacedertEquals(302, getMockResponse().getStatusCode());
    SystemRecord record1 = SystemRecord.lookupById(connection, server1.getCobblerId());
    replacedertNotNull(record1);
    replacedertEquals(profile.getId(), record1.getProfile().getId());
    SystemRecord record2 = SystemRecord.lookupById(connection, server2.getCobblerId());
    replacedertNull(record2);
}

19 View Complete Implementation : CobblerEnableBootstrapCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Stores a Cobbler system, profile and distro for bare-metal
 * server registration.
 *
 * Replaces existing entries, if any.
 *
 * @return any errors
 */
@Override
public ValidatorError store() {
    // remove any existing record
    ValidatorError result = new CobblerDisableBootstrapCommand(user).store();
    if (result != null) {
        return result;
    }
    ConfigDefaults config = ConfigDefaults.get();
    String kernelPath = config.getCobblerBootstrapKernel();
    String initrdPath = config.getCobblerBootstrapInitrd();
    if (!skipFileCheck) {
        if (kernelPath == null || !new File(kernelPath).exists()) {
            log.error("Kernel file not found: " + kernelPath);
            return new ValidatorError("bootstrapsystems.kernel_not_found", kernelPath);
        }
        if (initrdPath == null || !new File(initrdPath).exists()) {
            log.error("Initrd file not found: " + kernelPath);
            return new ValidatorError("bootstrapsystems.initrd_not_found", initrdPath);
        }
    }
    // add new records
    CobblerConnection connection = getCobblerConnection();
    Distro distro = new Distro.Builder().setName(Distro.BOOTSTRAP_NAME).setKernel(kernelPath).setInitrd(initrdPath).setKsmeta(new HashMap<String, Object>()).setBreed(config.getCobblerBootstrapBreed()).setArch(config.getCobblerBootstrapArch()).build(connection);
    log.debug("Distro added");
    Profile profile = Profile.create(connection, Profile.BOOTSTRAP_NAME, distro);
    Map<String, Object> kernelOptions = new HashMap<String, Object>();
    kernelOptions.put("spacewalk_hostname", config.getHostname());
    Long orgId = user.getOrg().getId();
    kernelOptions.put("spacewalk_activationkey", orgId + "-spacewalk-bootstrap-activation-key");
    String[] splits = config.getCobblerBootstrapExtraKernelOptions().split("[= ]");
    for (int i = 0; i < splits.length / 2; i++) {
        kernelOptions.put(splits[i * 2], splits[i * 2 + 1]);
    }
    profile.setKernelOptions(kernelOptions);
    profile.save();
    log.debug("Profile added");
    SystemRecord system = SystemRecord.create(connection, SystemRecord.BOOTSTRAP_NAME, profile);
    system.save();
    log.debug("System record added");
    ActivationKey activationKey = ActivationKeyFactory.createNewKey(user, null, ActivationKey.BOOTSTRAP_TOKEN, "For bootstrap use", null, null, false);
    activationKey.setBootstrap("Y");
    log.debug("Activation key added");
    Set<ServerGroupType> enreplacedlements = activationKey.getEnreplacedlements();
    for (ServerGroupType enreplacedlement : enreplacedlements) {
        activationKey.removeEnreplacedlement(enreplacedlement);
    }
    activationKey.addEnreplacedlement(ServerConstants.getServerGroupTypeBootstrapEnreplacedled());
    log.debug("Enreplacedlement added");
    return new CobblerSyncCommand(user).store();
}

19 View Complete Implementation : CobblerProfileCreateCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Save the Cobbler profile to cobbler.
 * @return ValidatorError if there was a problem
 */
public ValidatorError store() {
    CobblerConnection con = getCobblerConnection();
    Distro distro = getDistroForKickstart();
    if (distro == null) {
        return new ValidatorError("kickstart.cobbler.profile.invalidvirt");
    }
    Profile prof = Profile.create(con, CobblerCommand.makeCobblerName(this.ksData), distro);
    Map<String, String> meta = new HashMap<String, String>();
    meta.put("org", ksData.getOrg().getId().toString());
    prof.setKsMeta(meta);
    KickstartFactory.saveKickstartData(this.ksData);
    prof.setVirtBridge(this.ksData.getDefaultVirtBridge());
    prof.setVirtCpus(ConfigDefaults.get().getDefaultVirtCpus());
    prof.setVirtRam(ConfigDefaults.get().getDefaultVirtMemorySize(this.ksData));
    prof.setVirtFileSize(ConfigDefaults.get().getDefaultVirtDiskSize());
    prof.setKickstart(this.ksData.buildCobblerFileName());
    prof.save();
    updateCobblerFields(prof);
    ksData.setCobblerId(prof.getUid());
    if (callCobblerSync) {
        return new CobblerSyncCommand(user).store();
    }
    return null;
}

19 View Complete Implementation : CobblerProfileDeleteCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * {@inheritDoc}
 */
@Override
public ValidatorError store() {
    // No need to delete if it doesnt exist in cobbler
    Profile profile = ksData.getCobblerObject(user);
    if (profile == null) {
        log.warn("No cobbler profile replacedociated with this Profile.");
        return null;
    }
    if (!profile.remove()) {
        return new ValidatorError("cobbler.profile.remove_failed");
    }
    return new CobblerSyncCommand(user).store();
}

19 View Complete Implementation : CobblerProfileEditCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * {@inheritDoc}
 */
public ValidatorError store() {
    if (StringUtils.isBlank(ksData.getCobblerId())) {
        return new CobblerProfileCreateCommand(ksData, user).store();
    }
    Profile prof = Profile.lookupById(getCobblerConnection(), ksData.getCobblerId());
    validateUrl(prof);
    if (prof != null) {
        String cobName = makeCobblerName(ksData);
        String cobFileName = ksData.buildCobblerFileName();
        if (!cobName.equals(prof.getName()) || !cobFileName.equals(ksData.getCobblerFileName()) || !(new File(cobFileName)).exists()) {
            // delete current cfg file
            KickstartFactory.removeKickstartTemplatePath(ksData);
            // create new cfg file
            KickstartFactory.saveKickstartData(ksData);
            // change ks profile name
            prof.setName(cobName);
            // change ks profile cfg path
            prof.setKickstart(cobFileName);
        }
        updateCobblerFields(prof);
        if (callCobblerSync) {
            return new CobblerSyncCommand(user).store();
        }
    }
    return null;
}

19 View Complete Implementation : CobblerEnableBootstrapCommandTest.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Tests the execution of this Cobbler command.
 * @throws Exception if unforeseen problems arise
 */
public void testStore() throws Exception {
    // create a pre-existing system, profile and distro to test they have
    // been replaced
    CobblerConnection connection = CobblerXMLRPCHelper.getConnection("test");
    Distro distro = new Distro.Builder().setName(Distro.BOOTSTRAP_NAME).setKernel("test-kernel").setInitrd("test-initrd").setKsmeta(new HashMap<String, Object>()).build(connection);
    Profile profile = Profile.create(connection, Profile.BOOTSTRAP_NAME, distro);
    SystemRecord system = SystemRecord.create(connection, SystemRecord.BOOTSTRAP_NAME, profile);
    // create pre-existing activation key
    ActivationKey previousActivationKey = ActivationKeyFactory.createNewKey(user, null, "test-key", "For bootstrap use", 0L, null, false);
    previousActivationKey.setBootstrap("Y");
    // check that all above actually exists
    HashMap<String, Object> criteria = new HashMap<String, Object>();
    criteria.put("uid", system.getId());
    List<Map<String, Object>> previousSystem = CobblerDisableBootstrapCommandTest.invoke(connection, "find_system", criteria);
    replacedertEquals(1, previousSystem.size());
    criteria.put("uid", profile.getId());
    List<Map<String, Object>> previousProfile = CobblerDisableBootstrapCommandTest.invoke(connection, "find_profile", criteria);
    replacedertEquals(1, previousProfile.size());
    criteria.put("uid", distro.getId());
    List<Map<String, Object>> previousDistro = CobblerDisableBootstrapCommandTest.invoke(connection, "find_distro", criteria);
    replacedertEquals(1, previousDistro.size());
    List<ActivationKey> previousActivationKeys = ActivationKeyManager.getInstance().findBootstrap();
    replacedertEquals(1, previousActivationKeys.size());
    CobblerEnableBootstrapCommand command = new CobblerEnableBootstrapCommand(user, true);
    replacedertNull(command.store());
    // check previous records have been deleted
    criteria.put("uid", system.getId());
    previousSystem = CobblerDisableBootstrapCommandTest.invoke(connection, "find_system", criteria);
    replacedertEquals(0, previousSystem.size());
    criteria.put("uid", profile.getId());
    previousProfile = CobblerDisableBootstrapCommandTest.invoke(connection, "find_profile", criteria);
    replacedertEquals(0, previousProfile.size());
    criteria.put("uid", distro.getId());
    previousDistro = CobblerDisableBootstrapCommandTest.invoke(connection, "find_distro", criteria);
    replacedertEquals(0, previousDistro.size());
    // check new records have been added
    ConfigDefaults config = ConfigDefaults.get();
    criteria.clear();
    criteria.put("name", Distro.BOOTSTRAP_NAME);
    Map<String, Object> newDistro = CobblerDisableBootstrapCommandTest.invoke(connection, "find_distro", criteria).get(0);
    replacedertEquals(config.getCobblerBootstrapKernel(), newDistro.get("kernel"));
    replacedertEquals(config.getCobblerBootstrapInitrd(), newDistro.get("initrd"));
    replacedertEquals(config.getCobblerBootstrapBreed(), newDistro.get("breed"));
    replacedertEquals(config.getCobblerBootstrapArch(), newDistro.get("arch"));
    criteria.put("name", Profile.BOOTSTRAP_NAME);
    Map<String, Object> newProfile = CobblerDisableBootstrapCommandTest.invoke(connection, "find_profile", criteria).get(0);
    replacedertEquals(Distro.BOOTSTRAP_NAME, newProfile.get("distro"));
    Map<String, Object> expectedOptions = new HashMap<String, Object>();
    String activationKeyToken = user.getOrg().getId() + "-" + ActivationKey.BOOTSTRAP_TOKEN;
    expectedOptions.put("spacewalk_hostname", config.getHostname());
    expectedOptions.put("spacewalk_activationkey", activationKeyToken);
    expectedOptions.put("ROOTFS_FSCK", "0");
    replacedertEquals(expectedOptions, newProfile.get("kernel_options"));
    criteria.put("name", SystemRecord.BOOTSTRAP_NAME);
    Map<String, Object> newSystem = CobblerDisableBootstrapCommandTest.invoke(connection, "find_system", criteria).get(0);
    replacedertEquals(Profile.BOOTSTRAP_NAME, newSystem.get("profile"));
    List<ActivationKey> activationKeys = ActivationKeyManager.getInstance().findBootstrap();
    replacedertEquals(1, activationKeys.size());
    ActivationKey activationKey = activationKeys.get(0);
    replacedertEquals(activationKeyToken, activationKey.getKey());
    replacedertNotNull(activationKey.getToken());
    replacedertNull(activationKey.getUsageLimit());
    replacedertFalse(activationKey.getDeployConfigs());
    Set<ServerGroupType> enreplacedlements = activationKey.getToken().getEnreplacedlements();
    replacedertEquals(1, enreplacedlements.size());
    replacedertEquals("bootstrap_enreplacedled", enreplacedlements.iterator().next().getLabel());
}

19 View Complete Implementation : SSMScheduleCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
private ValidatorError scheduleSystem(Long sid) throws TaskomaticApiException {
    KickstartData uniqueKs = ksdata;
    String profileId = "";
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    String serverName = server != null ? server.getName() : sid + "";
    if (server.isBootstrap()) {
        return new ValidatorError("kickstart.schedule.no.schedule.on.bootstrap.jsp", serverName);
    }
    if (isIpBasedKs) {
        uniqueKs = KickstartManager.getInstance().findProfileForServersNetwork(server);
    }
    if (uniqueKs == null && !isCobblerOnly) {
        // an IP Range was not found for the ip address of this system
        // and no org default was set.  In the future maybe we should handle this
        // but for now, we'll just move on
        return new ValidatorError("kickstart.schedule.no.profile.jsp", serverName);
    }
    KickstartScheduleCommand com;
    if (isCobblerOnly) {
        com = KickstartScheduleCommand.createCobblerScheduleCommand(sid, cobblerProfileName, user, scheduleDate, null);
        Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerProfileName);
        profileId = prof.getId();
    } else {
        com = new KickstartScheduleCommand(sid, uniqueKs, user, scheduleDate, null);
        if (useIpv6Gateway()) {
            com.setIpv6Gateway();
        }
        profileId = uniqueKs.getCobblerId();
    }
    com.setKernelOptions(ScheduleKickstartWizardAction.parseKernelOptions(customKernelParams, kernelParamType, profileId, false, user));
    com.setPostKernelOptions(ScheduleKickstartWizardAction.parseKernelOptions(customPostKernelParams, postKernelParamType, profileId, true, user));
    com.setProfileType(profileType);
    com.setProfileId(packageProfileId);
    com.setServerProfileId(serverProfileId);
    com.setProxy(proxy);
    com.setNetworkDevice(networkType, networkInterface);
    if (proxy == null) {
        com.setKickstartServerName(ConfigDefaults.get().getCobblerHost());
    } else {
        com.setKickstartServerName(proxy.getHostname());
    }
    ValidatorError error = com.store();
    if (error == null) {
        this.scheduledActions.add(com.getScheduledAction());
    }
    return error;
}

19 View Complete Implementation : SystemRecordTest.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Sets up a connection and system.
 * @throws Exception in case anything goes wrong
 */
public void setUp() throws Exception {
    super.setUp();
    connection = CobblerXMLRPCHelper.getConnection(user.getLogin());
    Distro distro = new Distro.Builder().setName("test-distro").setKernel("kernel").setInitrd("initrd").setKsmeta(new HashMap<String, Object>()).setBreed("redhat").setOsVersion("rhel6").setArch("x86_64").build(connection);
    Profile profile = Profile.create(connection, "test-profile", distro);
    system = SystemRecord.create(connection, "test-system", profile);
}

18 View Complete Implementation : CobblerProfileDto.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Create as CobblerProfileDto instance
 *  from the given Cobbler profile object
 * @param profile  the Cobbler profile object
 * @return the converted Dto instance
 */
public static CobblerProfileDto create(Profile profile) {
    CobblerProfileDto dto = new CobblerProfileDto();
    dto.selectionKey = profile.getUid();
    dto.setCobblerId(profile.getId());
    dto.setLabel(profile.getName());
    dto.setTreeLabel(profile.getDistro().getName());
    dto.setCobblerUrl(KickstartUrlHelper.getCobblerProfilePath(profile.getName()));
    return dto;
}

18 View Complete Implementation : KickstartCloneCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Execute the clone or copy of the KickstartData replacedociated with this command.
 *
 * Call getClonedKickstart() to get the new object created.
 *
 * @return ValidatorError if there was a problem
 */
public ValidatorError store() {
    if (clonedKickstart != null) {
        throw new UnsupportedOperationException("Can't call store twice on this Command");
    }
    // we keep the name and the label the same.
    clonedKickstart = this.ksdata.deepCopy(user, newLabel);
    KickstartWizardHelper helperCmd = new KickstartWizardHelper(user);
    helperCmd.store(clonedKickstart);
    Profile original = ksdata.getCobblerObject(user);
    Profile cloned = clonedKickstart.getCobblerObject(user);
    cloned.setKsMeta(original.getKsMeta());
    cloned.setVirtRam(original.getVirtRam());
    cloned.setVirtCpus(original.getVirtCpus());
    cloned.setVirtFileSize(original.getVirtFileSize());
    cloned.setVirtBridge(original.getVirtBridge());
    cloned.setVirtPath(original.getVirtBridge());
    cloned.setKernelOptions(original.getKernelOptions());
    cloned.setKernelOptionsPost(original.getKernelOptionsPost());
    cloned.save();
    return null;
}

18 View Complete Implementation : ProvisionVirtualInstanceCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * {@inheritDoc}
 */
@Override
public DataResult<KickstartDto> getKickstartProfiles() {
    DataResult<KickstartDto> result = super.getKickstartProfiles();
    for (Iterator<KickstartDto> itr = result.iterator(); itr.hasNext(); ) {
        KickstartDto dto = itr.next();
        Profile prf = Profile.lookupById(CobblerXMLRPCHelper.getConnection(this.getUser()), dto.getCobblerId());
        if (prf != null) {
            dto.setVirtBridge(prf.getVirtBridge());
            dto.setVirtCpus(prf.getVirtCpus());
            dto.setVirtMemory(prf.getVirtRam());
            dto.setVirtSpace(prf.getVirtFileSize());
        } else {
            itr.remove();
        }
    }
    return result;
}

18 View Complete Implementation : KickstartFileSyncTask.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * {@inheritDoc}
 */
public void execute(JobExecutionContext ctxIn) throws JobExecutionException {
    CobblerConnection cc = CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser());
    List<KickstartData> kickstarts = KickstartFactory.listAllKickstartData();
    for (KickstartData ks : kickstarts) {
        // If this is a wizard profile
        if (!ks.isRawData()) {
            Profile p = Profile.lookupById(cc, ks.getCobblerId());
            if (p != null) {
                String ksFilePath = ks.buildCobblerFileName();
                if (!(new File(ksFilePath)).exists() || !ksFilePath.equals(p.getKickstart())) {
                    log.info("Syncing " + ks.getLabel());
                    CobblerProfileEditCommand cpec = new CobblerProfileEditCommand(ks);
                    cpec.store();
                }
            }
        }
    }
}

18 View Complete Implementation : KickstartFileSyncTaskTest.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
public void testTask() throws Exception {
    User user = UserTestUtils.createUserInOrgOne();
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    KickstartData ks = KickstartDataTest.createTestKickstartData(user.getOrg());
    ks.setKickstartDefaults(KickstartDataTest.createDefaults(ks, user));
    KickstartDataTest.createCobblerObjects(ks);
    KickstartFactory.saveKickstartData(ks);
    ks = (KickstartData) TestUtils.saveAndReload(ks);
    Profile p = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), ks.getCobblerId());
    File f = new File(p.getKickstart());
    replacedertTrue(f.exists());
    f.delete();
    replacedertFalse(f.exists());
    KickstartFileSyncTask task = new KickstartFileSyncTask();
    task.execute(null);
    f = new File(p.getKickstart());
    replacedertTrue(f.exists());
}

18 View Complete Implementation : CobblerDisableBootstrapCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Removes any existing Cobbler system, profile, distro for bare-metal
 * server registration.
 * @return any errors
 */
@Override
public ValidatorError store() {
    CobblerConnection connection = getCobblerConnection();
    // remove any pre-existing record
    SystemRecord previousSystem = SystemRecord.lookupByName(connection, SystemRecord.BOOTSTRAP_NAME);
    if (previousSystem != null) {
        if (!previousSystem.remove()) {
            log.error("Could not remove existing system record");
            return new ValidatorError("cobbler.system.remove_failed");
        }
        log.debug("Existing system record removed");
    }
    Profile previousProfile = Profile.lookupByName(connection, Profile.BOOTSTRAP_NAME);
    if (previousProfile != null) {
        if (!previousProfile.remove()) {
            log.error("Could not remove existing profile");
            return new ValidatorError("cobbler.profile.remove_failed");
        }
        log.debug("Existing profile removed");
    }
    Distro previousDistro = Distro.lookupByName(connection, Distro.BOOTSTRAP_NAME);
    if (previousDistro != null) {
        if (!previousDistro.remove()) {
            log.error("Could not remove existing distro");
            return new ValidatorError("cobbler.distro.remove_failed");
        }
        log.debug("Existing distro removed");
    }
    List<ActivationKey> previousActivationKeys = ActivationKeyManager.getInstance().findBootstrap();
    for (ActivationKey key : previousActivationKeys) {
        ActivationKeyFactory.removeKey(key);
    }
    log.debug("Existing activation keys removed");
    return new CobblerSyncCommand(user).store();
}

17 View Complete Implementation : KickstartData.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * @return the cobblerName
 */
public String getCobblerFileName() {
    if (getCobblerId() != null) {
        Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()), getCobblerId());
        if (prof != null && !StringUtils.isBlank(prof.getKickstart())) {
            return prof.getKickstart();
        }
    }
    return null;
}

17 View Complete Implementation : ProvisionVirtualizationWizardAction.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Get the cobbler profile
 * @param context the request context
 * @return the cobbler profile
 */
private Profile getCobblerProfile(RequestContext context) {
    if (context.getRequest().getAttribute(PROFILE) == null) {
        String cobblerId = (String) context.getRequest().getAttribute(RequestContext.COBBLER_ID);
        User user = context.getCurrentUser();
        Profile cobblerProfile = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
        context.getRequest().setAttribute(PROFILE, cobblerProfile);
    }
    return (Profile) context.getRequest().getAttribute(PROFILE);
}

17 View Complete Implementation : KickstartActivationKeysCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Adds default regtokens from the kickstart profile.
 * @param ids The ids of the regtokens to add.
 */
public void addTokensByIds(List<Long> ids) {
    Set<String> keysToAdd = new HashSet<String>();
    for (Long id : ids) {
        Token token = TokenFactory.lookupById(id);
        this.getKickstartData().addDefaultRegToken(token);
    }
    // So we will add them all even if they are already there (in case the
    // Key was added via the commandline and doesn't actually have them :/
    for (Token token : this.getKickstartData().getDefaultRegTokens()) {
        keysToAdd.add(ActivationKeyFactory.lookupByToken(token).getKey());
    }
    Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(this.getUser()), this.getKickstartData().getCobblerId());
    if (prof != null) {
        prof.syncRedHatManagementKeys(new ArrayList<String>(), keysToAdd);
    }
    prof.save();
}

17 View Complete Implementation : KickstartActivationKeysCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Removes default regtokens from the kickstart profile.
 * @param ids The ids of the regtokens to remove.
 */
public void removeTokensByIds(List<Long> ids) {
    Set<String> keysToRemove = new HashSet<String>();
    for (Long id : ids) {
        Set<Token> tokenSetCopy = new HashSet<Token>();
        tokenSetCopy.addAll(this.getKickstartData().getDefaultRegTokens());
        for (Token token : tokenSetCopy) {
            if (token.getId() == id) {
                this.getKickstartData().getDefaultRegTokens().remove(token);
                keysToRemove.add(ActivationKeyFactory.lookupByToken(token).getKey());
            }
        }
    }
    Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(this.getUser()), this.getKickstartData().getCobblerId());
    if (prof != null) {
        prof.syncRedHatManagementKeys(keysToRemove, new ArrayList<String>());
    }
    prof.save();
}

16 View Complete Implementation : KickstartData.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Sets the registration type
 * @param type the refgistration type
 * @param user the user needed to load the profile form cobbler
 */
public void setRegistrationType(RegistrationType type, User user) {
    Profile prof = getCobblerObject(user);
    Map<String, Object> meta = prof.getKsMeta();
    meta.put(RegistrationType.COBBLER_VAR, type.getType());
    prof.setKsMeta(meta);
    prof.save();
}

16 View Complete Implementation : KickstartFactory.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Removes ks cfg template path
 * @param ksdataIn kickstart data
 */
public static void removeKickstartTemplatePath(KickstartData ksdataIn) {
    Profile p = Profile.lookupById(CobblerXMLRPCHelper.getAutomatedConnection(), ksdataIn.getCobblerId());
    String path = getKickstartTemplatePath(ksdataIn, p);
    if (path != null) {
        File file = new File(path);
        if (file.exists()) {
            log.debug("deleting : " + path);
            file.delete();
        }
    }
}

15 View Complete Implementation : KickstartLister.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Sets the kickstart url for the preplaceded in cobbler profiles.
 * @param dtos the kickstart dto
 * @param user the user object needed to connect to cobbler
 */
public void setKickstartUrls(List<KickstartDto> dtos, User user) {
    CobblerConnection conn = CobblerXMLRPCHelper.getConnection(user);
    for (KickstartDto dto : dtos) {
        Profile p = Profile.lookupById(conn, dto.getCobblerId());
        if (p != null) {
            dto.setCobblerUrl(KickstartUrlHelper.getCobblerProfilePath(p.getName()));
        }
    }
}

14 View Complete Implementation : ProvisionVirtualizationWizardAction.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
@Override
protected ProvisionVirtualInstanceCommand getScheduleCommand(DynaActionForm form, RequestContext ctx, Date scheduleTime, String host) {
    Profile cobblerProfile = getCobblerProfile(ctx);
    User user = ctx.getCurrentUser();
    ProvisionVirtualInstanceCommand cmd;
    KickstartData data = KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerProfile.getId());
    if (data != null) {
        cmd = new ProvisionVirtualInstanceCommand((Long) form.get(RequestContext.SID), data, ctx.getCurrentUser(), scheduleTime, host);
    } else {
        cmd = ProvisionVirtualInstanceCommand.createCobblerScheduleCommand((Long) form.get(RequestContext.SID), cobblerProfile.getName(), user, scheduleTime, host);
    }
    return cmd;
}

14 View Complete Implementation : KickstartLister.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Returns a list of Cobbler only profiles.
 * i.e profiles that are not part of spacewalk
 * but are part of cobbler.
 * @param user the user object needed for cobbler conneciton
 * @return list of cobbler profile dtos.
 */
public List<CobblerProfileDto> listCobblerProfiles(User user) {
    logger.debug("Adding cobblerProfiles to the list");
    Set<String> excludes = new HashSet<String>(KickstartFactory.listKickstartDataCobblerIds());
    List<CobblerProfileDto> profiles = new LinkedList<CobblerProfileDto>();
    List<Profile> cProfiles = Profile.list(CobblerXMLRPCHelper.getConnection(user), excludes);
    for (Profile profile : cProfiles) {
        Distro distro = profile.getDistro();
        Object orgId = distro.getKsMeta().get("org");
        if (orgId == null || user.getOrg().getId().toString().equals(String.valueOf(orgId))) {
            profiles.add(CobblerProfileDto.create(profile));
        }
    }
    logger.debug("Returning cobbler profiles: " + profiles);
    return profiles;
}

13 View Complete Implementation : KickstartFactory.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Save a KickstartData to the DB and replacedociate
 * the storage with the KickstartSession preplaceded in.  This is
 * used if you want to save the KickstartData and replacedociate the
 *
 * @param ksdataIn Kickstart Data to be stored in db
 * @param ksession KickstartSession to replacedociate with this save.
 */
public static void saveKickstartData(KickstartData ksdataIn, KickstartSession ksession) {
    log.debug("saveKickstartData: " + ksdataIn.getLabel());
    singleton.saveObject(ksdataIn);
    String fileData = null;
    if (ksdataIn.isRawData()) {
        log.debug("saveKickstartData is raw, use file");
        KickstartRawData rawData = (KickstartRawData) ksdataIn;
        fileData = rawData.getData();
    } else {
        log.debug("saveKickstartData wizard.  use object");
        KickstartFormatter formatter = new KickstartFormatter(KickstartUrlHelper.COBBLER_SERVER_VARIABLE, ksdataIn, ksession);
        fileData = formatter.getFileData();
    }
    Profile p = Profile.lookupById(CobblerXMLRPCHelper.getAutomatedConnection(), ksdataIn.getCobblerId());
    if (p != null && p.getKsMeta() != null) {
        Map ksmeta = p.getKsMeta();
        Iterator i = ksmeta.keySet().iterator();
        while (i.hasNext()) {
            String name = (String) i.next();
            log.debug("fixing ksmeta: " + name);
            fileData = StringUtils.replace(fileData, "\\$" + name, "$" + name);
        }
    } else {
        log.debug("No ks meta for this profile.");
    }
    String path = ksdataIn.buildCobblerFileName();
    log.debug("writing ks file to : " + path);
    FileUtils.writeStringToFile(fileData, path);
}

13 View Complete Implementation : ActivationKeyManager.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * helper method to change an activation keys' key.
 *  This loops through all replacedociated kickstart profiles and makes
 *  the change in cobbler
 */
private static void changeCobblerProfileKey(ActivationKey key, String oldKey, String newKey, User user) {
    List<KickstartData> kss = ActivationKeyFactory.listreplacedociatedKickstarts(key);
    for (KickstartData ks : kss) {
        if (ks.getCobblerId() != null) {
            Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), ks.getCobblerId());
            Set oldSet = new HashSet();
            if (!StringUtils.isEmpty(oldKey)) {
                oldSet.add(oldKey);
            }
            Set newSet = new HashSet();
            if (!StringUtils.isEmpty(newKey)) {
                newSet.add(newKey);
            }
            prof.syncRedHatManagementKeys(oldSet, newSet);
            prof.save();
        }
    }
}

13 View Complete Implementation : KickstartLister.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Returns a list of Cobbler only profiles.
 * i.e profiles that are not part of spacewalk
 * but are part of cobbler.
 * @param user the user object needed for cobbler conneciton
 * @return list of cobbler profile dtos.
 */
public List<CobblerProfileDto> listCobblerProfiles(User user) {
    logger.debug("Adding cobblerProfiles to the list");
    Set<String> excludes = new HashSet<String>(KickstartFactory.listKickstartDataCobblerIds());
    List<CobblerProfileDto> profiles = new LinkedList<CobblerProfileDto>();
    List<Profile> cProfiles = Profile.list(CobblerXMLRPCHelper.getConnection(user), excludes);
    for (Profile profile : cProfiles) {
        Distro distro = profile.getDistro();
        Object orgId = distro.getKsMeta().get("org");
        String name = profile.getName();
        String userOrgId = user.getOrg().getId().toString();
        if (!name.equals(Profile.BOOTSTRAP_NAME) && (orgId == null || userOrgId.equals(String.valueOf(orgId)))) {
            profiles.add(CobblerProfileDto.create(profile));
        }
    }
    logger.debug("Returning cobbler profiles: " + profiles);
    return profiles;
}

10 View Complete Implementation : CobblerSystemCreateCommand.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Store the System to cobbler
 * @param saveCobblerId false if CobblerVirtualSystemCommand is calling, true otherwise
 * @return ValidatorError if the store failed.
 */
public ValidatorError store(boolean saveCobblerId) {
    Profile profile = Profile.lookupByName(getCobblerConnection(), profileName);
    // First lookup by MAC addr
    SystemRecord rec = lookupExisting();
    if (rec == null) {
        // Next try by name
        rec = SystemRecord.lookupByName(getCobblerConnection(user), getCobblerSystemRecordName());
    }
    // Else, lets make a new system
    if (rec == null) {
        rec = SystemRecord.create(getCobblerConnection(), getCobblerSystemRecordName(), profile);
    }
    try {
        processNetworkInterfaces(rec, server);
    } catch (XmlRpcException e) {
        if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("IP address duplicated")) {
            return new ValidatorError("frontend.actions.systems.virt.duplicateipaddressvalue");
        }
        throw e;
    }
    rec.enableNetboot(true);
    rec.setProfile(profile);
    if (isDhcp) {
        rec.setIpv6Autoconfiguration(true);
    } else {
        rec.setIpv6Autoconfiguration(false);
    }
    if (this.activationKeys == null || this.activationKeys.length() == 0) {
        log.error("This cobbler profile does not " + "have a redhat_management_key set ");
    } else {
        rec.setRedHatManagementKey(activationKeys);
    }
    if (!StringUtils.isBlank(getKickstartHost())) {
        rec.setServer(getKickstartHost());
    } else {
        rec.setServer("");
    }
    // Setup the kickstart metadata so the URLs and activation key are setup
    Map<String, Object> ksmeta = rec.getKsMeta();
    if (ksmeta == null) {
        ksmeta = new HashMap<String, Object>();
    }
    if (!StringUtils.isBlank(mediaPath)) {
        ksmeta.put(KickstartUrlHelper.COBBLER_MEDIA_VARIABLE, this.mediaPath);
    }
    if (!StringUtils.isBlank(getKickstartHost())) {
        ksmeta.put(SystemRecord.REDHAT_MGMT_SERVER, getKickstartHost());
    }
    ksmeta.remove(KickstartFormatter.STATIC_NETWORK_VAR);
    ksmeta.put(KickstartFormatter.USE_IPV6_GATEWAY, this.useIpv6Gateway ? "true" : "false");
    if (this.ksDistro != null) {
        ksmeta.put(KickstartFormatter.KS_DISTRO, this.ksDistro);
    }
    rec.setKsMeta(ksmeta);
    if (getServer().getHostname() != null) {
        rec.setHostName(getServer().getHostname());
    } else if (getServer().getName() != null) {
        rec.setHostName(getServer().getName());
    }
    rec.setKernelOptions(kernelOptions);
    rec.setKernelOptionsPost(postKernelOptions);
    try {
        rec.save();
    } catch (XmlRpcException e) {
        if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("IP address duplicated")) {
            return new ValidatorError("frontend.actions.systems.virt.duplicateipaddressvalue");
        }
        throw e;
    }
    /*
         * This is a band-aid for the problem revealed in bug 846221. However
         * the real fix involves creating a new System for the virtual guest
         * instead of re-using the host System object, and I am unsure of what
         * effects that would have. The System object is used when creating
         * reActivation keys and setting up the cobbler SystemRecord network
         * info among other things. No bugs have been reported in those areas
         * yet, so I don't want to change something that has the potential to
         * break a lot of things.
         */
    if (saveCobblerId) {
        server.setCobblerId(rec.getId());
    }
    return null;
}

9 View Complete Implementation : KickstartDetailsEditAction.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Proccess Cobbler form values, pulling in the form
 *      and pushing the values to cobbler
 * @param ksdata the kickstart data
 * @param form the form
 * @param user the user
 * @throws ValidatorException if there is not enough ram
 */
public static void processCobblerFormValues(KickstartData ksdata, DynaActionForm form, User user) throws ValidatorException {
    if (KickstartDetailsEditAction.canSaveVirtOptions(ksdata, form)) {
        int virtMemory = (Integer) form.get(VIRT_MEMORY);
        if (ksdata.isRhel7OrGreater() && virtMemory < 1024) {
            ValidatorException.raiseException("kickstart.cobbler.profile.notenoughmemory");
        } else if (ksdata.isSUSE() && virtMemory < 512) {
            ValidatorException.raiseException("kickstart.cobbler.profile.notenoughmemorysuse");
        }
    }
    CobblerProfileEditCommand cmd = new CobblerProfileEditCommand(ksdata, user);
    cmd.setKernelOptions(StringUtils.defaultString(form.getString(KERNEL_OPTIONS)));
    cmd.setPostKernelOptions(StringUtils.defaultString(form.getString(POST_KERNEL_OPTIONS)));
    cmd.store();
    Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), ksdata.getCobblerId());
    if (prof == null) {
        return;
    }
    if (KickstartDetailsEditAction.canSaveVirtOptions(ksdata, form)) {
        prof.setVirtRam((Integer) form.get(VIRT_MEMORY));
        prof.setVirtCpus((Integer) form.get(VIRT_CPU));
        prof.setVirtFileSize((Integer) form.get(VIRT_DISK_SIZE));
        prof.setVirtBridge(form.getString(VIRT_BRIDGE));
    }
    prof.save();
}

8 View Complete Implementation : KickstartDetailsEditAction.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Setup cobbler form values These include, kernel options and virt options
 * @param ctx the RequestContext
 * @param form The form
 * @param data the kickstart data
 */
public static void setupCobblerFormValues(RequestContext ctx, DynaActionForm form, KickstartData data) {
    Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(ctx.getCurrentUser()), data.getCobblerId());
    if (prof != null) {
        form.set(KERNEL_OPTIONS, prof.getKernelOptionsString());
        form.set(POST_KERNEL_OPTIONS, prof.getKernelOptionsPostString());
    }
    KickstartVirtualizationType type = data.getKickstartDefaults().getVirtualizationType();
    // Should we show virt options?
    if (!type.equals(KickstartVirtualizationType.paraHost()) && !type.equals(KickstartVirtualizationType.none())) {
        if (prof == null) {
            form.set(VIRT_BRIDGE, data.getDefaultVirtBridge());
            form.set(VIRT_CPU, ConfigDefaults.get().getDefaultVirtCpus());
            form.set(VIRT_DISK_SIZE, ConfigDefaults.get().getDefaultVirtDiskSize());
            form.set(VIRT_MEMORY, ConfigDefaults.get().getDefaultVirtMemorySize(data));
        } else {
            setFormValueOrDefault(form, VIRT_BRIDGE, prof.getVirtBridge(), data.getDefaultVirtBridge());
            setFormValueOrDefault(form, VIRT_CPU, prof.getVirtCpus(), ConfigDefaults.get().getDefaultVirtCpus());
            setFormValueOrDefault(form, VIRT_DISK_SIZE, prof.getVirtFileSize(), ConfigDefaults.get().getDefaultVirtDiskSize());
            setFormValueOrDefault(form, VIRT_MEMORY, prof.getVirtRam(), ConfigDefaults.get().getDefaultVirtMemorySize(data));
        }
        ctx.getRequest().setAttribute(IS_VIRT, Boolean.TRUE);
    }
}

8 View Complete Implementation : CobblerSystemCreateCommand.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * Store the System to cobbler
 * @param saveCobblerId false if CobblerVirtualSystemCommand is calling, true otherwise
 * @return ValidatorError if the store failed.
 */
public ValidatorError store(boolean saveCobblerId) {
    Profile profile = Profile.lookupByName(getCobblerConnection(), profileName);
    // First lookup by MAC addr
    SystemRecord rec = lookupExisting(server);
    if (rec == null) {
        // Next try by name
        rec = SystemRecord.lookupByName(getCobblerConnection(user), getCobblerSystemRecordName());
    }
    // Else, lets make a new system
    if (rec == null) {
        rec = SystemRecord.create(getCobblerConnection(), getCobblerSystemRecordName(), profile);
    }
    try {
        processNetworkInterfaces(rec, server);
    } catch (XmlRpcException e) {
        if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("IP address duplicated")) {
            return new ValidatorError("frontend.actions.systems.virt.duplicateipaddressvalue", server.getName());
        }
        throw e;
    }
    rec.enableNetboot(true);
    rec.setProfile(profile);
    if (isDhcp) {
        rec.setIpv6Autoconfiguration(true);
    } else {
        rec.setIpv6Autoconfiguration(false);
    }
    if (this.activationKeys == null || this.activationKeys.length() == 0) {
        log.error("This cobbler profile does not " + "have a redhat_management_key set ");
    } else {
        rec.setRedHatManagementKey(activationKeys);
    }
    if (!StringUtils.isBlank(getKickstartHost())) {
        rec.setServer(getKickstartHost());
    } else {
        rec.setServer("");
    }
    // Setup the kickstart metadata so the URLs and activation key are setup
    Map<String, Object> ksmeta = rec.getKsMeta();
    if (ksmeta == null) {
        ksmeta = new HashMap<String, Object>();
    }
    if (!StringUtils.isBlank(mediaPath)) {
        ksmeta.put(KickstartUrlHelper.COBBLER_MEDIA_VARIABLE, this.mediaPath);
    }
    if (!StringUtils.isBlank(getKickstartHost())) {
        ksmeta.put(SystemRecord.REDHAT_MGMT_SERVER, getKickstartHost());
    }
    ksmeta.remove(KickstartFormatter.STATIC_NETWORK_VAR);
    ksmeta.put(KickstartFormatter.USE_IPV6_GATEWAY, this.useIpv6Gateway ? "true" : "false");
    if (this.ksDistro != null) {
        ksmeta.put(KickstartFormatter.KS_DISTRO, this.ksDistro);
    }
    rec.setKsMeta(ksmeta);
    Profile recProfile = rec.getProfile();
    if (recProfile != null && "suse".equals(recProfile.getDistro().getBreed())) {
        if (kernelOptions != null && kickstartHost != null && mediaPath != null && !kernelOptions.contains("install=")) {
            kernelOptions = kernelOptions + " install=http://" + kickstartHost + mediaPath;
        }
    }
    if (getServer().getHostname() != null) {
        rec.setHostName(getServer().getHostname());
    } else if (getServer().getName() != null) {
        rec.setHostName(getServer().getName());
    }
    rec.setKernelOptions(kernelOptions);
    rec.setKernelOptionsPost(postKernelOptions);
    // The comment is optional
    if (comment != null) {
        rec.setComment(comment);
    }
    try {
        rec.save();
    } catch (XmlRpcException e) {
        if (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().contains("IP address duplicated")) {
            return new ValidatorError("frontend.actions.systems.virt.duplicateipaddressvalue", server.getName());
        }
        throw e;
    }
    /*
         * This is a band-aid for the problem revealed in bug 846221. However
         * the real fix involves creating a new System for the virtual guest
         * instead of re-using the host System object, and I am unsure of what
         * effects that would have. The System object is used when creating
         * reActivation keys and setting up the cobbler SystemRecord network
         * info among other things. No bugs have been reported in those areas
         * yet, so I don't want to change something that has the potential to
         * break a lot of things.
         */
    if (saveCobblerId) {
        server.setCobblerId(rec.getId());
    }
    return new CobblerSyncCommand(user).store();
}

6 View Complete Implementation : ProvisionVirtualizationWizardAction.java
Copyright GNU General Public License v2.0
Author : uyuni-project
/**
 * {@inheritDoc}
 */
@Override
public ActionForward runSecond(ActionMapping mapping, DynaActionForm form, RequestContext ctx, HttpServletResponse response, WizardStep step) throws Exception {
    if (!validateFirstSelections(form, ctx)) {
        return runFirst(mapping, form, ctx, response, step);
    }
    ActionErrors errors = validateInput(form);
    if (!errors.isEmpty()) {
        addErrors(ctx.getRequest(), errors);
        // saveMessages(ctx.getRequest(), errors);
        return runFirst(mapping, form, ctx, response, step);
    }
    ActionForward forward = super.runSecond(mapping, form, ctx, response, step);
    Profile pf = getCobblerProfile(ctx);
    KickstartData ksdata = ctx.lookupAndBindKickstartData();
    if (StringUtils.isEmpty(form.getString(VIRTUAL_FILE_PATH))) {
        form.set(VIRTUAL_FILE_PATH, ProvisionVirtualInstanceCommand.makeDefaultVirtPath(form.getString(GUEST_NAME), ksdata.getKickstartDefaults().getVirtualizationType()));
    }
    if (StringUtils.isEmpty(form.getString(MEMORY_ALLOCATION))) {
        form.set(MEMORY_ALLOCATION, String.valueOf(pf.getVirtRam()));
    }
    if (StringUtils.isEmpty(form.getString(VIRTUAL_CPUS))) {
        form.set(VIRTUAL_CPUS, String.valueOf(pf.getVirtCpus()));
    }
    if (StringUtils.isEmpty(form.getString(LOCAL_STORAGE_GB))) {
        form.set(LOCAL_STORAGE_GB, String.valueOf(pf.getVirtFileSize()));
    }
    if (StringUtils.isEmpty(form.getString(VIRTUAL_BRIDGE))) {
        form.set(VIRTUAL_BRIDGE, String.valueOf(pf.getVirtBridge()));
    }
    if (StringUtils.isEmpty(form.getString(TARGET_PROFILE_TYPE))) {
        form.set(TARGET_PROFILE_TYPE, KickstartScheduleCommand.TARGET_PROFILE_TYPE_NONE);
    }
    return forward;
}

1 View Complete Implementation : SsmKSScheduleAction.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
private List<Action> schedule(HttpServletRequest request, ActionForm form, RequestContext context) {
    SSMScheduleCommand com = null;
    User user = context.getCurrentUser();
    DynaActionForm dynaForm = (DynaActionForm) form;
    DatePicker picker = getStrutsDelegate().prepopulateDatePicker(context.getRequest(), dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);
    List<SystemOverview> systems = KickstartManager.getInstance().kickstartableSystemsInSsm(user);
    if (isIP(request)) {
        com = SSMScheduleCommand.initIPKickstart(user, systems, picker.getDate());
    } else {
        ListHelper helper = new ListHelper(this, request);
        String cobblerId = ListTagHelper.getRadioSelection(helper.getListName(), request);
        KickstartData data = KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerId);
        if (data == null) {
            Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
            com = SSMScheduleCommand.initCobblerOnly(user, systems, picker.getDate(), prof.getName());
        } else {
            com = SSMScheduleCommand.init(user, systems, picker.getDate(), data);
        }
    }
    if (dynaForm.getString(USE_IPV6_GATEWAY).equals("1")) {
        com.setIpv6Gateway();
    }
    String proxyId = dynaForm.getString(ScheduleKickstartWizardAction.PROXY_HOST);
    if (!StringUtils.isEmpty(proxyId)) {
        Server proxy = ServerFactory.lookupById(Long.parseLong(proxyId));
        com.setProxy(proxy);
    }
    com.setProfileType(dynaForm.getString(ScheduleKickstartWizardAction.TARGET_PROFILE_TYPE));
    com.setServerProfileId((Long) dynaForm.get("targetServerProfile"));
    com.setPackageProfileId((Long) dynaForm.get("targetProfile"));
    // do kernel params
    com.setKernelParamType(dynaForm.getString(ScheduleKickstartWizardAction.KERNEL_PARAMS_TYPE));
    com.setCustomKernelParams(dynaForm.getString(ScheduleKickstartWizardAction.KERNEL_PARAMS));
    // do post kernel params
    com.setPostKernelParamType(dynaForm.getString(ScheduleKickstartWizardAction.POST_KERNEL_PARAMS_TYPE));
    com.setCustomPostKernelParams(dynaForm.getString(ScheduleKickstartWizardAction.POST_KERNEL_PARAMS));
    com.setNetworkDevice(dynaForm.getString(ScheduleKickstartWizardAction.NETWORK_TYPE), dynaForm.getString(ScheduleKickstartWizardAction.NETWORK_INTERFACE));
    List<ValidatorError> errors = com.store();
    return com.getScheduledActions();
}

1 View Complete Implementation : SsmKSScheduleAction.java
Copyright GNU General Public License v2.0
Author : uyuni-project
private ScheduleActionResult schedule(HttpServletRequest request, ActionForm form, RequestContext context) {
    SSMScheduleCommand com = null;
    User user = context.getCurrentUser();
    DynaActionForm dynaForm = (DynaActionForm) form;
    DatePicker picker = getStrutsDelegate().prepopulateDatePicker(context.getRequest(), dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);
    List<SystemOverview> systems = KickstartManager.getInstance().kickstartableSystemsInSsm(user);
    if (isIP(request)) {
        com = SSMScheduleCommand.initIPKickstart(user, systems, picker.getDate());
    } else {
        ListHelper helper = new ListHelper(this, request);
        String cobblerId = ListTagHelper.getRadioSelection(helper.getListName(), request);
        KickstartData data = KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerId);
        if (data == null) {
            Profile prof = Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
            com = SSMScheduleCommand.initCobblerOnly(user, systems, picker.getDate(), prof.getName());
        } else {
            com = SSMScheduleCommand.init(user, systems, picker.getDate(), data);
        }
    }
    if (dynaForm.getString(USE_IPV6_GATEWAY).equals("1")) {
        com.setIpv6Gateway();
    }
    String proxyId = dynaForm.getString(ScheduleKickstartWizardAction.PROXY_HOST);
    if (!StringUtils.isEmpty(proxyId)) {
        Server proxy = ServerFactory.lookupById(Long.parseLong(proxyId));
        com.setProxy(proxy);
    }
    com.setProfileType(dynaForm.getString(ScheduleKickstartWizardAction.TARGET_PROFILE_TYPE));
    com.setServerProfileId((Long) dynaForm.get("targetServerProfile"));
    com.setPackageProfileId((Long) dynaForm.get("targetProfile"));
    // do kernel params
    com.setKernelParamType(dynaForm.getString(ScheduleKickstartWizardAction.KERNEL_PARAMS_TYPE));
    com.setCustomKernelParams(dynaForm.getString(ScheduleKickstartWizardAction.KERNEL_PARAMS));
    // do post kernel params
    com.setPostKernelParamType(dynaForm.getString(ScheduleKickstartWizardAction.POST_KERNEL_PARAMS_TYPE));
    com.setCustomPostKernelParams(dynaForm.getString(ScheduleKickstartWizardAction.POST_KERNEL_PARAMS));
    com.setNetworkDevice(dynaForm.getString(ScheduleKickstartWizardAction.NETWORK_TYPE), dynaForm.getString(ScheduleKickstartWizardAction.NETWORK_INTERFACE));
    List<ValidatorError> errors = com.store();
    return new ScheduleActionResult(com.getScheduledActions().size(), errors);
}