1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

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

This commit is contained in:
Ruben S. Montero 2014-04-09 10:04:48 +02:00
commit d5262f0bf8
10 changed files with 435 additions and 27 deletions

View File

@ -176,7 +176,7 @@ public:
VirtualMachineSaveDisk():
RequestManagerVirtualMachine("VirtualMachineSaveDisk",
"Saves a disk from virtual machine as a new image",
"A:siissb"){};
"A:siissbb"){};
~VirtualMachineSaveDisk(){};

View File

@ -147,7 +147,7 @@ EOT
},
{
:name => 'admin_password',
:large => '--admin_password password',
:large => '--admin_password pass',
:short => "-p",
:description =>
'Password for the admin user of the group',
@ -155,7 +155,7 @@ EOT
},
{
:name => 'admin_driver',
:large => '--admin_driver auth_driver',
:large => '--admin_driver driver',
:short => "-d",
:description =>
'Auth driver for the admin user of the group',
@ -163,20 +163,20 @@ EOT
},
{
:name => 'resources',
:large => '--resources resources_str',
:large => '--resources res_str',
:short => "-r",
:description =>
'Which resources can be created by group users "\
"(VM+NET+IMAGE+TEMPLATE by default)',
"Which resources can be created by group users "<<
"(VM+NET+IMAGE+TEMPLATE by default)",
:format => String
},
{
:name => 'admin_resources',
:large => '--admin_resources resources_str',
:large => '--admin_resources res_str',
:short => "-o",
:description =>
'Which resources can be created by group users "\
"(VM+NET+IMAGE+TEMPLATE by default)',
"Which resources can be created by the admin user "<<
"(VM+NET+IMAGE+TEMPLATE by default)",
:format => String
}
]

View File

@ -46,9 +46,12 @@ class OneQuotaHelper
# ID = <ID of the image>
# RVMS = <Max. number of VMs using the image>
# ]
EOT
HELP_QUOTA_FOOTER = <<-EOT.unindent
#
# In any quota:
# -1 means use the default limit ('defaultquota' command)
# -1 means use the default limit (set with the 'defaultquota' command)
# 0 means unlimited.
#
# The usage counters "*_USED" are shown for information
@ -56,12 +59,23 @@ class OneQuotaHelper
#-----------------------------------------------------------------------
EOT
HELP_DEFAULT_QUOTA_FOOTER = <<-EOT.unindent
#
# In any quota:
# 0 means unlimited.
#
# The usage counters "*_USED" will always be 0 for the default
# quotas, and can be ignored.
#-----------------------------------------------------------------------
EOT
# Edits the quota template of a resource
# @param [XMLElement] resource to get the current info from
# @param [String] path to the new contents. If nil a editor will be
# used
# @param [True|False] is_default To change the help text
# @return [String] contents of the new quotas
def self.set_quota(resource, path)
def self.set_quota(resource, path, is_default=false)
str = ""
if path.nil?
@ -71,6 +85,13 @@ class OneQuotaHelper
path = tmp.path
tmp << HELP_QUOTA
if (is_default)
tmp << HELP_DEFAULT_QUOTA_FOOTER
else
tmp << HELP_QUOTA_FOOTER
end
tmp << resource.template_like_str("DATASTORE_QUOTA") << "\n"
tmp << resource.template_like_str("VM_QUOTA") << "\n"
tmp << resource.template_like_str("NETWORK_QUOTA") << "\n"

View File

@ -79,17 +79,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Examples:
- using a template description file:
onegroup create group_description.tmpl
- create a group with admin user and allow group users
to only create new templates and VMs, and group admin to manage
templates, vms, images and virtual networks
onegroup create --name groupA
--admin_user admin_userA --admin_password somestr
--resource TEMPLATE+VM
--resources TEMPLATE+VM
--admin_resources TEMPLATE+VM+IMAGE+NET
EOT
@ -232,7 +228,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit(-1)
end
str = OneQuotaHelper.set_quota(default_quotas, args[0])
str = OneQuotaHelper.set_quota(default_quotas, args[0], true)
rc = system.set_group_quotas(str)

View File

@ -265,7 +265,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit(-1)
end
str = OneQuotaHelper.set_quota(default_quotas, args[0])
str = OneQuotaHelper.set_quota(default_quotas, args[0], true)
rc = system.set_user_quotas(str)

View File

