mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
Merge branch 'feature-1291'
This commit is contained in:
commit
8f809df025
41 files changed
+1352
-236
No files matched your search
@@ -31,6 +31,8 @@ import org.w3c.dom.Node;
|
||||
*/
|
||||
public class ClusterPool extends Pool implements Iterable<Cluster>{
|
||||
|
||||
public static final int NONE_CLUSTER_ID = -1;
|
||||
|
||||
private static final String ELEMENT_NAME = "CLUSTER";
|
||||
private static final String INFO_METHOD = "clusterpool.info";
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.opennebula.client.datastore;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.PoolElement;
|
||||
import org.opennebula.client.cluster.ClusterPool;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
@@ -57,6 +58,21 @@ public class Datastore extends PoolElement
|
||||
// Static XML-RPC methods
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Allocates a new Datastore in OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param description A string containing the template of the datastore.
|
||||
* @param clusterId Id of the cluster
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this Datastore.
|
||||
*/
|
||||
public static OneResponse allocate(Client client,
|
||||
String description, int clusterId)
|
||||
{
|
||||
return client.call(ALLOCATE, description, clusterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new Datastore in OpenNebula.
|
||||
*
|
||||
@@ -67,7 +83,7 @@ public class Datastore extends PoolElement
|
||||
*/
|
||||
public static OneResponse allocate(Client client, String description)
|
||||
{
|
||||
return client.call(ALLOCATE, description);
|
||||
return allocate(client, description, ClusterPool.NONE_CLUSTER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +141,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The id of the target datastore we want to modify.
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
@@ -139,7 +155,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the datastore permissions
|
||||
*
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The id of the target datastore.
|
||||
* @param owner_u 1 to allow, 0 deny, -1 do not change
|
||||
@@ -166,7 +182,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the permissions
|
||||
*
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The id of the target object.
|
||||
* @param octet Permissions octet, e.g. 640
|
||||
@@ -179,7 +195,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the permissions
|
||||
*
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The id of the target object.
|
||||
* @param octet Permissions octed , e.g. 640
|
||||
@@ -261,7 +277,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
*
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
@@ -273,7 +289,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the owner
|
||||
*
|
||||
*
|
||||
* @param uid The new owner user ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
@@ -284,7 +300,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the group
|
||||
*
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
@@ -295,7 +311,7 @@ public class Datastore extends PoolElement
|
||||
|
||||
/**
|
||||
* Changes the datastore permissions
|
||||
*
|
||||
*
|
||||
* @param owner_u 1 to allow, 0 deny, -1 do not change
|
||||
* @param owner_m 1 to allow, 0 deny, -1 do not change
|
||||
* @param owner_a 1 to allow, 0 deny, -1 do not change
|
||||
|
||||
@@ -36,9 +36,11 @@ public class Host extends PoolElement{
|
||||
private static final String MONITORING = METHOD_PREFIX + "monitoring";
|
||||
|
||||
private static final String[] HOST_STATES =
|
||||
{"INIT", "MONITORING_MONITORED", "MONITORED", "ERROR", "DISABLED",
|
||||
{"INIT", "MONITORING_MONITORED", "MONITORED", "ERROR", "DISABLED",
|
||||
"MONITORING_ERROR"};
|
||||
|
||||
private static final String[] SHORT_HOST_STATES =
|
||||
{"init", "update", "on", "err", "off", "retry"};
|
||||
|
||||
/**
|
||||
* Creates a new Host representation.
|
||||
@@ -290,24 +292,8 @@ public class Host extends PoolElement{
|
||||
*/
|
||||
public String shortStateStr()
|
||||
{
|
||||
String st = stateStr();
|
||||
|
||||
if(st == null)
|
||||
return null;
|
||||
else if(st.equals("ERROR"))
|
||||
return "err";
|
||||
else if (st.equals("DISABLED"))
|
||||
return "off";
|
||||
else if (st.equals("INIT"))
|
||||
return "init";
|
||||
else if (st.equals("MONITORING_MONITORED"))
|
||||
return "update";
|
||||
else if (st.equals("MONITORED"))
|
||||
return "on";
|
||||
else if (st.equals("MONITORING_ERROR"))
|
||||
return "retry";
|
||||
|
||||
return "";
|
||||
int state = state();
|
||||
return state != -1 ? SHORT_HOST_STATES[state()] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,20 +28,23 @@ public class Image extends PoolElement
|
||||
{
|
||||
|
||||
private static final String METHOD_PREFIX = "image.";
|
||||
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
private static final String ENABLE = METHOD_PREFIX + "enable";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
private static final String CHMOD = METHOD_PREFIX + "chmod";
|
||||
private static final String CHTYPE = METHOD_PREFIX + "chtype";
|
||||
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
private static final String ENABLE = METHOD_PREFIX + "enable";
|
||||
private static final String PERSISTENT = METHOD_PREFIX + "persistent";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
private static final String CHMOD = METHOD_PREFIX + "chmod";
|
||||
private static final String CHTYPE = METHOD_PREFIX + "chtype";
|
||||
private static final String CLONE = METHOD_PREFIX + "clone";
|
||||
|
||||
private static final String[] IMAGE_STATES =
|
||||
{"INIT", "READY", "USED", "DISABLED"};
|
||||
{"INIT", "READY", "USED", "DISABLED", "LOCKED",
|
||||
"ERROR", "CLONE", "DELETE", "USED_PERS"};
|
||||
|
||||
private static final String[] SHORT_IMAGE_STATES =
|
||||
{"init", "rdy", "used", "disa"};
|
||||
{"init", "rdy", "used", "disa", "lock", "err", "clon", "dele", "used"};
|
||||
|
||||
private static final String[] IMAGE_TYPES =
|
||||
{"OS", "CDROM", "DATABLOCK"};
|
||||
@@ -76,7 +79,7 @@ public class Image extends PoolElement
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param description A string containing the template of the image.
|
||||
* @param clusterId The cluster ID. If it is -1, this image
|
||||
* @param datastoreId The cluster ID. If it is -1, this image
|
||||
* won't be added to any cluster.
|
||||
*
|
||||
* @return If successful the message contains the associated
|
||||
@@ -85,22 +88,9 @@ public class Image extends PoolElement
|
||||
public static OneResponse allocate(
|
||||
Client client,
|
||||
String description,
|
||||
int clusterId)
|
||||
int datastoreId)
|
||||
{
|
||||
return client.call(ALLOCATE, description, clusterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new Image in OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param description A string containing the template of the image.
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this Image.
|
||||
*/
|
||||
public static OneResponse allocate(Client client, String description)
|
||||
{
|
||||
return allocate(client, description, -1);
|
||||
return client.call(ALLOCATE, description, datastoreId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,6 +144,19 @@ public class Image extends PoolElement
|
||||
return client.call(ENABLE, id, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Image as persistent or not persistent.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The image id of the target image we want to modify.
|
||||
* @param persistent True to make it persistent, false non-persistent
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public static OneResponse persistent(Client client, int id, boolean persistent)
|
||||
{
|
||||
return client.call(PERSISTENT, id, persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes or unpublishes an image.
|
||||
*
|
||||
@@ -249,6 +252,19 @@ public class Image extends PoolElement
|
||||
return client.call(CHTYPE, id, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this Image into a new one
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The Image id of the target Image.
|
||||
* @param name Name for the new Image.
|
||||
* @return If successful the message contains the new Image ID.
|
||||
*/
|
||||
public static OneResponse clone(Client client, int id, String name)
|
||||
{
|
||||
return client.call(CLONE, id, name);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
@@ -318,6 +334,37 @@ public class Image extends PoolElement
|
||||
return enable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Image as persistent or not persistent.
|
||||
*
|
||||
* @param persistent True for enabling, false for disabling.
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public OneResponse persistent(boolean persistent)
|
||||
{
|
||||
return persistent(client, id, persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Image as persistent
|
||||
*
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public OneResponse persistent()
|
||||
{
|
||||
return persistent(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Image as persistent or not persistent.
|
||||
*
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public OneResponse nonpersistent()
|
||||
{
|
||||
return persistent(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes or unpublishes the image.
|
||||
*
|
||||
@@ -440,6 +487,17 @@ public class Image extends PoolElement
|
||||
return chtype(client, id, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this Image into a new one
|
||||
*
|
||||
* @param name Name for the new Image.
|
||||
* @return If successful the message contains the new Image ID.
|
||||
*/
|
||||
public OneResponse clone(String name)
|
||||
{
|
||||
return clone(client, id, name);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
||||
@@ -97,7 +97,7 @@ public class VirtualMachine extends PoolElement{
|
||||
"shut",
|
||||
"shut",
|
||||
"fail",
|
||||
"dele",
|
||||
"clea",
|
||||
"unkn" };
|
||||
|
||||
/**
|
||||
@@ -523,7 +523,7 @@ public class VirtualMachine extends PoolElement{
|
||||
*/
|
||||
public OneResponse restart()
|
||||
{
|
||||
return action("shutdown");
|
||||
return action("restart");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -22,6 +22,7 @@ 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.*;
|
||||
|
||||
|
||||
@@ -47,6 +48,33 @@ public class ImageTest
|
||||
"ATT2 = \"VAL2\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the Image changes to the specified state.
|
||||
* There is a time-out of 10 seconds.
|
||||
*/
|
||||
void waitAssert(Image img, String state)
|
||||
{
|
||||
int n_steps = 10;
|
||||
int step = 1000;
|
||||
|
||||
int i = 0;
|
||||
|
||||
img.info();
|
||||
|
||||
while( !( img.stateString().equals(state) || i > n_steps )
|
||||
&& !img.stateString().equals("ERROR") )
|
||||
{
|
||||
try{ Thread.sleep(step); } catch (Exception e){}
|
||||
|
||||
img.info();
|
||||
i++;
|
||||
}
|
||||
|
||||
assertTrue(
|
||||
"Image timeout, wanted state: " + state + "; it is in state "
|
||||
+ img.stateString(), img.stateString().equals(state) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@@ -71,10 +99,12 @@ public class ImageTest
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Image.allocate(client, template());
|
||||
res = Image.allocate(client, template(), 1);
|
||||
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
image = new Image(imgid, client);
|
||||
|
||||
waitAssert(image, "READY");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,15 +121,15 @@ public class ImageTest
|
||||
{
|
||||
image.delete();
|
||||
|
||||
res = Image.allocate(client, template());
|
||||
assertTrue( !res.isError() );
|
||||
res = Image.allocate(client, template(), 1);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
image = new Image(imgid, client);
|
||||
|
||||
|
||||
res = imagePool.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
boolean found = false;
|
||||
for(Image img : imagePool)
|
||||
@@ -110,12 +140,37 @@ public class ImageTest
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clone_method()
|
||||
{
|
||||
res = image.clone("cloned_image");
|
||||
assertTrue(res.getErrorMessage(), !res.isError());
|
||||
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
Image cloned_image = new Image(imgid, client);
|
||||
|
||||
res = imagePool.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
boolean found = false;
|
||||
for(Image img : imagePool)
|
||||
{
|
||||
found = found || img.getName().equals("cloned_image");
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
|
||||
res = cloned_image.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( cloned_image.getName().equals("cloned_image") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void info()
|
||||
{
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
// assertTrue( image.getId().equals("0") );
|
||||
// assertTrue( image.id() == 0 );
|
||||
assertTrue( image.getName().equals("test_img_"+cont) );
|
||||
@@ -125,7 +180,7 @@ public class ImageTest
|
||||
public void update()
|
||||
{
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
||||
@@ -134,65 +189,61 @@ public class ImageTest
|
||||
"ATT3 = VAL3";
|
||||
|
||||
res = image.update(new_template);
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
// @Test
|
||||
@Test
|
||||
public void enable()
|
||||
{
|
||||
res = image.enable();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( image.isEnabled() );
|
||||
}
|
||||
|
||||
// TODO
|
||||
// @Test
|
||||
@Test
|
||||
public void disable()
|
||||
{
|
||||
res = image.disable();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( !image.isEnabled() );
|
||||
assertTrue( res.getErrorMessage(), !image.isEnabled() );
|
||||
}
|
||||
// TODO
|
||||
/*
|
||||
|
||||
@Test
|
||||
public void publish()
|
||||
{
|
||||
res = image.publish();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( image.isPublic() );
|
||||
assertTrue( image.xpath("PERMISSIONS/GROUP_U").equals( "1" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpublish()
|
||||
{
|
||||
res = image.unpublish();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( !image.isPublic() );
|
||||
assertTrue( image.xpath("PERMISSIONS/GROUP_U").equals( "0" ) );
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
// assertTrue( image.xpath("ID").equals("0") );
|
||||
assertTrue( image.xpath("NAME").equals("test_img_"+cont) );
|
||||
@@ -202,7 +253,7 @@ public class ImageTest
|
||||
public void delete()
|
||||
{
|
||||
res = image.delete();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
// res = image.info();
|
||||
// assertTrue( res.isError() );
|
||||
|
||||
@@ -298,7 +298,7 @@ TM_MAD = [
|
||||
|
||||
DATASTORE_MAD = [
|
||||
executable = "one_datastore",
|
||||
arguments = "-t 15 -d fs,vmware,iscsi,dummy"
|
||||
arguments = "-t 15 -d fs,vmware,iscsi,lvm"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
@@ -406,10 +406,9 @@ HM_MAD = [
|
||||
# absolute path or relative to $ONE_LOCATION/lib/mads (or
|
||||
# /usr/lib/one/mads/ if OpenNebula was installed in /)
|
||||
#
|
||||
# arguments :
|
||||
# --authn: list of authentication modules separated by commas, if not
|
||||
# defined all the modules available will be enabled
|
||||
# --authz: authorization module
|
||||
# authn : list of authentication modules separated by commas, if not
|
||||
# defined all the modules available will be enabled
|
||||
# authz : list of authentication modules separated by commas
|
||||
#
|
||||
# SESSION_EXPIRATION_TIME: Time in seconds to keep an authenticated token as
|
||||
# valid. During this time, the driver is not used. Use 0 to disable session
|
||||
@@ -422,8 +421,8 @@ HM_MAD = [
|
||||
|
||||
AUTH_MAD = [
|
||||
executable = "one_auth_mad",
|
||||
arguments = "--authn ssh,x509,ldap,server_cipher,server_x509"
|
||||
# arguments = "--authz quota --authn ssh,x509,ldap,server_cipher,server_x509"
|
||||
authn = "ssh,x509,ldap,server_cipher,server_x509"
|
||||
# , authz = "quota"
|
||||
]
|
||||
|
||||
SESSION_EXPIRATION_TIME = 900
|
||||
|
||||
Reference in new issue
Block a user