mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-16 09:43:18 +09:00
Feature #487: Java API: Helpers to allocate VMs from registered Templates
This commit is contained in:
1 parent
f49a206adf
commit
48e7a8cd9c
2 files changed
+64
-1
No files matched your search
@@ -19,6 +19,7 @@ package org.opennebula.client.vm;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.PoolElement;
|
||||
import org.opennebula.client.template.Template;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
@@ -134,6 +135,56 @@ public class VirtualMachine extends PoolElement{
|
||||
return client.call(ALLOCATE, description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new VM in OpenNebula from a registered Template.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param templateId The source Template's ID
|
||||
* @param newName Name for the new VM, replaces the Template's one.
|
||||
* Can be null.
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this VM.
|
||||
*/
|
||||
public static OneResponse allocateFromTemplate(Client client,
|
||||
int templateId, String newName)
|
||||
{
|
||||
String template = "TEMPLATE_ID = " + templateId;
|
||||
if( newName != null )
|
||||
{
|
||||
template += "\nNAME = " + newName;
|
||||
}
|
||||
|
||||
return allocate(client, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new VM in OpenNebula from a registered Template.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param templateId The source Template's ID
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this VM.
|
||||
*/
|
||||
public static OneResponse allocateFromTemplate(Client client,
|
||||
int templateId)
|
||||
{
|
||||
return allocateFromTemplate(client, templateId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new VM in OpenNebula from a registered Template.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param template The source Template.
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this VM.
|
||||
*/
|
||||
public static OneResponse allocateFromTemplate(Client client,
|
||||
Template template)
|
||||
{
|
||||
return allocateFromTemplate(client, template.id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the information of the given VM.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.template.*;
|
||||
import org.opennebula.client.vm.VirtualMachine;
|
||||
|
||||
|
||||
|
||||
@@ -177,7 +178,7 @@ public class TemplateTest
|
||||
assertTrue( template.xpath("NAME").equals(name) );
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = template.delete();
|
||||
@@ -186,4 +187,15 @@ public class TemplateTest
|
||||
res = template.info();
|
||||
assertTrue( res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocateFromTemplate()
|
||||
{
|
||||
template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = VirtualMachine.allocateFromTemplate(client, template);
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getMessage().equals("0") );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user