@ -32,6 +32,9 @@ public class Group extends PoolElement{
private static final String INFO = METHOD_PREFIX + "info";
private static final String DELETE = METHOD_PREFIX + "delete";
private static final String QUOTA = METHOD_PREFIX + "quota";
private static final String ADD_PROVIDER = METHOD_PREFIX + "addprovider";
private static final String DEL_PROVIDER = METHOD_PREFIX + "delprovider";
private static final String UPDATE = METHOD_PREFIX + "update";
/**
* Creates a new Group representation.
@ -108,6 +111,51 @@ public class Group extends PoolElement{
return client.call(QUOTA, id, quota_template);
}
/**
* Adds a resource provider to this group
*
* @param client XML-RPC Client.
* @param id The group id.
* @param zoneId The zone id.
* @param clusterId The cluster id.
* @return A encapsulated response.
*/
public static OneResponse addProvider(Client client, int id,
int zoneId, int clusterId)
{
return client.call(ADD_PROVIDER, id, zoneId, clusterId);
}
/**
* Deletes a resource provider from this group
*
* @param client XML-RPC Client.
* @param id The group id.
* @param zoneId The zone id.
* @param clusterId The cluster id.
* @return A encapsulated response.
*/
public static OneResponse delProvider(Client client, int id,
int zoneId, int clusterId)
{
return client.call(DEL_PROVIDER, id, zoneId, clusterId);
}
/**
* Replaces the template contents.
*
* @param client XML-RPC Client.
* @param id The group id of the target group we want to modify.
* @param new_template New template contents
* @param append True to append new attributes instead of replace the whole template
* @return If successful the message contains the group id.
*/
public static OneResponse update(Client client, int id, String new_template,
boolean append)
{
return client.call(UPDATE, id, new_template, append ? 1 : 0);
}
// =================================
// Instanced object XML-RPC methods
// =================================
@ -146,6 +194,53 @@ public class Group extends PoolElement{
return setQuota(client, id, quota_template);
}
/**
* Adds a resource provider to this group
*
* @param zoneId The zone id.
* @param clusterId The cluster id.
* @return A encapsulated response.
*/
public OneResponse addProvider(int zoneId, int clusterId)
{
return addProvider(client, id, zoneId, clusterId);
}
/**
* Deletes a resource provider from this group
*
* @param zoneId The zone id.
* @param clusterId The cluster id.
* @return A encapsulated response.
*/
public OneResponse delProvider(int zoneId, int clusterId)
{
return delProvider(client, id, zoneId, clusterId);
}
/**
* Replaces the template contents.
*
* @param new_template New template contents
* @return If successful the message contains the group id.
*/
public OneResponse update(String new_template)
{
return update(new_template, false);
}
/**
* Replaces the template contents.
*
* @param new_template New template contents
* @param append True to append new attributes instead of replace the whole template
* @return If successful the message contains the group id.
*/
public OneResponse update(String new_template, boolean append)
{
return update(client, id, new_template, append);
}
// =================================
// Helpers
// =================================

View File

@ -365,12 +365,16 @@ public class VirtualMachine extends PoolElement{
* the default type
* @param hot True to save the disk immediately, false will perform
* the operation when the VM shuts down
* @param doTemplate True to clone also the VM originating template
* and replace the disk with the saved image
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse diskSnapshot(Client client, int id,
int diskId, String imageName, String imageType, boolean hot)
int diskId, String imageName, String imageType,
boolean hot, boolean doTemplate)
{
return client.call(SAVEDISK, id ,diskId, imageName, imageType, hot);
return client.call(SAVEDISK, id ,diskId, imageName, imageType,
hot, doTemplate);
}
/**
@ -707,12 +711,15 @@ public class VirtualMachine extends PoolElement{
* the default type
* @param hot True to save the disk immediately, false will perform
* the operation when the VM shuts down
* @param doTemplate True to clone also the VM originating template
* and replace the disk with the saved image
* @return If an error occurs the error message contains the reason.
*/
public OneResponse diskSnapshot(int diskId, String imageName,
String imageType, boolean hot)
String imageType, boolean hot, boolean doTemplate)
{
return diskSnapshot(client, id, diskId, imageName, imageType, hot);
return diskSnapshot(client, id, diskId, imageName, imageType,
hot, doTemplate);
}
/**
@ -725,7 +732,7 @@ public class VirtualMachine extends PoolElement{
*/
public OneResponse diskSnapshot(int diskId, String imageName)
{
return diskSnapshot(diskId, imageName, "", false);
return diskSnapshot(diskId, imageName, "", false, false);
}
/**
@ -739,7 +746,7 @@ public class VirtualMachine extends PoolElement{
*/
public OneResponse diskSnapshot(int diskId, String imageName, boolean hot)
{
return diskSnapshot(diskId, imageName, "", hot);
return diskSnapshot(diskId, imageName, "", hot, false);
}
/**
@ -1136,11 +1143,11 @@ public class VirtualMachine extends PoolElement{
}
/**
* @deprecated Replaced by {@link #diskSnapshot(int,String,String,boolean)}
* @deprecated Replaced by {@link #diskSnapshot(int,String,String,boolean,boolean)}
*/
public OneResponse savedisk(int diskId, String imageName, String imageType)
{
return diskSnapshot(diskId, imageName, imageType, false);
return diskSnapshot(diskId, imageName, imageType, false, false);
}
/**

View File

@ -0,0 +1,187 @@
/*******************************************************************************
* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.zone;
import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.PoolElement;
import org.w3c.dom.Node;
/**
* This class represents an OpenNebula zone.
* It also offers static XML-RPC call wrappers.
*/
public class Zone extends PoolElement{
private static final String METHOD_PREFIX = "zone.";
private static final String INFO = METHOD_PREFIX + "info";
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
private static final String UPDATE = METHOD_PREFIX + "update";
private static final String RENAME = METHOD_PREFIX + "rename";
private static final String DELETE = METHOD_PREFIX + "delete";
/**
* Creates a new Zone representation.
*
* @param id The zone id.
* @param client XML-RPC Client.
*/
public Zone(int id, Client client)
{
super(id, client);
}
/**
* @see PoolElement
*/
protected Zone(Node xmlElement, Client client)
{
super(xmlElement, client);
}
// =================================
// Static XML-RPC methods
// =================================
/**
* Allocates a new Zone in OpenNebula.
*
* @param client XML-RPC Client.
* @param description A string containing the template of the zone.
* @return If successful the message contains the associated
* id generated for this Zone.
*/
public static OneResponse allocate(Client client, String description)
{
return client.call(ALLOCATE, description);
}
/**
* Retrieves the information of the given zone.
*
* @param client XML-RPC Client.
* @param id The zone id.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client, int id)
{
return client.call(INFO, id);
}
/**
* Deletes a zone from OpenNebula.
*
* @param client XML-RPC Client.
* @param id The zone id.
* @return A encapsulated response.
*/
public static OneResponse delete(Client client, int id)
{
return client.call(DELETE, id);
}
/**
* Replaces the template contents.
*
* @param client XML-RPC Client.
* @param id The zone id of the target zone we want to modify.
* @param new_template New template contents
* @param append True to append new attributes instead of replace the whole template
* @return If successful the message contains the zone id.
*/
public static OneResponse update(Client client, int id, String new_template,
boolean append)
{
return client.call(UPDATE, id, new_template, append ? 1 : 0);
}
/**
* Renames this Zone
*
* @param client XML-RPC Client.
* @param id The Zone id of the target Zone.
* @param name New name for the Zone.
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse rename(Client client, int id, String name)
{
return client.call(RENAME, id, name);
}
// =================================
// Instanced object XML-RPC methods
// =================================
/**
* Loads the xml representation of the zone.
* The info is also stored internally.
*
* @see Zone#info(Client, int)
*/
public OneResponse info()
{
OneResponse response = info(client, id);
super.processInfo(response);
return response;
}
/**
* Deletes the zone from OpenNebula.
*
* @see Zone#delete(Client, int)
*/
public OneResponse delete()
{
return delete(client, id);
}
/**
* Renames this Zone
*
* @param name New name for the Zone.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse rename(String name)
{
return rename(client, id, name);
}
/**
* Replaces the template contents.
*
* @param new_template New template contents
* @return If successful the message contains the zone id.
*/
public OneResponse update(String new_template)
{
return update(new_template, false);
}
/**
* Replaces the template contents.
*
* @param new_template New template contents
* @param append True to append new attributes instead of replace the whole template
* @return If successful the message contains the zone id.
*/
public OneResponse update(String new_template, boolean append)
{
return update(client, id, new_template, append);
}
}

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.zone;
import java.util.AbstractList;
import java.util.Iterator;
import org.opennebula.client.Client;
import org.opennebula.client.OneResponse;
import org.opennebula.client.Pool;
import org.opennebula.client.PoolElement;
import org.w3c.dom.Node;
/**
* This class represents an OpenNebula zone pool.
* It also offers static XML-RPC call wrappers.
*/
public class ZonePool extends Pool implements Iterable<Zone>{
private static final String ELEMENT_NAME = "ZONE";
private static final String INFO_METHOD = "zonepool.info";
/**
* Creates a new zone pool
* @param client XML-RPC Client.
*/
public ZonePool(Client client)
{
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
public PoolElement factory(Node node)
{
return new Zone(node, client);
}
/**
* Retrieves all the zones in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info(Client client)
{
return Pool.info(client, INFO_METHOD);
}
/**
* Loads the xml representation of the zone pool.
*
* @see ZonePool#info(Client)
*/
public OneResponse info()
{
return super.info();
}
public Iterator<Zone> iterator()
{
AbstractList<Zone> ab = new AbstractList<Zone>()
{
public int size()
{
return getLength();
}
public Zone get(int index)
{
return (Zone) item(index);
}
};
return ab.iterator();
}
/**
* Returns the Zone with the given Id from the pool. If it is not found,
* then returns null. The method {@link #info()} must be called before.
*
* @param id of the Zone to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Zone getById(int id)
{
return (Zone) super.getById(id);
}
}

View File

@ -393,7 +393,6 @@ module OpenNebula
# perform the operation when the VM shuts down
# @param do_template [true|false] True to clone also the VM originating
# template and replace the disk with the saved image
# perform the operation when the VM shuts down
#
# @return [Integer, OpenNebula::Error] the new Image ID in case of
# success, error otherwise