1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Hector Sanjuan 2012-04-03 13:41:05 +02:00
commit 63045cdb38
32 changed files with 1987 additions and 251 deletions

View File

@ -299,8 +299,21 @@ protected:
*/
bool check(const string& ip);
/**
* Check if the passed ip corresponds with a given lease
* @param ip of the lease to be checked
* @return true if the ip was already assigned
*/
bool check(unsigned int ip);
/**
* Check if a VM is the owner of the ip
* @param ip of the lease to be checked
* @param vid the ID of the VM
* @return true if the ip was already assigned
*/
bool is_owner(const string& ip, int vid);
/**
* Reads the leases from the DB, and updates the lease hash table
* @param db pointer to the database.

View File

@ -136,7 +136,7 @@ public:
};
/**
* Release previously given lease
* Release previously given lease
* @param _ip IP identifying the lease
* @return 0 if success
*/
@ -145,6 +145,17 @@ public:
return leases->release(ip);
};
/**
* Check if a VM is the owner of the ip
* @param ip of the lease to be checked
* @param vid the ID of the VM
* @return true if the ip was already assigned
*/
bool is_owner (const string& ip, int vid)
{
return leases->is_owner(ip, vid);
};
/**
* Gets size of the network (used + free)
* @return number of hosts that can be fitted in this network

View File

@ -1035,6 +1035,11 @@ ECO_BIN_FILES="src/cloud/ec2/bin/econe-server \
src/cloud/ec2/bin/econe-register \
src/cloud/ec2/bin/econe-run-instances \
src/cloud/ec2/bin/econe-terminate-instances \
src/cloud/ec2/bin/econe-describe-addresses \
src/cloud/ec2/bin/econe-allocate-address \
src/cloud/ec2/bin/econe-release-address \
src/cloud/ec2/bin/econe-associate-address \
src/cloud/ec2/bin/econe-disassociate-address \
src/cloud/ec2/bin/econe-upload"
ECO_BIN_CLIENT_FILES="src/cloud/ec2/bin/econe-describe-images \
@ -1042,6 +1047,11 @@ ECO_BIN_CLIENT_FILES="src/cloud/ec2/bin/econe-describe-images \
src/cloud/ec2/bin/econe-register \
src/cloud/ec2/bin/econe-run-instances \
src/cloud/ec2/bin/econe-terminate-instances \
src/cloud/ec2/bin/econe-describe-addresses \
src/cloud/ec2/bin/econe-allocate-address \
src/cloud/ec2/bin/econe-release-address \
src/cloud/ec2/bin/econe-associate-address \
src/cloud/ec2/bin/econe-disassociate-address \
src/cloud/ec2/bin/econe-upload"
ECO_ETC_FILES="src/cloud/ec2/etc/econe.conf"

View File

@ -0,0 +1,125 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
COMMANDS_HELP=<<-EOT
econe-describe-images
Allocate a new elastic IP address for the user
Usage:
econe-allocate-address [OPTIONS]
Options:
--help, -h
Show help
--access-key <id>, -K <id>
The username of the user
--secret-key <key>, -S <key>
The password of the user
--url <url>, -U <url>
Set url as the web service url to use
--headers, -H
Display column headers
EOT
require 'econe/EC2QueryClient'
require 'CloudClient'
require 'getoptlong'
include CloudCLI
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--version', '-v',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
puts COMMANDS_HELP
return
when '--version'
puts CloudCLI.version_text
exit 0
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{cmd_name}: #{e.message}"
exit -1
end
addr = ec2_client.allocate_address
if CloudClient::is_error?(addr)
puts "#{cmd_name}: #{addr.message}"
exit -1
end
if headers
puts "publicIP"
puts "------------------------------------------------------------------------------"
end
puts addr['publicIP']
exit 0

View File

@ -0,0 +1,135 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
COMMANDS_HELP=<<-EOT
econe-associate-address
Associate a publicIP of the user with a given instance
Usage:
econe-associate-address [OPTIONS] PUBLIC-IP INSTANCE-ID
Options:
--help, -h
Show help
--access-key <id>, -K <id>
The username of the user
--secret-key <key>, -S <key>
The password of the user
--url <url>, -U <url>
Set url as the web service url to use
--headers, -H
Display column headers
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
INSTANCE-ID: Id of the instance to be associated with the ElasticIP
EOT
require 'econe/EC2QueryClient'
require 'CloudClient'
require 'getoptlong'
include CloudCLI
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--version', '-v',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
puts COMMANDS_HELP
return
when '--version'
puts CloudCLI.version_text
exit 0
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
public_ip = ARGV.shift
instance_id = ARGV.shift
if !public_ip
puts "#{cmd_name}: missing publicIP parameter"
exit -1
end
if !instance_id
puts "#{cmd_name}: missing instanceID parameter"
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{cmd_name}: #{e.message}"
exit -1
end
rc = ec2_client.associate_address(public_ip, instance_id)
if CloudClient::is_error?(rc)
puts "#{cmd_name}: #{rc.message}"
exit -1
end
exit 0

View File

@ -0,0 +1,133 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
COMMANDS_HELP=<<-EOT
econe-describe-images
List elastic IP addresses
Usage:
econe-describe-addresses [OPTIONS]
Options:
--help, -h
Show help
--access-key <id>, -K <id>
The username of the user
--secret-key <key>, -S <key>
The password of the user
--url <url>, -U <url>
Set url as the web service url to use
--headers, -H
Display column headers
EOT
require 'econe/EC2QueryClient'
require 'CloudClient'
require 'getoptlong'
include CloudCLI
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--version', '-v',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
puts COMMANDS_HELP
return
when '--version'
puts CloudCLI.version_text
exit 0
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{cmd_name}: #{e.message}"
exit -1
end
rc = ec2_client.describe_addresses
if CloudClient::is_error?(rc)
puts "#{cmd_name}: #{rc.message}"
exit -1
end
addresses = rc['addressesSet']['item']
fmt = "%-12s %s"
if headers
puts fmt % ["publicIP", "instanceId"]
puts "------------------------------------------------------------------------------"
end
if addresses
addresses.each { |addr|
puts fmt % [addr['publicIP'],addr['instanceID']]
}
end
exit 0

View File

@ -0,0 +1,128 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
COMMANDS_HELP=<<-EOT
econe-disasociate-address
Disasociate a publicIP of the user currently associated with an instance
Usage:
econe-disasociate-address [OPTIONS] PUBLIC-IP
Options:
--help, -h
Show help
--access-key <id>, -K <id>
The username of the user
--secret-key <key>, -S <key>
The password of the user
--url <url>, -U <url>
Set url as the web service url to use
--headers, -H
Display column headers
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
EOT
require 'econe/EC2QueryClient'
require 'CloudClient'
require 'getoptlong'
include CloudCLI
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--version', '-v',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
puts COMMANDS_HELP
return
when '--version'
puts CloudCLI.version_text
exit 0
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
public_ip = ARGV.shift
if !public_ip
puts "#{cmd_name}: missing publicIP parameter"
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{cmd_name}: #{e.message}"
exit -1
end
rc = ec2_client.disassociate_address(public_ip)
if CloudClient::is_error?(rc)
puts "#{cmd_name}: #{rc.message}"
exit -1
end
exit 0

View File

@ -0,0 +1,128 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
COMMANDS_HELP=<<-EOT
econe-release-address
Release a publicIP of the user
Usage:
econe-release-address [OPTIONS] PUBLIC-IP
Options:
--help, -h
Show help
--access-key <id>, -K <id>
The username of the user
--secret-key <key>, -S <key>
The password of the user
--url <url>, -U <url>
Set url as the web service url to use
--headers, -H
Display column headers
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
EOT
require 'econe/EC2QueryClient'
require 'CloudClient'
require 'getoptlong'
include CloudCLI
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--version', '-v',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
puts COMMANDS_HELP
return
when '--version'
puts CloudCLI.version_text
exit 0
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
public_ip = ARGV.shift
if !public_ip
puts "#{cmd_name}: missing publicIP parameter"
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{cmd_name}: #{e.message}"
exit -1
end
rc = ec2_client.release_address(public_ip)
if CloudClient::is_error?(rc)
puts "#{cmd_name}: #{rc.message}"
exit -1
end
exit 0

View File

@ -33,13 +33,13 @@
#############################################################
# Authentication driver for incomming requests
# ec2, default Acess key and Secret key scheme
# x509, for x509 certificates based authentication
# - ec2, default Acess key and Secret key scheme
# - x509, for x509 certificates based authentication
:auth: ec2
# Authentication driver to communicate with OpenNebula core
# cipher, for symmetric cipher encryption of tokens
# x509, for x509 certificate encryption of tokens
# - cipher, for symmetric cipher encryption of tokens
# - x509, for x509 certificate encryption of tokens
:core_auth: cipher
#############################################################
@ -57,9 +57,11 @@
# Cluster associated with the EC2 resources, by default no Cluster is defined
#:cluster_id:
# Datastore in which the Images uploaded through EC2 will be allocated, by default 1
# Datastore in which the Images uploaded through EC2 will be allocated, by
# default 1
#:datastore_id:
# VM types allowed and its template file (inside templates directory)
:instance_types:
:m1.small:
@ -70,13 +72,13 @@
#############################################################
# VirtualNetwork containing the elastic ips to be used with EC2. If no defined
# the Elastic IP functionality is disabled
# the Elastic IP functionality is disabled
#:elasticips_vnet_id:
# Script to associate a public IP with a private IP
# arguments: elastic_ip private_ip vnet_template(base64_encoded)
# - arguments: elastic_ip private_ip vnet_template(base64_encoded)
:associate_script: /usr/bin/false
# Script to disassociate a public IP
# arguments: elastic_ip
# - arguments: elastic_ip
:disassociate_script: /usr/bin/false

View File

@ -237,5 +237,74 @@ module EC2QueryClient
return response
end
######################################################################
######################################################################
def describe_addresses()
begin
response = @ec2_connection.describe_addresses
rescue Exception => e
error = CloudClient::Error.new(e.message)
return error
end
return response
end
######################################################################
######################################################################
def allocate_address()
begin
response = @ec2_connection.allocate_address
rescue Exception => e
error = CloudClient::Error.new(e.message)
return error
end
return response
end
######################################################################
######################################################################
def associate_address(public_ip, instance_id)
begin
response = @ec2_connection.associate_address(
:public_ip => public_ip,
:instance_id => instance_id)
rescue Exception => e
error = CloudClient::Error.new(e.message)
return error
end
return response
end
######################################################################
######################################################################
def disassociate_address(public_ip)
begin
response = @ec2_connection.disassociate_address(
:public_ip => public_ip)
rescue Exception => e
error = CloudClient::Error.new(e.message)
return error
end
return response
end
######################################################################
######################################################################
def release_address(public_ip)
begin
response = @ec2_connection.release_address(
:public_ip => public_ip)
rescue Exception => e
error = CloudClient::Error.new(e.message)
return error
end
return response
end
end
end

View File

@ -124,6 +124,12 @@ do_clean()
find share/examples -name '*.class' -delete
find test/ -name '*.class' -delete
echo "Cleaning javadoc files..."
rm -rf $DOC_DIR > /dev/null 2>&1
echo "Cleaning jar files..."
rm -rf $JAR_DIR > /dev/null 2>&1
}
if [ "$DO_CLEAN" = "yes" ] ; then

View File

@ -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.
@ -59,7 +59,7 @@ public abstract class PoolElement {
/**
* Creates a new PoolElement from the xml provided.
*
*
* @param client XML-RPC Client.
* @param xmlElement XML representation of the element.
*/
@ -102,7 +102,7 @@ public abstract class PoolElement {
/**
* Changes the permissions
*
*
* @param client XML-RPC Client.
* @param method XML-RPC method.
* @param id The id of the target object.
@ -130,11 +130,11 @@ public abstract class PoolElement {
/**
* Changes the permissions
*
*
* @param client XML-RPC Client.
* @param method XML-RPC method.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @param octet Permissions octet, e.g. 640
* @return If an error occurs the error message contains the reason.
*/
protected static OneResponse chmod(Client client, String method, int id,
@ -158,7 +158,7 @@ public abstract class PoolElement {
/**
* Changes the permissions
*
*
* @param client XML-RPC Client.
* @param method XML-RPC method.
* @param id The id of the target object.
@ -207,7 +207,7 @@ public abstract class PoolElement {
/**
* Returns the owner User's ID, or -1 if the element doesn't have one.
*
*
* @return the owner User's ID, or -1 if the element doesn't have one.
*/
public int uid()
@ -229,7 +229,7 @@ public abstract class PoolElement {
/**
* Returns the element group's ID, or -1 if the element doesn't have one.
*
*
* @return the element group's ID, or -1 if the element doesn't have one.
*/
public int gid()

View File

@ -64,6 +64,8 @@ public class Acl extends PoolElement{
tmpResources.put("USER" , 0x0000010000000000L);
tmpResources.put("TEMPLATE" , 0x0000020000000000L);
tmpResources.put("GROUP" , 0x0000040000000000L);
tmpResources.put("DATASTORE", 0x0000100000000000L);
tmpResources.put("CLUSTER" , 0x0000200000000000L);
RESOURCES = Collections.unmodifiableMap(tmpResources);

View File

@ -0,0 +1,321 @@
/*******************************************************************************
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.cluster;
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 cluster.
* It also offers static XML-RPC call wrappers.
*/
public class Cluster extends PoolElement{
private static final String METHOD_PREFIX = "cluster.";
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
private static final String DELETE = METHOD_PREFIX + "delete";
private static final String INFO = METHOD_PREFIX + "info";
private static final String ADDHOST = METHOD_PREFIX + "addhost";
private static final String DELHOST = METHOD_PREFIX + "delhost";
private static final String ADDDATASTORE = METHOD_PREFIX + "adddatastore";
private static final String DELDATASTORE = METHOD_PREFIX + "deldatastore";
private static final String ADDVNET = METHOD_PREFIX + "addvnet";
private static final String DELVNET = METHOD_PREFIX + "delvnet";
/**
* Creates a new Cluster representation.
*
* @param id The cluster id.
* @param client XML-RPC Client.
*/
public Cluster(int id, Client client)
{
super(id, client);
}
/**
* @see PoolElement
*/
protected Cluster(Node xmlElement, Client client)
{
super(xmlElement, client);
}
// =================================
// Static XML-RPC methods
// =================================
/**
* Allocates a new cluster in OpenNebula
*
* @param client XML-RPC Client.
* @param name Name for the new cluster.
* @return If successful the message contains the associated
* id generated for this cluster.
*/
public static OneResponse allocate(Client client, String name)
{
return client.call(ALLOCATE, name);
}
/**
* Retrieves the information of the given cluster.
*
* @param client XML-RPC Client.
* @param id The cluster 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 cluster from OpenNebula.
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @return A encapsulated response.
*/
public static OneResponse delete(Client client, int id)
{
return client.call(DELETE, id);
}
/**
* Adds a Host to this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param hid Host ID.
*
* @return A encapsulated response.
*/
public static OneResponse addHost(Client client, int id, int hid)
{
return client.call(ADDHOST, id, hid);
}
/**
* Deletes a Host from this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param hid Host ID.
*
* @return A encapsulated response.
*/
public static OneResponse delHost(Client client, int id, int hid)
{
return client.call(DELHOST, id, hid);
}
/**
* Adds a Datastore to this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param dsId Datastore ID.
*
* @return A encapsulated response.
*/
public static OneResponse addDatastore(Client client, int id, int dsId)
{
return client.call(ADDDATASTORE, id, dsId);
}
/**
* Deletes a Datastore from this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param dsId Datastore ID.
*
* @return A encapsulated response.
*/
public static OneResponse delDatastore(Client client, int id, int dsId)
{
return client.call(DELDATASTORE, id, dsId);
}
/**
* Adds a VNet to this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param vnetId VNet ID.
*
* @return A encapsulated response.
*/
public static OneResponse addVnet(Client client, int id, int vnetId)
{
return client.call(ADDVNET, id, vnetId);
}
/**
* Deletes a VNet from this Cluster
*
* @param client XML-RPC Client.
* @param id The cluster id.
* @param vnetId VNet ID.
*
* @return A encapsulated response.
*/
public static OneResponse delVnet(Client client, int id, int vnetId)
{
return client.call(DELVNET, id, vnetId);
}
// =================================
// Instanced object XML-RPC methods
// =================================
/**
* Loads the xml representation of the cluster.
* The info is also stored internally.
*
* @see Cluster#info(Client, int)
*/
public OneResponse info()
{
OneResponse response = info(client, id);
super.processInfo(response);
return response;
}
/**
* Deletes the cluster from OpenNebula.
*
* @see Cluster#delete(Client, int)
*/
public OneResponse delete()
{
return delete(client, id);
}
/**
* Adds a Host to this Cluster
*
* @param hid Host ID.
* @return A encapsulated response.
*/
public OneResponse addHost(int hid)
{
return addHost(client, id, hid);
}
/**
* Deletes a Host from this Cluster
*
* @param hid Host ID.
* @return A encapsulated response.
*/
public OneResponse delHost(int hid)
{
return delHost(client, id, hid);
}
/**
* Adds a Datastore to this Cluster
*
* @param dsId Datastore ID.
* @return A encapsulated response.
*/
public OneResponse addDatastore(int dsId)
{
return addDatastore(client, id, dsId);
}
/**
* Deletes a Datastore from this Cluster
*
* @param dsId Datastore ID.
* @return A encapsulated response.
*/
public OneResponse delDatastore(int dsId)
{
return delDatastore(client, id, dsId);
}
/**
* Adds a VNet to this Cluster
*
* @param vnetId VNet ID.
* @return A encapsulated response.
*/
public OneResponse addVnet(int vnetId)
{
return addVnet(client, id, vnetId);
}
/**
* Deletes a VNet from this Cluster
*
* @param vnetId VNet ID.
* @return A encapsulated response.
*/
public OneResponse delVnet(int vnetId)
{
return delVnet(client, id, vnetId);
}
// =================================
// Helpers
// =================================
/**
* Returns whether or not the host is part of this cluster
*
* @param id The host ID.
* @return Whether or not the host is part of this cluster.
*/
public boolean containsHost(int id)
{
return containsResource("HOSTS", id);
}
/**
* Returns whether or not the datastore is part of this cluster
*
* @param id The datastore ID.
* @return Whether or not the datastore is part of this cluster.
*/
public boolean containsDatastore(int id)
{
return containsResource("DATASTORES", id);
}
/**
* Returns whether or not the vnet is part of this cluster
*
* @param id The vnet ID.
* @return Whether or not the vnet is part of this cluster.
*/
public boolean containsVnet(int id)
{
return containsResource("VNETS", id);
}
private boolean containsResource(String resource, int id)
{
String res = xpath(resource+"/ID[.="+id+"]");
return res != null && res.equals(""+id);
}
}

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.cluster;
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 cluster pool.
* It also offers static XML-RPC call wrappers.
*/
public class ClusterPool extends Pool implements Iterable<Cluster>{
private static final String ELEMENT_NAME = "CLUSTER";
private static final String INFO_METHOD = "clusterpool.info";
/**
* Creates a new cluster pool
* @param client XML-RPC Client.
*/
public ClusterPool(Client client)
{
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
public PoolElement factory(Node node)
{
return new Cluster(node, client);
}
/**
* Retrieves all the clusters 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 cluster pool.
*
* @see ClusterPool#info(Client)
*/
public OneResponse info()
{
return super.info();
}
public Iterator<Cluster> iterator()
{
AbstractList<Cluster> ab = new AbstractList<Cluster>()
{
public int size()
{
return getLength();
}
public Cluster get(int index)
{
return (Cluster) item(index);
}
};
return ab.iterator();
}
/**
* Returns the Cluster with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Cluster to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Cluster getById(int id)
{
return (Cluster) super.getById(id);
}
}

View File

@ -0,0 +1,357 @@
/*******************************************************************************
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.datastore;
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 datastore.
* It also offers static XML-RPC call wrappers.
*/
public class Datastore extends PoolElement
{
private static final String METHOD_PREFIX = "datastore.";
private static final String INFO = METHOD_PREFIX + "info";
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
private static final String DELETE = METHOD_PREFIX + "delete";
private static final String UPDATE = METHOD_PREFIX + "update";
private static final String CHOWN = METHOD_PREFIX + "chown";
private static final String CHMOD = METHOD_PREFIX + "chmod";
/**
* Creates a new Datastore representation.
* @param id The datastore id.
* @param client XML-RPC Client.
*/
public Datastore(int id, Client client)
{
super(id, client);
}
/**
* @see PoolElement
*/
protected Datastore(Node xmlElement, Client client)
{
super(xmlElement, client);
}
// =================================
// 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.
* @return If successful the message contains the associated
* id generated for this Datastore.
*/
public static OneResponse allocate(Client client, String description)
{
return client.call(ALLOCATE, description);
}
/**
* Retrieves the information of the given Datastore.
*
* @param client XML-RPC Client.
* @param id The datastore id to retrieve the information from
* @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 datastore from OpenNebula.
*
* @param client XML-RPC Client.
* @param id The id of the target datastore we want to delete.
* @return A encapsulated response.
*/
public static OneResponse delete(Client client, int id)
{
return client.call(DELETE, id);
}
/**
* Replaces the datastore contents.
*
* @param client XML-RPC Client.
* @param id The id of the target datastore we want to modify.
* @param new_template New datastore contents.
* @return If successful the message contains the datastore id.
*/
public static OneResponse update(Client client, int id, String new_template)
{
return client.call(UPDATE, id, new_template);
}
/**
* Publishes or unpublishes a datastore.
*
* @param client XML-RPC Client.
* @param id The id of the target datastore we want to modify.
* @param publish True for publishing, false for unpublishing.
* @return If successful the message contains the datastore id.
*/
public static OneResponse publish(Client client, int id, boolean publish)
{
int group_u = publish ? 1 : 0;
return chmod(client, id, -1, -1, -1, group_u, -1, -1, -1, -1, -1);
}
/**
* 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.
* @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.
*/
public static OneResponse chown(Client client, int id, int uid, int gid)
{
return client.call(CHOWN, id, uid, gid);
}
/**
* 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
* @param owner_m 1 to allow, 0 deny, -1 do not change
* @param owner_a 1 to allow, 0 deny, -1 do not change
* @param group_u 1 to allow, 0 deny, -1 do not change
* @param group_m 1 to allow, 0 deny, -1 do not change
* @param group_a 1 to allow, 0 deny, -1 do not change
* @param other_u 1 to allow, 0 deny, -1 do not change
* @param other_m 1 to allow, 0 deny, -1 do not change
* @param other_a 1 to allow, 0 deny, -1 do not change
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id,
int owner_u, int owner_m, int owner_a,
int group_u, int group_m, int group_a,
int other_u, int other_m, int other_a)
{
return chmod(client, CHMOD, id,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octet, e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, String octet)
{
return chmod(client, CHMOD, id, octet);
}
/**
* Changes the permissions
*
* @param client XML-RPC Client.
* @param id The id of the target object.
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chmod(Client client, int id, int octet)
{
return chmod(client, CHMOD, id, octet);
}
// =================================
// Instanced object XML-RPC methods
// =================================
/**
* Retrieves the information of the Datastore.
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info()
{
OneResponse response = info(client, id);
super.processInfo(response);
return response;
}
/**
* Deletes the datastore from OpenNebula.
*
* @return A encapsulated response.
*/
public OneResponse delete()
{
return delete(client, id);
}
/**
* Replaces the datastore template.
*
* @param new_template New datastore template.
* @return If successful the message contains the datastore id.
*/
public OneResponse update(String new_template)
{
return update(client, id, new_template);
}
/**
* Publishes or unpublishes the datastore.
*
* @param publish True for publishing, false for unpublishing.
* @return If successful the message contains the datastore id.
*/
public OneResponse publish(boolean publish)
{
return publish(client, id, publish);
}
/**
* Publishes the datastore.
*
* @return If successful the message contains the datastore id.
*/
public OneResponse publish()
{
return publish(true);
}
/**
* Unpublishes the datastore.
*
* @return If successful the message contains the datastore id.
*/
public OneResponse unpublish()
{
return publish(false);
}
/**
* 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.
*/
public OneResponse chown(int uid, int gid)
{
return chown(client, id, uid, gid);
}
/**
* Changes the owner
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chown(int uid)
{
return chown(uid, -1);
}
/**
* Changes the group
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chgrp(int gid)
{
return chown(-1, gid);
}
/**
* 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
* @param group_u 1 to allow, 0 deny, -1 do not change
* @param group_m 1 to allow, 0 deny, -1 do not change
* @param group_a 1 to allow, 0 deny, -1 do not change
* @param other_u 1 to allow, 0 deny, -1 do not change
* @param other_m 1 to allow, 0 deny, -1 do not change
* @param other_a 1 to allow, 0 deny, -1 do not change
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int owner_u, int owner_m, int owner_a,
int group_u, int group_m, int group_a,
int other_u, int other_m, int other_a)
{
return chmod(client, id,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(String octet)
{
return chmod(client, id, octet);
}
/**
* Changes the permissions
*
* @param octet Permissions octed , e.g. 640
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chmod(int octet)
{
return chmod(client, id, octet);
}
// =================================
// Helpers
// =================================
/**
* Returns whether or not the image is part of this datastore
*
* @param id The image ID.
* @return Whether or not the image is part of this datastore.
*/
public boolean contains(int id)
{
String res = xpath("IMAGES/ID[.="+id+"]");
return res != null && res.equals(""+id);
}
}

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.opennebula.client.datastore;
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 datastore pool.
* It also offers static XML-RPC call wrappers.
*/
public class DatastorePool extends Pool implements Iterable<Datastore>{
private static final String ELEMENT_NAME = "DATASTORE";
private static final String INFO_METHOD = "datastorepool.info";
/**
* Creates a new datastore pool
* @param client XML-RPC Client.
*/
public DatastorePool(Client client)
{
super(ELEMENT_NAME, client, INFO_METHOD);
}
@Override
public PoolElement factory(Node node)
{
return new Datastore(node, client);
}
/**
* Retrieves all the datastores 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 datastore pool.
*
* @see DatastorePool#info(Client)
*/
public OneResponse info()
{
return super.info();
}
public Iterator<Datastore> iterator()
{
AbstractList<Datastore> ab = new AbstractList<Datastore>()
{
public int size()
{
return getLength();
}
public Datastore get(int index)
{
return (Datastore) item(index);
}
};
return ab.iterator();
}
/**
* Returns the Datastore with the given Id from the pool. If it is not found,
* then returns null.
*
* @param id of the Datastore to retrieve
* @return The Image with the given Id, or null if it was not found.
*/
public Datastore getById(int id)
{
return (Datastore) super.getById(id);
}
}

View File

@ -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.
@ -33,15 +33,15 @@ public class Host extends PoolElement{
private static final String DELETE = METHOD_PREFIX + "delete";
private static final String ENABLE = METHOD_PREFIX + "enable";
private static final String UPDATE = METHOD_PREFIX + "update";
private static final String[] HOST_STATES =
private static final String[] HOST_STATES =
{"INIT", "MONITORING", "MONITORED", "ERROR", "DISABLED"};
/**
* Creates a new Host representation.
*
* @param id The host id (hid) of the machine.
*
* @param id The host id (hid) of the machine.
* @param client XML-RPC Client.
*/
public Host(int id, Client client)
@ -64,17 +64,20 @@ public class Host extends PoolElement{
/**
* Allocates a new host in OpenNebula
*
*
* @param client XML-RPC Client.
* @param hostname Hostname of the machine we want to add
* @param hostname Hostname of the machine we want to add
* @param im The name of the information manager (im_mad_name),
* this values are taken from the oned.conf with the tag name IM_MAD (name)
* this values are taken from the oned.conf with the tag name IM_MAD (name)
* @param vmm The name of the virtual machine manager mad name
* (vmm_mad_name), this values are taken from the oned.conf with the
* tag name VM_MAD (name)
* @param vnm The name of the virtual network manager mad name
* (vnm_mad_name), this values are taken from the oned.conf with the
* tag name VN_MAD (name)
* @param clusterId The cluster ID. If it is -1, this host won't be
* added to any cluster.
*
* @return If successful the message contains the associated
* id generated for this host
*/
@ -82,16 +85,44 @@ public class Host extends PoolElement{
String hostname,
String im,
String vmm,
String vnm)
String vnm,
int clusterId)
{
return client.call(ALLOCATE, hostname, im, vmm, vnm);
return client.call(ALLOCATE, hostname, im, vmm, vnm, clusterId);
}
/**
* Allocates a new host in OpenNebula
*
* @param client XML-RPC Client.
* @param hostname Hostname of the machine we want to add
* @param im The name of the information manager (im_mad_name),
* this values are taken from the oned.conf with the tag name IM_MAD (name)
* @param vmm The name of the virtual machine manager mad name
* (vmm_mad_name), this values are taken from the oned.conf with the
* tag name VM_MAD (name)
* @param vnm The name of the virtual network manager mad name
* (vnm_mad_name), this values are taken from the oned.conf with the
* tag name VN_MAD (name)
*
* @return If successful the message contains the associated
* id generated for this host
*/
public static OneResponse allocate(
Client client,
String hostname,
String im,
String vmm,
String vnm)
{
return allocate(client, hostname, im, vmm, vnm, -1);
}
/**
* Retrieves the information of the given host.
*
*
* @param client XML-RPC Client.
* @param id The host id (hid) of the target machine.
* @param id The host id (hid) of the target machine.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
@ -102,7 +133,7 @@ public class Host extends PoolElement{
/**
* Deletes a host from OpenNebula.
*
*
* @param client XML-RPC Client.
* @param id The host id (hid) of the target machine.
* @return A encapsulated response.
@ -114,7 +145,7 @@ public class Host extends PoolElement{
/**
* Enables or disables a given host.
*
*
* @param client XML-RPC Client.
* @param id The host id (hid) of the target machine.
* @param enable If set true OpenNebula will enable the
@ -128,7 +159,7 @@ public class Host extends PoolElement{
/**
* Replaces the template contents.
*
*
* @param client XML-RPC Client.
* @param id The image id of the target host we want to modify.
* @param new_template New template contents
@ -146,7 +177,7 @@ public class Host extends PoolElement{
/**
* Loads the xml representation of the host.
* The info is also stored internally.
*
*
* @see Host#info(Client, int)
*/
public OneResponse info()
@ -158,7 +189,7 @@ public class Host extends PoolElement{
/**
* Deletes the host from OpenNebula.
*
*
* @see Host#delete(Client, int)
*/
public OneResponse delete()
@ -168,7 +199,7 @@ public class Host extends PoolElement{
/**
* Enables or disables the host.
*
*
* @see Host#enable(Client, int, boolean)
*/
public OneResponse enable(boolean enable)
@ -178,7 +209,7 @@ public class Host extends PoolElement{
/**
* Enables the host.
*
*
* @return A encapsulated response.
*/
public OneResponse enable()
@ -188,7 +219,7 @@ public class Host extends PoolElement{
/**
* Disables the host
*
*
* @return A encapsulated response.
*/
public OneResponse disable()
@ -198,7 +229,7 @@ public class Host extends PoolElement{
/**
* Replaces the template contents.
*
*
* @param new_template New template contents
* @return If successful the message contains the host id.
*/
@ -215,7 +246,7 @@ public class Host extends PoolElement{
* Returns the state of the Host.
* <br/>
* The method {@link Host#info()} must be called before.
*
*
* @return The state of the Host.
*/
public String stateStr()
@ -228,7 +259,7 @@ public class Host extends PoolElement{
* Returns the short length string state of the Host.
* <br/>
* The method {@link Host#info()} must be called before.
*
*
* @return The short length string state of the Host.
*/
public String shortStateStr()
@ -246,7 +277,7 @@ public class Host extends PoolElement{
/**
* Returns true if the host is enabled.
*
*
* @return True if the host is enabled.
*/
public boolean isEnabled()

View File

@ -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.
@ -71,6 +71,24 @@ public class Image extends PoolElement
// Static XML-RPC methods
// =================================
/**
* Allocates a new Image in OpenNebula.
*
* @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
* won't be added to any cluster.
*
* @return If successful the message contains the associated
* id generated for this Image.
*/
public static OneResponse allocate(
Client client,
String description,
int clusterId)
{
return client.call(ALLOCATE, description, clusterId);
}
/**
* Allocates a new Image in OpenNebula.
@ -82,7 +100,7 @@ public class Image extends PoolElement
*/
public static OneResponse allocate(Client client, String description)
{
return client.call(ALLOCATE, description);
return allocate(client, description, -1);
}
/**
@ -100,7 +118,7 @@ public class Image extends PoolElement
/**
* Deletes an image from OpenNebula.
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to delete.
* @return A encapsulated response.
@ -112,7 +130,7 @@ public class Image extends PoolElement
/**
* Replaces the template contents.
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param new_template New template contents
@ -125,7 +143,7 @@ public class Image extends PoolElement
/**
* Enables or disables an image.
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param enable True for enabling, false for disabling.
@ -138,7 +156,7 @@ public class Image extends PoolElement
/**
* Publishes or unpublishes an image.
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param publish True for publishing, false for unpublishing.
@ -153,7 +171,7 @@ public class Image extends PoolElement
/**
* Changes the owner/group
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param uid The new owner user ID. Set it to -1 to leave the current one.
@ -167,7 +185,7 @@ public class Image extends PoolElement
/**
* Changes the Image permissions
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param owner_u 1 to allow, 0 deny, -1 do not change
@ -194,7 +212,7 @@ public class Image 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
@ -207,7 +225,7 @@ public class Image 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
@ -220,7 +238,7 @@ public class Image extends PoolElement
/**
* Changes the Image type
*
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param type The new Image type
@ -250,7 +268,7 @@ public class Image extends PoolElement
/**
* Deletes the image from OpenNebula.
*
*
* @return A encapsulated response.
*/
public OneResponse delete()
@ -260,7 +278,7 @@ public class Image extends PoolElement
/**
* Replaces the template contents.
*
*
* @param new_template New template contents
* @return If successful the message contains the image id.
*/
@ -271,7 +289,7 @@ public class Image extends PoolElement
/**
* Enables or disables the image.
*
*
* @param enable True for enabling, false for disabling.
* @return If successful the message contains the image id.
*/
@ -282,7 +300,7 @@ public class Image extends PoolElement
/**
* Enables the image.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse enable()
@ -292,7 +310,7 @@ public class Image extends PoolElement
/**
* Disables the image.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse disable()
@ -302,7 +320,7 @@ public class Image extends PoolElement
/**
* Publishes or unpublishes the image.
*
*
* @param publish True for publishing, false for unpublishing.
* @return If successful the message contains the image id.
*/
@ -313,7 +331,7 @@ public class Image extends PoolElement
/**
* Publishes the image.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse publish()
@ -323,7 +341,7 @@ public class Image extends PoolElement
/**
* Unpublishes the image.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse unpublish()
@ -333,7 +351,7 @@ public class Image 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.
@ -345,7 +363,7 @@ public class Image extends PoolElement
/**
* Changes the owner
*
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
@ -356,7 +374,7 @@ public class Image extends PoolElement
/**
* Changes the group
*
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
@ -367,7 +385,7 @@ public class Image extends PoolElement
/**
* Changes the Image 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
@ -413,7 +431,7 @@ public class Image extends PoolElement
/**
* Changes the Image type
*
*
* @param type The new Image type
* @return If an error occurs the error message contains the reason.
*/
@ -430,7 +448,7 @@ public class Image extends PoolElement
* Returns the state of the Image.
* <br/>
* The method {@link Image#info()} must be called before.
*
*
* @return The state of the Image.
*/
public String stateString()
@ -443,7 +461,7 @@ public class Image extends PoolElement
* Returns the short length string state of the Image.
* <br/>
* The method {@link Image#info()} must be called before.
*
*
* @return The short length string state of the Image.
*/
public String shortStateStr()
@ -454,7 +472,7 @@ public class Image extends PoolElement
/**
* Returns the type of the Image.
*
*
* @return The type of the Image.
*/
public int type()
@ -465,7 +483,7 @@ public class Image extends PoolElement
/**
* Returns the type of the Image as a String.
*
*
* @return The type of the Image as a String.
*/
public String typeStr()
@ -476,7 +494,7 @@ public class Image extends PoolElement
/**
* Returns the type of the Image as a short String.
*
*
* @return The type of the Image as a short String.
*/
public String shortTypeStr()
@ -487,7 +505,7 @@ public class Image extends PoolElement
/**
* Returns true if the image is enabled.
*
*
* @return True if the image is enabled.
*/
public boolean isEnabled()

View File

@ -19,7 +19,6 @@ 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;
/**
@ -152,7 +151,7 @@ public class VirtualMachine extends PoolElement{
/**
* Changes the owner/group
*
*
* @param client XML-RPC Client.
* @param id The virtual machine id (vid) of the target instance.
* @param uid The new owner user ID. Set it to -1 to leave the current one.
@ -166,7 +165,7 @@ public class VirtualMachine extends PoolElement{
/**
* Changes the VM permissions
*
*
* @param client XML-RPC Client.
* @param id The VM id of the target VM.
* @param owner_u 1 to allow, 0 deny, -1 do not change
@ -193,7 +192,7 @@ public class VirtualMachine 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
@ -206,7 +205,7 @@ public class VirtualMachine 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
@ -317,7 +316,7 @@ public class VirtualMachine 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.
@ -329,7 +328,7 @@ public class VirtualMachine extends PoolElement{
/**
* Changes the owner
*
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
@ -340,7 +339,7 @@ public class VirtualMachine extends PoolElement{
/**
* Changes the group
*
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
@ -352,7 +351,7 @@ public class VirtualMachine extends PoolElement{
/**
* Changes the VM 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

View File

@ -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.
@ -41,7 +41,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Creates a new virtual network representation.
*
*
* @param id The virtual network id (nid) .
* @param client XML-RPC Client.
*/
@ -64,24 +64,47 @@ public class VirtualNetwork extends PoolElement{
/**
* Allocates a new virtual network in OpenNebula.
*
*
* @param client XML-RPC Client.
* @param description A string containing the template
* of the virtual network.
* of the virtual network.
* @param clusterId The cluster ID. If it is -1, this virtual network
* won't be added to any cluster.
*
* @return If successful the message contains the associated
* id generated for this virtual network.
*/
public static OneResponse allocate(Client client, String description)
public static OneResponse allocate(
Client client,
String description,
int clusterId)
{
return client.call(ALLOCATE, description);
return client.call(ALLOCATE, description, clusterId);
}
/**
* Allocates a new virtual network in OpenNebula.
*
* @param client XML-RPC Client.
* @param description A string containing the template
* of the virtual network.
*
* @return If successful the message contains the associated
* id generated for this virtual network.
*/
public static OneResponse allocate(
Client client,
String description)
{
return allocate(client, description, -1);
}
/**
* Retrieves the information of the given virtual network
*
*
* @param client XML-RPC Client.
* @param id the virtual network id (nid) for the network to
* retrieve the information from.
* retrieve the information from.
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
@ -92,7 +115,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Deletes a network from OpenNebula.
*
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @return A encapsulated response.
@ -104,7 +127,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Publishes or unpublishes a virtual network.
*
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @param publish True for publishing, false for unpublishing.
@ -171,7 +194,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Changes the owner/group
*
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @param uid The new owner user ID. Set it to -1 to leave the current one.
@ -185,7 +208,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Changes the VirtualNetwork permissions
*
*
* @param client XML-RPC Client.
* @param id The virtual network id (nid) of the target network.
* @param owner_u 1 to allow, 0 deny, -1 do not change
@ -212,7 +235,7 @@ public class VirtualNetwork 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
@ -225,7 +248,7 @@ public class VirtualNetwork 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
@ -256,7 +279,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Loads the xml representation of the virtual network.
* The info is also stored internally.
*
*
* @see VirtualNetwork#info(Client, int)
*/
public OneResponse info()
@ -268,7 +291,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Deletes the network from OpenNebula.
*
*
* @return A encapsulated response.
*/
public OneResponse delete()
@ -278,7 +301,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Publishes or unpublishes the virtual network.
*
*
* @param publish True for publishing, false for unpublishing.
* @return If successful the message contains the image id.
*/
@ -289,7 +312,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Publishes the virtual network.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse publish()
@ -299,7 +322,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Unpublishes the virtual network.
*
*
* @return If successful the message contains the image id.
*/
public OneResponse unpublish()
@ -379,7 +402,7 @@ public class VirtualNetwork 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.
@ -391,7 +414,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Changes the owner
*
*
* @param uid The new owner user ID.
* @return If an error occurs the error message contains the reason.
*/
@ -402,7 +425,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Changes the group
*
*
* @param gid The new group ID.
* @return If an error occurs the error message contains the reason.
*/
@ -413,7 +436,7 @@ public class VirtualNetwork extends PoolElement{
/**
* Changes the VirtualNetwork 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

View File

@ -63,7 +63,7 @@ public class HostTest
@Before
public void setUp() throws Exception
{
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "vnm_dummy");
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "dummy");
int hid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
host = new Host(hid, client);
@ -83,7 +83,7 @@ public class HostTest
{
String name = "allocate_test";
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "vmm_dummy");
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "dummy");
assertTrue( !res.isError() );
// assertTrue( res.getMessage().equals("0") );

View File

@ -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.host.Host;
import org.opennebula.client.vm.VirtualMachine;
import org.opennebula.client.vm.VirtualMachinePool;
@ -80,12 +81,15 @@ public class VirtualMachineTest
res = Host.allocate(client, "host_A",
"im_dummy", "vmm_dummy", "vmm_dummy", "tm_dummy");
"im_dummy", "vmm_dummy", "dummy");
hid_A = Integer.parseInt( res.getMessage() );
res = Host.allocate(client, "host_B",
"im_dummy", "vmm_dummy", "vmm_dummy", "tm_dummy");
"im_dummy", "vmm_dummy", "dummy");
hid_B = Integer.parseInt( res.getMessage() );
Datastore systemDs = new Datastore(0, client);
systemDs.update("TM_MAD = dummy");
}
/**
@ -295,7 +299,8 @@ public class VirtualMachineTest
assertTrue( vm.xpath("TEMPLATE/CONTEXT/DNS").equals("192.169.1.4") );
}
@Test
// TODO
// @Test
public void savedisk()
{
String template = "NAME = savedisk_vm\n"+

View File

@ -40,7 +40,6 @@ public class VirtualNetworkTest
private static String template =
"NAME = " + name + "\n"+
"TYPE = RANGED\n" +
"PUBLIC = NO\n" +
"BRIDGE = vbr0\n" +
"NETWORK_SIZE = C\n" +
"NETWORK_ADDRESS = 192.168.0.0\n";
@ -147,30 +146,7 @@ public class VirtualNetworkTest
res = vnet.info();
assertTrue( res.isError() );
}
// TODO
/*
@Test
public void publish()
{
res = vnet.info();
assertTrue( !res.isError() );
assertTrue( !vnet.isPublic() );
// Publish it
res = vnet.publish();
assertTrue( !res.isError() );
res = vnet.info();
assertTrue( vnet.isPublic() );
// Unpublish it
res = vnet.unpublish();
assertTrue( !res.isError() );
res = vnet.info();
assertTrue( !vnet.isPublic() );
}
*/
@Test
public void addLeases()
{
@ -273,4 +249,5 @@ public class VirtualNetworkTest
assertTrue( vnet.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
assertTrue( vnet.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
}
}

View File

@ -6,7 +6,7 @@
# Daemon configuration attributes
#-------------------------------------------------------------------------------
# MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions.
# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL cannot have smaller values
# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values
# than MANAGER_TIMER.
#
# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization.
@ -16,11 +16,6 @@
# (use 0 to disable VM monitoring).
# VM_PER_INTERVAL: Number of VMs monitored in each interval.
#
# VM_DIR: Remote path to store the VM images, it should be shared between all
# the cluster nodes to perform live migrations. This variable is the default
# for all the hosts in the cluster. VM_DIR IS ONLY FOR THE NODES AND *NOT* THE
# FRONT-END
#
# SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management
# scripts.
#
@ -49,7 +44,6 @@ HOST_MONITORING_INTERVAL = 600
VM_POLLING_INTERVAL = 600
#VM_PER_INTERVAL = 5
#VM_DIR=/srv/cloud/one/var
SCRIPTS_REMOTE_DIR=/var/tmp/one
@ -84,8 +78,13 @@ NETWORK_SIZE = 254
MAC_PREFIX = "02:00"
#*******************************************************************************
# Image Repository Configuration
# DataStore Configuration
#*******************************************************************************
# DATASTORE_LOCATION: Path for Datastores in the hosts. It IS the same for all
# the hosts in the cluster. DATASTORE_LOCATION IS ONLY FOR THE HOSTS AND *NOT*
# THE FRONT-END. It defaults to /var/lib/one/datastores (or
# $ONE_LOCATION/var/datastores in self-contained mode)
#
# DEFAULT_IMAGE_TYPE: This can take values
# OS Image file holding an operating system
# CDROM Image file holding a CDROM
@ -97,6 +96,9 @@ MAC_PREFIX = "02:00"
# xvd XEN Virtual Disk
# vd KVM virtual disk
#*******************************************************************************
#DATASTORE_LOCATION = /var/lib/one/datastores
DEFAULT_IMAGE_TYPE = "OS"
DEFAULT_DEVICE_PREFIX = "hd"
@ -199,7 +201,7 @@ IM_MAD = [ name="im_dummy", executable="one_im_dummy"]
# KVM Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
# -l <actions[=command_name]> actions executed locally, command can be
# -l <actions[=command_name]> actions executed locally, command can be
# overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate,poll=poll_ganglia,save"
@ -216,7 +218,7 @@ VM_MAD = [
# XEN Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time
# -l <actions[=command_name]> actions executed locally, command can be
# -l <actions[=command_name]> actions executed locally, command can be
# overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate,poll=poll_ganglia,save"
@ -271,75 +273,33 @@ VM_MAD = [ name="vmm_dummy", executable="one_vmm_dummy", type="xml" ]
# executable: path of the transfer driver executable, can be an
# absolute path or relative to $ONE_LOCATION/lib/mads (or
# /usr/lib/one/mads/ if OpenNebula was installed in /)
#
# arguments : for the driver executable, usually a commands configuration file
# , can be an absolute path or relative to $ONE_LOCATION/etc (or
# /etc/one/ if OpenNebula was installed in /)
# arguments :
# -t: number of threads, i.e. number of transfers made at the same time
# -d: list of transfer drivers separated by commas, if not defined all the
# drivers available will be enabled
#*******************************************************************************
#-------------------------------------------------------------------------------
# SHARED Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
TM_MAD = [
name = "tm_shared",
executable = "one_tm",
arguments = "tm_shared/tm_shared.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# SSH Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_ssh",
# executable = "one_tm",
# arguments = "tm_ssh/tm_ssh.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
TM_MAD = [
name = "tm_dummy",
executable = "one_tm",
arguments = "tm_dummy/tm_dummy.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# LVM Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_lvm",
# executable = "one_tm",
# arguments = "tm_lvm/tm_lvm.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# VMware DataStore Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_vmware",
# executable = "one_tm",
# arguments = "tm_vmware/tm_vmware.conf" ]
#-------------------------------------------------------------------------------
arguments = "-t 15 -d dummy,lvm,shared,qcow2,ssh,vmware,iscsi" ]
#*******************************************************************************
# Image Manager Driver Configuration
# Datastore Driver Configuration
#*******************************************************************************
# Drivers to manage the image repository, specialized for the storage backend
# Drivers to manage the datastores, specialized for the storage backend
# executable: path of the transfer driver executable, can be an
# absolute path or relative to $ONE_LOCATION/lib/mads (or
# /usr/lib/one/mads/ if OpenNebula was installed in /)
#
# arguments : for the driver executable
# -t number of threads, i.e. number of repo operations at the same time
# -d datastore mads separated by commas
#*******************************************************************************
#-------------------------------------------------------------------------------
# FS based Image Manager Driver Configuration
# -t number of threads, i.e. number of repo operations at the same time
#-------------------------------------------------------------------------------
IMAGE_MAD = [
executable = "one_image",
arguments = "fs -t 15" ]
#-------------------------------------------------------------------------------
DATASTORE_MAD = [
executable = "one_datastore",
arguments = "-t 15 -d fs,vmware,iscsi,dummy"
]
#*******************************************************************************
# Hook Manager Configuration
@ -376,7 +336,6 @@ IMAGE_MAD = [
# allocated
# - NO, The hook is executed in the OpenNebula server (default)
#
#
# Host Hooks (HOST_HOOK) defined by:
# name : for the hook, useful to track the hook (OPTIONAL)
# on : when the hook should be executed,
@ -395,10 +354,8 @@ IMAGE_MAD = [
# - YES, The hook is executed in the host
# - NO, The hook is executed in the OpenNebula server (default)
#-------------------------------------------------------------------------------
HM_MAD = [
executable = "one_hm" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
@ -455,8 +412,12 @@ HM_MAD = [
# --authz: authorization module
#
# 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
# valid. During this time, the driver is not used. Use 0 to disable session
# caching
#
# ENABLE_OTHER_PERMISSIONS: Whether or not to enable the permissions for
# 'other'. Users in the oneadmin group will still be able to change
# these permissions. Values: YES or NO
#*******************************************************************************
AUTH_MAD = [
@ -467,3 +428,19 @@ AUTH_MAD = [
SESSION_EXPIRATION_TIME = 900
#ENABLE_OTHER_PERMISSIONS = "YES"
#*******************************************************************************
# Restricted Attributes Configuration
#*******************************************************************************
# The following attributes are restricted to users outside the oneadmin group
#*******************************************************************************
VM_RESTRICTED_ATTR = "CONTEXT/FILES"
VM_RESTRICTED_ATTR = "DISK/SOURCE"
VM_RESTRICTED_ATTR = "NIC/MAC"
VM_RESTRICTED_ATTR = "NIC/VLAN_ID"
VM_RESTRICTED_ATTR = "RANK"
IMAGE_RESTRICTED_ATTR = "SOURCE"

View File

@ -129,7 +129,7 @@ module OpenNebula
#This doesn't work in ruby 1.8.5
#return self["DATASTORE/ID[.=#{uid}]"] != nil
id_array = retrieve_elements('DATASTORE/ID')
id_array = retrieve_elements('IMAGES/ID')
return id_array != nil && id_array.include?(uid.to_s)
end

View File

@ -225,6 +225,8 @@ module OpenNebula
end
end
# Returns wheter there are elements for a given XPath
# xpath_str:: _String_ XPath expression to locate the element
def has_elements?(xpath_str)
if NOKOGIRI
element = @xml.xpath(xpath_str.to_s.upcase)
@ -235,10 +237,13 @@ module OpenNebula
end
end
# Returns the <TEMPLATE> element in text form
# indent:: _Boolean_ indents the resulting string, default true
def template_str(indent=true)
template_like_str('TEMPLATE', indent)
end
# Returns the <TEMPLATE> element in XML form
def template_xml
if NOKOGIRI
@xml.xpath('TEMPLATE').to_s
@ -247,47 +252,54 @@ module OpenNebula
end
end
# Returns elements in text form
# root_element:: _String_ base element
# indent:: _Boolean_ indents the resulting string, default true
# xpath_exp:: _String_ filter elements with a XPath
def template_like_str(root_element, indent=true, xpath_exp=nil)
if NOKOGIRI
xml_template=@xml.xpath(root_element).to_s
rexml=REXML::Document.new(xml_template).root
xml_template = @xml.xpath(root_element).to_s
rexml = REXML::Document.new(xml_template).root
else
rexml=@xml.elements[root_element]
rexml = @xml.elements[root_element]
end
if indent
ind_enter="\n"
ind_tab=' '
ind_enter = "\n"
ind_tab = ' '
else
ind_enter=''
ind_tab=' '
ind_enter = ''
ind_tab = ' '
end
str=rexml.elements.collect(xpath_exp) {|n|
if n.class==REXML::Element
str_line=""
if n.has_elements?
str_line << n.name << "=[" << ind_enter
str = rexml.elements.collect(xpath_exp) {|n|
next if n.class != REXML::Element
str_line << n.collect {|n2|
if n2 && n2.class==REXML::Element
str = ""
str << ind_tab << n2.name << '='
str << attr_to_str(n2.text) if n2.text
str
end
}.compact.join(','+ind_enter)
str_line<<" ]"
else
str_line << n.name << '=' << attr_to_str(n.text.to_s)
end
str_line
str_line = ""
if n.has_elements?
str_line << "#{n.name}=[#{ind_enter}" << n.collect { |n2|
next if n2.class != REXML::Element or !n2.has_text?
str = "#{ind_tab}#{n2.name}=#{attr_to_str(n2.text)}"
}.compact.join(",#{ind_enter}") << " ]"
else
next if !n.has_text?
str_line << "#{n.name}=#{attr_to_str(n.text)}"
end
str_line
}.compact.join("\n")
str
return str
end
#
#
#
def to_xml(pretty=false)
if NOKOGIRI && pretty
str = @xml.to_xml
@ -305,6 +317,9 @@ module OpenNebula
return str
end
#
#
#
def to_hash(hash={}, element=nil)
element ||= @xml.document.root
@ -344,13 +359,14 @@ module OpenNebula
end
private
#
#
#
def attr_to_str(attr)
attr.gsub!('"',"\\\"")
if attr.match(/[=,' ']/)
return '"' + attr + '"'
end
attr = "\"#{attr}\""
return attr
end
end

View File

@ -234,6 +234,11 @@ module Migrator
# Update SOURCE
doc.root.each_element("SOURCE") { |e|
previous_source = e.text
if previous_source.nil?
next
end
hash = previous_source.split('/')[-1]
if ( hash.length == 32 && hash =~ /^[0-9A-F]+$/i )
@ -275,7 +280,7 @@ module Migrator
" <GROUP_U>1</GROUP_U>" <<
" <GROUP_M>0</GROUP_M>" <<
" <GROUP_A>0</GROUP_A>" <<
" <OTHER_U>0</OTHER_U>" <<
" <OTHER_U>1</OTHER_U>" <<
" <OTHER_M>0</OTHER_M>" <<
" <OTHER_A>0</OTHER_A>" <<
" </PERMISSIONS>" <<
@ -299,7 +304,7 @@ module Migrator
:gid => 0,
:owner_u => 1,
:group_u => 1,
:other_u => 0)
:other_u => 1)
return true
end

View File

@ -102,7 +102,7 @@ if is_iscsi "$DST_HOST"; then
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
sleep 1
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
ln -s "\$DISK_BY_PATH" "$DST_PATH"
ln -sf "\$DISK_BY_PATH" "$DST_PATH"
EOF
)

View File

@ -198,7 +198,6 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
int rc;
string name;
SingleAttribute * attr;
string value;
ostringstream oss;
@ -209,9 +208,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
oss << oid;
value = oss.str();
attr = new SingleAttribute("VMID",value);
obj_template->set(attr);
replace_template_attribute("VMID", value);
get_template_attribute("NAME",name);
@ -1087,8 +1084,11 @@ void VirtualMachine::release_network_leases()
continue;
}
vn->release_lease(ip);
vnpool->update(vn);
if (vn->is_owner(ip,oid))
{
vn->release_lease(ip);
vnpool->update(vn);
}
vn->unlock();
}

View File

@ -29,9 +29,26 @@ $: << File.dirname(__FILE__)
require 'vmware_driver'
#------------------------------------------------------------------------------
# Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
# Set to ~10min
#------------------------------------------------------------------------------
POLL_INTERVAL=2
TIMEOUT=300
deploy_id = ARGV[0]
host = ARGV[1]
vmware_drv = VMwareDriver.new(host)
vmware_drv.shutdown(deploy_id)
count=0
while (vmware_drv.poll(deploy_id).match(/STATE=(.*)/)[1] != "d") do
sleep POLL_INTERVAL
if count > TIMEOUT then
OpenNebula.log_debug("Timeout reached and VM #{deploy_id} is still alive.")
exit -1
end
count+=POLL_INTERVAL
end

View File

@ -415,6 +415,28 @@ bool Leases::check(unsigned int ip)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Leases::is_owner(const string& ip, int vid)
{
unsigned int _ip;
map<unsigned int,Lease *>::iterator it;
Leases::Lease::ip_to_number(ip,_ip);
it = leases.find(_ip);
if (it!=leases.end())
{
return (it->second->vid == vid);
}
else
{
return false;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Leases::hold_leases(vector<const Attribute*>& vector_leases,
string& error_msg)
{