1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Ruben S. Montero 2012-06-22 13:42:38 +02:00
commit abc580309d
12 changed files with 79 additions and 72 deletions

View File

@ -31,7 +31,7 @@ class RequestManagerClone: public Request
protected:
RequestManagerClone(const string& method_name,
const string& help,
const string& params)
const string& params = "A:sis")
:Request(method_name,params,help)
{};
@ -45,7 +45,7 @@ protected:
virtual Template * clone_template(PoolObjectSQL* obj) = 0;
virtual int pool_allocate(
xmlrpc_c::paramList const& paramList,
int source_id,
Template * tmpl,
int& id,
string& error_str,
@ -60,8 +60,7 @@ class VMTemplateClone : public RequestManagerClone
public:
VMTemplateClone():
RequestManagerClone("VMTemplateClone",
"Clone an existing virtual machine template",
"A:sis")
"Clone an existing virtual machine template")
{
Nebula& nd = Nebula::instance();
pool = nd.get_tpool();
@ -80,7 +79,7 @@ public:
};
int pool_allocate(
xmlrpc_c::paramList const& paramList,
int source_id,
Template * tmpl,
int& id,
string& error_str,
@ -105,8 +104,7 @@ class DocumentClone : public RequestManagerClone
public:
DocumentClone():
RequestManagerClone("DocumentClone",
"Clone an existing generic document",
"A:sisi")
"Clone an existing generic document")
{
Nebula& nd = Nebula::instance();
pool = nd.get_docpool();
@ -125,18 +123,17 @@ public:
};
int pool_allocate(
xmlrpc_c::paramList const& paramList,
int source_id,
Template * tmpl,
int& id,
string& error_str,
RequestAttributes& att)
{
int type = xmlrpc_c::value_int(paramList.getInt(3));
DocumentPool * docpool = static_cast<DocumentPool *>(pool);
Document * doc = docpool->get(source_id, true);
return docpool->allocate(att.uid, att.gid, att.uname, att.gname, type,
tmpl, &id, error_str);
return docpool->allocate(att.uid, att.gid, att.uname, att.gname,
doc->get_document_type(), tmpl, &id, error_str);
};
};

View File

@ -37,6 +37,8 @@ require 'cli/cli_helper'
require 'rubygems'
require 'json'
USER_AGENT = "CLI"
#
# Options
#
@ -113,7 +115,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.list
@ -142,7 +145,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.create(File.read(args[0]))
@ -165,7 +169,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.show(args[0])

View File

@ -19,12 +19,14 @@ require 'cloud/CloudClient'
module Market
class Client
def initialize(username, password, url)
def initialize(username, password, url, user_agent="Ruby")
@username = username
@password = password
url ||= 'http://localhost:9292/'
url ||= 'http://localhost:9292/'
@uri = URI.parse(url)
@user_agent = "OpenNebula 3.5.80 (#{user_agent})"
end
def get(path)
@ -47,6 +49,8 @@ module Market
req.basic_auth @username, @password
end
req['User-Agent'] = @user_agent
res = CloudClient::http_start(@uri, @timeout) do |http|
http.request(req)
end
@ -57,8 +61,8 @@ module Market
class ApplianceClient < Client
def initialize(user, password, url)
super(user, password, url)
def initialize(user, password, url, agent)
super(user, password, url, agent)
end
def list

View File

