Пример #1
0
  private static void createVM(String newVmName) throws Exception {
    /*First check we can start an HVM on the master*/
    checkMasterHvmCapable();

    VM template = getFirstWindowsTemplate();
    logln("Template found: " + template.getNameLabel(connection));

    /* Clone the template */
    VM newVm = template.createClone(connection, newVmName);
    logln("New clone: " + newVm.getNameLabel(connection));

    /* Find a storage repository */
    SR defaultSR = getDefaultSR();
    logln("Default SR: " + defaultSR.getNameLabel(connection));

    /* Find a network */
    Network network = getFirstNetwork();
    logln("Network chosen: " + network.getNameLabel(connection));

    /*
     * We have our clone and our network, attach them to each other with a
     * VIF
     */
    makeVIF(newVm, network, "0");

    /* Put the SR uuid into the provision XML */
    Map<String, String> otherConfig = newVm.getOtherConfig(connection);
    String disks = otherConfig.get("disks");
    disks = disks.replace("sr=\"\"", "sr=\"" + defaultSR.getUuid(connection) + "\"");
    otherConfig.put("disks", disks);
    newVm.setOtherConfig(connection, otherConfig);

    makeCDDrive(newVm);

    /* Now provision the disks */
    log("provisioning... ");
    newVm.provision(connection);
    logln("provisioned");

    /* Should have done the trick. Let's see if it starts. */
    logln("Starting new VM.....");
    newVm.start(connection, false, false);

    logln("Shutting it down (hard).....");
    newVm.hardShutdown(connection);
  }
Пример #2
0
  /** Adds a new internal network not attached to any NICs. */
  protected void TestCore() throws Exception {

    Network.Record networkRecord = new Network.Record();
    networkRecord.nameLabel = "TestNetwork" + new Random().nextInt(10000);
    networkRecord.nameDescription = "Created by AddNetwork.java at " + new Date().toString();

    log("Adding new network: " + networkRecord.nameLabel);
    Network.create(connection, networkRecord);
  }