@ -34,11 +34,6 @@ import org.w3c.dom.Node;
* {
* private static final int TYPE = 200;
*
* protected int type()
* {
* return TYPE;
* }
*
* public GenericObjA(int id, Client client)
* {
* super(id, client);
@ -89,8 +84,6 @@ public abstract class Document extends PoolElement
super(xmlElement, client);
}
protected abstract int type();
// =================================
// Static XML-RPC methods
// =================================
@ -219,7 +212,7 @@ public abstract class Document extends PoolElement
*/
public OneResponse clone(String name)
{
return client.call(CLONE, id, name, type());
return client.call(CLONE, id, name);
}
// =================================

View File

@ -7,12 +7,6 @@ public class GenericObjA extends Document
{
private static final int TYPE = 200;
@Override
protected int type()
{
return TYPE;
}
public GenericObjA(int id, Client client)
{
super(id, client);

View File

@ -7,12 +7,6 @@ public class GenericObjB extends Document
{
private static final int TYPE = 201;
@Override
protected int type()
{
return TYPE;
}
public GenericObjB(int id, Client client)
{
super(id, client);

View File

@ -22,7 +22,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.datastore.Datastore;
import org.opennebula.client.image.*;
@ -52,7 +51,7 @@ public class ImageTest
* Wait until the Image changes to the specified state.
* There is a time-out of 10 seconds.
*/
void waitAssert(Image img, String state)
static void waitAssert(Image img, String state)
{
int n_steps = 10;
int step = 1000;

View File

@ -24,6 +24,7 @@ import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.datastore.Datastore;
import org.opennebula.client.host.Host;
import org.opennebula.client.image.Image;
import org.opennebula.client.vm.VirtualMachine;
import org.opennebula.client.vm.VirtualMachinePool;
@ -45,7 +46,7 @@ public class VirtualMachineTest
/**
* Wait until the VM changes to the specified state.
* There is a time-out of 10 seconds.
*/
*/
void waitAssert(VirtualMachine vm, String state, String lcmState)
{
int n_steps = 100;
@ -108,6 +109,7 @@ public class VirtualMachineTest
{
String template = "NAME = " + name + "\n"+
"MEMORY = 512\n" +
"CPU = 1\n" +
"CONTEXT = [DNS = 192.169.1.4]";
res = VirtualMachine.allocate(client, template);
@ -132,7 +134,7 @@ public class VirtualMachineTest
public void allocate()
{
res = vmPool.info();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
boolean found = false;
for(VirtualMachine vm : vmPool)
@ -147,7 +149,7 @@ public class VirtualMachineTest
public void update()
{
res = vm.info();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
assertTrue( vm.getName().equals(name) );
}
@ -156,7 +158,7 @@ public class VirtualMachineTest
public void hold()
{
res = vm.hold();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "HOLD", "-");
}
@ -166,7 +168,7 @@ public class VirtualMachineTest
vm.hold();
res = vm.release();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "PENDING", "-");
}
@ -174,7 +176,7 @@ public class VirtualMachineTest
public void deploy()
{
res = vm.deploy(hid_A);
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "ACTIVE", "RUNNING");
}
@ -185,7 +187,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.migrate(hid_B);
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "ACTIVE", "RUNNING");
}
@ -196,7 +198,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.liveMigrate(hid_B);
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "ACTIVE", "RUNNING");
}
@ -207,7 +209,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.shutdown();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "DONE", "-");
}
@ -218,7 +220,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.cancel();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "DONE", "-");
}
@ -229,7 +231,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.stop();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "STOPPED", "-");
}
@ -240,7 +242,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.suspend();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "SUSPENDED", "-");
}
@ -254,7 +256,7 @@ public class VirtualMachineTest
waitAssert(vm, "SUSPENDED", "-");
res = vm.resume();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "ACTIVE", "RUNNING");
}
@ -265,7 +267,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.finalizeVM();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "DONE", "-");
}
@ -282,7 +284,7 @@ public class VirtualMachineTest
waitAssert(vm, "ACTIVE", "RUNNING");
res = vm.resubmit();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
waitAssert(vm, "PENDING", "-");
}
@ -290,7 +292,7 @@ public class VirtualMachineTest
public void attributes()
{
res = vm.info();
assertTrue( !res.isError() );
assertTrue( res.getErrorMessage(), !res.isError() );
assertTrue( vm.xpath("NAME").equals(name) );
assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") );
@ -299,29 +301,44 @@ public class VirtualMachineTest
assertTrue( vm.xpath("TEMPLATE/CONTEXT/DNS").equals("192.169.1.4") );
}
// TODO
// @Test
@Test
public void savedisk()
{
String img_template =
"NAME = \"test_img\"\n" +
"PATH = /etc/hosts\n" +
"ATT1 = \"VAL1\"\n" +
"ATT2 = \"VAL2\"";
res = Image.allocate(client, img_template, 1);
assertTrue( res.getErrorMessage(), !res.isError() );
int imgid = Integer.parseInt(res.getMessage());
Image img = new Image(imgid, client);
ImageTest.waitAssert(img, "READY");
String template = "NAME = savedisk_vm\n"+
"MEMORY = 512\n" +
"CPU = 1\n" +
"CONTEXT = [DNS = 192.169.1.4]\n" +
"DISK = [ TYPE = fs, SIZE = 4, " +
"FORMAT = ext3, TARGET = sdg ]";
"DISK = [ IMAGE = test_img ]";
res = VirtualMachine.allocate(client, template);
assertTrue( res.getErrorMessage(), !res.isError() );
int vmid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
vm = new VirtualMachine(vmid, client);
res = vm.savedisk(0, "New_image");
assertTrue( !res.isError() );
assertTrue( res.getMessage().equals("0") );
assertTrue( res.getErrorMessage(), !res.isError() );
int new_imgid = Integer.parseInt(res.getMessage());
assertTrue( new_imgid == imgid+1 );
res = vm.info();
assertTrue( !res.isError() );
assertTrue( vm.xpath("TEMPLATE/DISK/SAVE_AS").equals(("0")) );
assertTrue( res.getErrorMessage(), !res.isError() );
}
}

View File

@ -156,7 +156,7 @@ module OpenNebula
def clone(name)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name, TYPE)
rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name)
return rc
end

View File

@ -80,7 +80,7 @@ void RequestManagerClone::request_execute(
}
}
rc = pool_allocate(paramList, tmpl, new_id, error_str, att);
rc = pool_allocate(source_id, tmpl, new_id, error_str, att);
if ( rc < 0 )
{

View File

@ -17,11 +17,14 @@
require 'marketplace/marketplace_client'
module SunstoneMarketplace
USER_AGENT = "Sunstone"
def get_appliance_pool
client = Market::ApplianceClient.new(
@config[:marketplace_username],
@config[:marketplace_password],
@config[:marketplace_url])
@config[:marketplace_url],
USER_AGENT)
response = client.list
@ -37,7 +40,8 @@ module SunstoneMarketplace
client = Market::ApplianceClient.new(
@config[:marketplace_username],
@config[:marketplace_password],
@config[:marketplace_url])
@config[:marketplace_url],
USER_AGENT)
response = client.show(app_id)

View File

@ -34,7 +34,7 @@ DATASTORE=`basename $TEMP_PATH`
DISK_PATH="/vmfs/volumes/$DATASTORE/$VM_ID/$DISK_NAME/disk.vmdk"
# Get the VMware ID corresponding to the deploy_id
VMWAREID=`vim-cmd vmsvc/getallvms|grep $DEPLOYID|cut -d' ' -f 1`
VMWAREID=`$SUDO vim-cmd vmsvc/getallvms|grep $DEPLOYID|cut -d' ' -f 1`
ATTACH_PARAMS="$VMWAREID $DISK_PATH $CONTROLLER_NUMBER $TARGET_NUMBER $DATASTORE"