mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
Merge remote-tracking branch 'upstream/bug-847' into bug-847
This commit is contained in:
commit
e3085cb6fe
23 files changed
+392
-223
No files matched your search
+5
-25
@@ -183,32 +183,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enum type
|
||||
* @return 0 on success, -1 otherwise
|
||||
* Sets the Image type.
|
||||
*
|
||||
* @param _type the new type. It will be transformed to upper case
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int set_type(const string& _type)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( _type == "OS" )
|
||||
{
|
||||
type = OS;
|
||||
}
|
||||
else if ( _type == "CDROM" )
|
||||
{
|
||||
type = CDROM;
|
||||
}
|
||||
else if ( _type == "DATABLOCK" )
|
||||
{
|
||||
type = DATABLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
int set_type(string& _type);
|
||||
|
||||
/**
|
||||
* Publish or unpublish an image
|
||||
|
||||
@@ -30,8 +30,9 @@ class RequestManagerImage: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerImage(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sib",help)
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
@@ -55,7 +56,8 @@ class ImageEnable : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImageEnable():
|
||||
RequestManagerImage("ImageEnable", "Enables or disables an image"){};
|
||||
RequestManagerImage("ImageEnable", "Enables or disables an image",
|
||||
"A:sib"){};
|
||||
|
||||
~ImageEnable(){};
|
||||
|
||||
@@ -71,7 +73,8 @@ class ImagePersistent : public RequestManagerImage
|
||||
public:
|
||||
ImagePersistent():
|
||||
RequestManagerImage("ImagePersistent",
|
||||
"Makes an image persistent or non-persistent"){};
|
||||
"Makes an image persistent or non-persistent",
|
||||
"A:sib"){};
|
||||
|
||||
~ImagePersistent(){};
|
||||
|
||||
@@ -79,6 +82,23 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageChangeType : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImageChangeType():
|
||||
RequestManagerImage("ImageChangeType",
|
||||
"Changes the type of an image",
|
||||
"A:sis"){};
|
||||
|
||||
~ImageChangeType(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -21,7 +21,7 @@ require 'fileutils'
|
||||
require 'x509_auth'
|
||||
|
||||
# Server authentication class. This authmethod can be used by opennebula services
|
||||
# to let access authenticated users by other means. It is based on x509 server
|
||||
# to let access authenticated users by other means. It is based on x509 server
|
||||
# certificates
|
||||
class ServerX509Auth < X509Auth
|
||||
###########################################################################
|
||||
@@ -39,7 +39,7 @@ class ServerX509Auth < X509Auth
|
||||
|
||||
def initialize()
|
||||
@options = SERVER_DEFAULTS
|
||||
|
||||
|
||||
load_options(SERVER_AUTH_CONF_PATH)
|
||||
|
||||
begin
|
||||
@@ -52,7 +52,7 @@ class ServerX509Auth < X509Auth
|
||||
end
|
||||
|
||||
if @options[:srv_user] == nil || @options[:srv_user].empty?
|
||||
raise "User for x509 server not defined"
|
||||
raise "User for x509 server not defined"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,11 +60,14 @@ class ServerX509Auth < X509Auth
|
||||
# Client side
|
||||
###########################################################################
|
||||
|
||||
# Creates a ServerCipher for client usage
|
||||
alias :new_client :new
|
||||
# Creates a ServerCipher for client and driver sage
|
||||
class << ServerX509Auth
|
||||
alias :new_client :new
|
||||
alias :new_driver :new
|
||||
end
|
||||
|
||||
# Generates a login token in the form:
|
||||
# - server_user:target_user:time_expires
|
||||
# - server_user:target_user:time_expires
|
||||
def login_token(expire, target_user=nil)
|
||||
target_user ||= @options[:srv_user]
|
||||
token_txt = "#{@options[:srv_user]}:#{target_user}:#{expire}"
|
||||
@@ -78,20 +81,17 @@ class ServerX509Auth < X509Auth
|
||||
###########################################################################
|
||||
# Server side
|
||||
###########################################################################
|
||||
|
||||
# Creates a ServerCipher for driver usage
|
||||
alias :new_driver :new
|
||||
|
||||
# auth method for auth_mad
|
||||
def authenticate(server_user, server_pass, signed_text)
|
||||
begin
|
||||
begin
|
||||
s_user, t_user, expires = decrypt(signed_text).split(':')
|
||||
|
||||
|
||||
return "Server password missmatch" if server_pass != password
|
||||
|
||||
return "User name missmatch" if ( s_user != server_user ||
|
||||
return "User name missmatch" if ( s_user != server_user ||
|
||||
s_user != @options[:srv_user] )
|
||||
|
||||
|
||||
return "login token expired" if Time.now.to_i >= expires.to_i
|
||||
|
||||
return true
|
||||
|
||||
@@ -51,11 +51,8 @@ class X509Auth
|
||||
# @option options [String] :ca_dir
|
||||
# directory of trusted CA's. Needed for auth method, not for login.
|
||||
def initialize(options={})
|
||||
@options={
|
||||
:certs_pem => nil,
|
||||
:key_pem => nil,
|
||||
:ca_dir => X509_DEFAULTS[:ca_dir]
|
||||
}.merge!(options)
|
||||
@options ||= X509_DEFAULTS
|
||||
@options.merge!(options)
|
||||
|
||||
load_options(X509_AUTH_CONF_PATH)
|
||||
|
||||
@@ -65,7 +62,7 @@ class X509Auth
|
||||
|
||||
if @options[:key_pem]
|
||||
@key = OpenSSL::PKey::RSA.new(@options[:key_pem])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
@@ -73,7 +70,7 @@ class X509Auth
|
||||
###########################################################################
|
||||
|
||||
# Creates the login file for x509 authentication at ~/.one/one_x509.
|
||||
# By default it is valid as long as the certificate is valid. It can
|
||||
# By default it is valid as long as the certificate is valid. It can
|
||||
# be changed to any number of seconds with expire parameter (sec.)
|
||||
def login(user, expire=0)
|
||||
write_login(login_token(user,expire))
|
||||
@@ -95,26 +92,26 @@ class X509Auth
|
||||
else
|
||||
expires = @cert_chain[0].not_after.to_i
|
||||
end
|
||||
|
||||
|
||||
text_to_sign = "#{user}:#{expires}"
|
||||
signed_text = encrypt(text_to_sign)
|
||||
|
||||
certs_pem = @cert_chain.collect{|cert| cert.to_pem}.join(":")
|
||||
|
||||
token = "#{signed_text}:#{certs_pem}"
|
||||
token = "#{signed_text}:#{certs_pem}"
|
||||
token64 = Base64::encode64(token).strip.delete("\n")
|
||||
|
||||
login_out = "#{user}:#{token64}"
|
||||
|
||||
|
||||
login_out
|
||||
end
|
||||
|
||||
|
||||
###########################################################################
|
||||
# Server side
|
||||
###########################################################################
|
||||
# auth method for auth_mad
|
||||
def authenticate(user, pass, signed_text)
|
||||
begin
|
||||
begin
|
||||
# Decryption demonstrates that the user posessed the private key.
|
||||
_user, expires = decrypt(signed_text).split(':')
|
||||
|
||||
@@ -122,17 +119,17 @@ class X509Auth
|
||||
|
||||
return "x509 proxy expired" if Time.now.to_i >= expires.to_i
|
||||
|
||||
# Some DN in the chain must match a DN in the password
|
||||
# Some DN in the chain must match a DN in the password
|
||||
dn_ok = @cert_chain.each do |cert|
|
||||
if pass.split('|').include?(cert.subject.to_s.delete("\s"))
|
||||
break true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
unless dn_ok == true
|
||||
return "Certificate subject missmatch"
|
||||
end
|
||||
|
||||
|
||||
validate
|
||||
|
||||
return true
|
||||
@@ -142,20 +139,20 @@ class X509Auth
|
||||
end
|
||||
|
||||
private
|
||||
# Writes a login_txt to the login file as defined in LOGIN_PATH
|
||||
# Writes a login_txt to the login file as defined in LOGIN_PATH
|
||||
# constant
|
||||
def write_login(login_txt)
|
||||
# Inits login file path and creates ~/.one directory if needed
|
||||
# Set instance variables
|
||||
login_dir = File.dirname(LOGIN_PATH)
|
||||
|
||||
|
||||
begin
|
||||
FileUtils.mkdir_p(login_dir)
|
||||
rescue Errno::EEXIST
|
||||
end
|
||||
|
||||
file = File.open(LOGIN_PATH, "w")
|
||||
file.write(login_txt)
|
||||
file.write(login_txt)
|
||||
file.close
|
||||
|
||||
File.chmod(0600,LOGIN_PATH)
|
||||
@@ -182,9 +179,9 @@ private
|
||||
end
|
||||
|
||||
# Decrypts base 64 encoded data with pub_key (public key)
|
||||
def decrypt(data)
|
||||
def decrypt(data)
|
||||
@cert_chain[0].public_key.public_decrypt(Base64::decode64(data))
|
||||
end
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Validate the user certificate
|
||||
@@ -194,12 +191,12 @@ private
|
||||
failed = "Could not validate user credentials: "
|
||||
|
||||
# Check start time and end time of certificates
|
||||
@cert_chain.each do |cert|
|
||||
@cert_chain.each do |cert|
|
||||
if cert.not_before > now || cert.not_after < now
|
||||
raise failed + "Certificate not valid. Current time is " +
|
||||
raise failed + "Certificate not valid. Current time is " +
|
||||
now.localtime.to_s + "."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
# Validate the proxy certifcates
|
||||
@@ -211,13 +208,13 @@ private
|
||||
raise failed + signee.subject.to_s + " with issuer " +
|
||||
signee.issuer.to_s + " was not verified by " +
|
||||
cert.subject.to_s + "."
|
||||
end
|
||||
end
|
||||
signee = cert
|
||||
end
|
||||
|
||||
# Validate the End Entity certificate
|
||||
if !@options[:ca_dir]
|
||||
raise failed + "No certifcate authority directory was specified."
|
||||
raise failed + "No certifcate authority directory was specified."
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
@@ -159,6 +159,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
chtype_desc = <<-EOT.unindent
|
||||
Changes the Image group
|
||||
EOT
|
||||
|
||||
command :chtype, chtype_desc,[:range, :imageid_list], :type do
|
||||
helper.perform_actions(args[0],options,"Type changed") do |image|
|
||||
image.chtype(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
disable_desc = <<-EOT.unindent
|
||||
Disables the given Image
|
||||
EOT
|
||||
|
||||
+3
-3
@@ -153,9 +153,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Examples:
|
||||
oneuser create my_user my_password
|
||||
oneuser create my_user -r /tmp/mypass
|
||||
oneuser create my_user --ssh --key /tmp/id_rsa -d ssh
|
||||
oneuser create my_user --ssh -r /tmp/public_key -d ssh
|
||||
oneuser create my_user --x509 --cert /tmp/my_cert.pem -d x509
|
||||
oneuser create my_user --ssh --key /tmp/id_rsa
|
||||
oneuser create my_user --ssh -r /tmp/public_key
|
||||
oneuser create my_user --x509 --cert /tmp/my_cert.pem
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :username, [:password, nil],
|
||||
|
||||
+13
-2
@@ -36,6 +36,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper = OneVMHelper.new
|
||||
|
||||
|
||||
TYPE={
|
||||
:name => "type",
|
||||
:short => "-t type",
|
||||
:large => "--type type",
|
||||
:format => String,
|
||||
:description => "Type of the new Image"
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
@@ -142,14 +151,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
States: ANY
|
||||
EOT
|
||||
|
||||
command :saveas, saveas_desc, :vmid, :diskid, :img_name do
|
||||
command :saveas, saveas_desc, :vmid, :diskid, :img_name, :options=>[TYPE] do
|
||||
disk_id = args[1].to_i
|
||||
image_name = args[2]
|
||||
image_type = options[:type] || ""
|
||||
|
||||
verbose = "disk #{disk_id} prepared to be saved in " <<
|
||||
"the image #{image_name}"
|
||||
|
||||
helper.perform_action(args[0],options,verbose) do |vm|
|
||||
res = vm.save_as(disk_id, image_name)
|
||||
res = vm.save_as(disk_id, image_name, image_type)
|
||||
|
||||
if !OpenNebula.is_error?(res)
|
||||
puts "Image ID: #{res}"
|
||||
|
||||
@@ -19,7 +19,8 @@ module X509CloudAuth
|
||||
# password:: _String_ the password
|
||||
# [return] _Hash_ with the username
|
||||
def get_username(password)
|
||||
@oneadmin_client ||= OpenNebula::Client.new(nil, @conf[:one_xmlrpc])
|
||||
token = @server_auth.login_token(expiration_time)
|
||||
@oneadmin_client ||= OpenNebula::Client.new(token, @conf[:one_xmlrpc])
|
||||
|
||||
if @user_pool.nil?
|
||||
@user_pool ||= OpenNebula::UserPool.new(@oneadmin_client)
|
||||
@@ -32,7 +33,7 @@ module X509CloudAuth
|
||||
|
||||
username = @user_pool["USER[PASSWORD=\"#{password}\"]/NAME"]
|
||||
return username if (username != nil)
|
||||
|
||||
|
||||
# Check if the DN is part of a |-separted multi-DN password
|
||||
user_elts = Array.new
|
||||
@user_pool.each {|e| user_elts << e['PASSWORD']}
|
||||
@@ -98,11 +99,6 @@ module X509CloudAuth
|
||||
raise msg
|
||||
end
|
||||
|
||||
auth = ServerX509Auth.new
|
||||
|
||||
@token = auth.login_token(username, subjectname, 300)
|
||||
@client = Client.new(@token, @conf[:one_xmlrpc])
|
||||
|
||||
return nil
|
||||
return username
|
||||
end
|
||||
end
|
||||
@@ -21,17 +21,18 @@ ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
CONFIGURATION_FILE = "/etc/one/econe.conf"
|
||||
TEMPLATE_LOCATION = "/etc/one/ec2query_templates"
|
||||
EC2_AUTH = "/etc/one/auth/ec2_auth"
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/econe.conf"
|
||||
TEMPLATE_LOCATION = ONE_LOCATION+"/etc/ec2query_templates"
|
||||
EC2_AUTH = ONE_LOCATION + "/etc/auth/ec2_auth"
|
||||
end
|
||||
|
||||
VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views"
|
||||
EC2_AUTH = VAR_LOCATION + "/ec2_auth"
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
@@ -76,13 +77,13 @@ if CloudServer.is_port_open?(settings.config[:server],
|
||||
puts "Port busy, please shutdown the service or move econe server port."
|
||||
exit 1
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = EC2_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
rescue => e
|
||||
puts "Error initializing authentication system"
|
||||
puts e.message
|
||||
puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
@@ -91,7 +92,7 @@ set :cloud_auth, cloud_auth
|
||||
econe_host = conf[:ssl_server]
|
||||
econe_host ||= conf[:server]
|
||||
econe_port = conf[:port]
|
||||
|
||||
|
||||
set :econe_host, econe_host
|
||||
set :econe_port, econe_port
|
||||
|
||||
|
||||
@@ -26,16 +26,18 @@ ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
TEMPLATE_LOCATION="/etc/one/occi_templates"
|
||||
CONFIGURATION_FILE = "/etc/one/occi-server.conf"
|
||||
OCCI_AUTH = "/etc/one/auth/occi_auth"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
TEMPLATE_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/occi-server.conf"
|
||||
OCCI_AUTH = ONE_LOCATION + "/etc/auth/occi_auth"
|
||||
end
|
||||
|
||||
OCCI_AUTH = VAR_LOCATION + "/occi_auth"
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud" # For the Repository Manager
|
||||
@@ -80,15 +82,15 @@ end
|
||||
set :host, settings.config[:server]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
begin
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = OCCI_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
rescue => e
|
||||
puts "Error initializing authentication system"
|
||||
puts e.message
|
||||
puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
set :cloud_auth, cloud_auth
|
||||
|
||||
##############################################################################
|
||||
|
||||
+29
-2
@@ -105,8 +105,6 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
|
||||
erase_template_attribute("TYPE", type_att);
|
||||
|
||||
TO_UPPER(type_att);
|
||||
|
||||
if ( type_att.empty() == true )
|
||||
{
|
||||
type_att = ImagePool::default_type();
|
||||
@@ -521,3 +519,32 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Image::set_type(string& _type)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
TO_UPPER(_type);
|
||||
|
||||
if ( _type == "OS" )
|
||||
{
|
||||
type = OS;
|
||||
}
|
||||
else if ( _type == "CDROM" )
|
||||
{
|
||||
type = CDROM;
|
||||
}
|
||||
else if ( _type == "DATABLOCK" )
|
||||
{
|
||||
type = DATABLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@@ -35,6 +35,7 @@ public class Image extends PoolElement
|
||||
private static final String ENABLE = METHOD_PREFIX + "enable";
|
||||
private static final String PUBLISH = METHOD_PREFIX + "publish";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
private static final String CHTYPE = METHOD_PREFIX + "chtype";
|
||||
|
||||
private static final String[] IMAGE_STATES =
|
||||
{"INIT", "READY", "USED", "DISABLED"};
|
||||
@@ -162,6 +163,19 @@ public class Image extends PoolElement
|
||||
return client.call(CHOWN, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chtype(Client client, int id, String type)
|
||||
{
|
||||
return client.call(CHTYPE, id, type);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
@@ -296,6 +310,17 @@ public class Image extends PoolElement
|
||||
return chown(-1, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the Image type
|
||||
*
|
||||
* @param type The new Image type
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chtype(String type)
|
||||
{
|
||||
return chtype(client, id, type);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
||||
@@ -292,7 +292,22 @@ public class VirtualMachine extends PoolElement{
|
||||
*/
|
||||
public OneResponse savedisk(int diskId, String imageName)
|
||||
{
|
||||
return client.call(SAVEDISK, id ,diskId, imageName);
|
||||
return savedisk(diskId, imageName, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified vm's disk to be saved in a new image when the
|
||||
* VirtualMachine shutdowns.
|
||||
*
|
||||
* @param diskId ID of the disk to be saved.
|
||||
* @param imageName Name of the new Image that will be created.
|
||||
* @param imageType Type of the new image. Set to empty string to use
|
||||
* the default type
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse savedisk(int diskId, String imageName, String imageType)
|
||||
{
|
||||
return client.call(SAVEDISK, id ,diskId, imageName, imageType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,8 @@ module OpenNebula
|
||||
:publish => "image.publish",
|
||||
:persistent => "image.persistent",
|
||||
:delete => "image.delete",
|
||||
:chown => "image.chown"
|
||||
:chown => "image.chown",
|
||||
:chtype => "image.chtype"
|
||||
}
|
||||
|
||||
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR}
|
||||
@@ -145,6 +146,19 @@ module OpenNebula
|
||||
super(IMAGE_METHODS[:chown], uid, gid)
|
||||
end
|
||||
|
||||
# Changes the Image type
|
||||
# @param type [String] new Image type
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chtype(type)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Image information
|
||||
#######################################################################
|
||||
|
||||
@@ -217,13 +217,19 @@ module OpenNebula
|
||||
# @param disk_id [Integer] ID of the disk to be saved
|
||||
# @param image_name [String] Name for the new image where the
|
||||
# disk will be saved
|
||||
# @param image_type [String] Type of the new image. Set to empty string
|
||||
# to use the default type
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new Image ID in case of
|
||||
# success, error otherwise
|
||||
def save_as(disk_id, image_name)
|
||||
def save_as(disk_id, image_name, image_type="")
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name)
|
||||
rc = @client.call(VM_METHODS[:savedisk],
|
||||
@pe_id,
|
||||
disk_id,
|
||||
image_name,
|
||||
image_type)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
@@ -267,6 +267,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr template_publish(new TemplatePublish());
|
||||
xmlrpc_c::methodPtr vn_publish(new VirtualNetworkPublish());
|
||||
xmlrpc_c::methodPtr image_publish(new ImagePublish());
|
||||
xmlrpc_c::methodPtr image_chtype(new ImageChangeType());
|
||||
|
||||
// Delete Methods
|
||||
xmlrpc_c::methodPtr host_delete(new HostDelete());
|
||||
@@ -385,6 +386,7 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
|
||||
RequestManagerRegistry.addMethod("one.image.info", image_info);
|
||||
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
|
||||
RequestManagerRegistry.addMethod("one.image.chtype", image_chtype);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
|
||||
|
||||
|
||||
@@ -112,3 +112,51 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string type = xmlrpc_c::value_string(paramList.getString(2));
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
string err_msg;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
image = static_cast<Image *>(pool->get(id,true));
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object),id),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
rc = image->set_type(type);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
err_msg = "Unknown type " + type;
|
||||
|
||||
failure_response(INTERNAL,request_error(err_msg,""), att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(image);
|
||||
|
||||
image->unlock();
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
@@ -394,6 +394,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int disk_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
string img_name = xmlrpc_c::value_string(paramList.getString(3));
|
||||
string img_type = xmlrpc_c::value_string(paramList.getString(4));
|
||||
|
||||
VirtualMachine * vm;
|
||||
string vm_owner;
|
||||
@@ -412,6 +413,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
oss << "PUBLIC = NO " << endl;
|
||||
oss << "SOURCE = - " << endl;
|
||||
|
||||
if ( img_type != "" )
|
||||
{
|
||||
oss << "TYPE = " << img_type << endl;
|
||||
}
|
||||
|
||||
itemplate = new ImageTemplate;
|
||||
|
||||
itemplate->parse(oss.str(), &error_char);
|
||||
|
||||
@@ -88,7 +88,7 @@ module OpenNebulaJSON
|
||||
end
|
||||
|
||||
def save_as(params=Hash.new)
|
||||
super(params['disk_id'].to_i, params['image_name'])
|
||||
super(params['disk_id'].to_i, params['image_name'], params['type'])
|
||||
end
|
||||
|
||||
def chown(params=Hash.new)
|
||||
|
||||
@@ -812,7 +812,7 @@ function setupSaveasDialog(){
|
||||
var id = $('#vm_id',this).text();
|
||||
var disk_id = $('#vm_disk_id',this).val();
|
||||
var image_name = $('#image_name',this).val();
|
||||
//var type = $('#image_type',this).val();
|
||||
var type = $('#image_type',this).val();
|
||||
|
||||
if (!id.length || !disk_id.length || !image_name.length) {
|
||||
notifyError("Skipping VM "+id+
|
||||
@@ -821,8 +821,8 @@ function setupSaveasDialog(){
|
||||
else {
|
||||
var obj = {
|
||||
disk_id : disk_id,
|
||||
image_name : image_name
|
||||
//type: type
|
||||
image_name : image_name,
|
||||
type: type
|
||||
};
|
||||
args.push(id);
|
||||
Sunstone.runAction("VM.saveas",id,obj);
|
||||
@@ -865,20 +865,15 @@ function popUpSaveasDialog(elems){
|
||||
<label for="image_name">Image name:</label>\
|
||||
<input type="text" id="image_name" name="image_name" value="" />\
|
||||
</div>\
|
||||
<!-- not used anymore\
|
||||
<div>\
|
||||
<label for="img_attr_value">Type:</label>\
|
||||
<select id="image_type" name="image_type">\
|
||||
<option value="">Default</option>\
|
||||
<option value="disk">Disk</option>\
|
||||
<option value="floppy">Floppy</option>\
|
||||
<option value="">Default (current image type)</option>\
|
||||
<option value="os">OS</option>\
|
||||
<option value="datablock">Datablock</option>\
|
||||
<option value="cdrom">CD-ROM</option>\
|
||||
<option value="swap">Swap</option>\
|
||||
<option value="fs">FS</option>\
|
||||
<option value="block">Block</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
-->\
|
||||
</fieldset>\
|
||||
</div>';
|
||||
$('#saveas_tabs',dialog).append(tab);
|
||||
|
||||
@@ -22,19 +22,19 @@ ONE_LOCATION = ENV["ONE_LOCATION"]
|
||||
if !ONE_LOCATION
|
||||
LOG_LOCATION = "/var/log/one"
|
||||
VAR_LOCATION = "/var/lib/one"
|
||||
ETC_LOCATION = "/etc/one"
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
|
||||
CONFIGURATION_FILE = "/etc/one/sunstone-server.conf"
|
||||
PLUGIN_CONFIGURATION_FILE = "/etc/one/sunstone-plugins.yaml"
|
||||
SUNSTONE_AUTH = "/var/one/sunstone_auth"
|
||||
else
|
||||
VAR_LOCATION = ONE_LOCATION+"/var"
|
||||
LOG_LOCATION = ONE_LOCATION+"/var"
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
LOG_LOCATION = ONE_LOCATION + "/var"
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-server.conf"
|
||||
PLUGIN_CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-plugins.yaml"
|
||||
SUNSTONE_AUTH = ONE_LOCATION + "/var/sunstone_auth"
|
||||
end
|
||||
|
||||
SUNSTONE_AUTH = VAR_LOCATION + "/sunstone_auth"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf"
|
||||
PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml"
|
||||
|
||||
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
@@ -68,12 +68,12 @@ set :config, conf
|
||||
set :host, settings.config[:host]
|
||||
set :port, settings.config[:port]
|
||||
|
||||
begin
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = SUNSTONE_AUTH
|
||||
cloud_auth = CloudAuth.new(settings.config)
|
||||
rescue => e
|
||||
puts "Error initializing authentication system"
|
||||
puts e.message
|
||||
puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
@@ -154,7 +154,7 @@ end
|
||||
##############################################################################
|
||||
get '/' do
|
||||
if !authorized?
|
||||
if settings.config[:auth] == "x509"
|
||||
if settings.config[:auth] == "x509"
|
||||
templ = "login_x509.html"
|
||||
else
|
||||
templ = "login.html"
|
||||
@@ -181,7 +181,7 @@ end
|
||||
|
||||
get '/login' do
|
||||
if !authorized?
|
||||
if settings.config[:auth] == "x509"
|
||||
if settings.config[:auth] == "x509"
|
||||
templ = "login_x509.html"
|
||||
else
|
||||
templ = "login.html"
|
||||
|
||||
+114
-101
@@ -26,6 +26,9 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fnmatch.h>
|
||||
@@ -51,19 +54,23 @@ UserPool::UserPool(SqlDB * db,
|
||||
{
|
||||
int one_uid = -1;
|
||||
int server_uid = -1;
|
||||
int i;
|
||||
|
||||
ostringstream oss;
|
||||
string one_token;
|
||||
string one_name;
|
||||
string one_pass;
|
||||
string one_auth_file;
|
||||
string random;
|
||||
|
||||
const char * one_auth;
|
||||
ifstream file;
|
||||
|
||||
string var_location;
|
||||
const char * one_location;
|
||||
string filenames[3];
|
||||
string error_str;
|
||||
stringstream sstr;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
_session_expiration_time = __session_expiration_time;
|
||||
|
||||
@@ -90,120 +97,126 @@ UserPool::UserPool(SqlDB * db,
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "Could not get one_auth file location";
|
||||
goto error_no_file;
|
||||
}
|
||||
}
|
||||
|
||||
file.open(one_auth);
|
||||
|
||||
if (file.good())
|
||||
if (!file.good())
|
||||
{
|
||||
getline(file,one_token);
|
||||
goto error_file;
|
||||
}
|
||||
|
||||
if (file.fail())
|
||||
{
|
||||
oss << "Error reading file: " << one_auth;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (User::split_secret(one_token,one_name,one_pass) == 0)
|
||||
{
|
||||
if ( one_name == SERVER_NAME )
|
||||
{
|
||||
oss << "The name '" << SERVER_NAME << "' is reserved";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the serveradmin user with a random password, and
|
||||
// write its authentication configuration files
|
||||
getline(file,one_token);
|
||||
|
||||
stringstream sstr;
|
||||
srand(time(0));
|
||||
sstr << rand();
|
||||
|
||||
string random = SSLTools::sha1_digest( sstr.str() );
|
||||
|
||||
one_location = getenv("ONE_LOCATION");
|
||||
|
||||
if (one_location == 0)
|
||||
{
|
||||
var_location = "/var/lib/one/";
|
||||
}
|
||||
else
|
||||
{
|
||||
var_location = one_location;
|
||||
var_location += "/var/";
|
||||
}
|
||||
|
||||
filenames[0] = var_location + "sunstone_auth";
|
||||
filenames[1] = var_location + "occi_auth";
|
||||
filenames[2] = var_location + "ec2_auth";
|
||||
|
||||
bool success = true;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while ( i < 3 && success )
|
||||
{
|
||||
ofstream ofile;
|
||||
ofile.open(filenames[i].c_str(), ios::out | ios::trunc);
|
||||
|
||||
if ( ofile.is_open() )
|
||||
{
|
||||
ofile << SERVER_NAME << ":" << random << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
|
||||
oss << "Could not create configuration file "<<
|
||||
filenames[i];
|
||||
}
|
||||
|
||||
ofile.close();
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( success )
|
||||
{
|
||||
allocate(&one_uid,
|
||||
GroupPool::ONEADMIN_ID,
|
||||
one_name,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
one_pass,
|
||||
UserPool::CORE_AUTH,
|
||||
true,
|
||||
error_str);
|
||||
|
||||
allocate(&server_uid,
|
||||
GroupPool::ONEADMIN_ID,
|
||||
SERVER_NAME,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
SSLTools::sha1_digest(random),
|
||||
"server_cipher",
|
||||
true,
|
||||
error_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "Wrong format must be <username>:<password>";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (file.fail())
|
||||
{
|
||||
oss << "Could not open file: " << one_auth;
|
||||
goto error_file_read;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
if (one_uid != 0 || server_uid != 1)
|
||||
if (User::split_secret(one_token,one_name,one_pass) != 0)
|
||||
{
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
throw;
|
||||
goto error_token;
|
||||
}
|
||||
|
||||
if ( one_name == SERVER_NAME )
|
||||
{
|
||||
goto error_one_name;
|
||||
}
|
||||
|
||||
srand(time(0));
|
||||
sstr << rand();
|
||||
|
||||
random = SSLTools::sha1_digest( sstr.str() );
|
||||
|
||||
filenames[0] = nd.get_var_location() + "/sunstone_auth";
|
||||
filenames[1] = nd.get_var_location() + "/occi_auth";
|
||||
filenames[2] = nd.get_var_location() + "/ec2_auth";
|
||||
|
||||
for (i=0 ; i < 3; i++)
|
||||
{
|
||||
int cfile = creat(filenames[i].c_str(), S_IRUSR | S_IWUSR);
|
||||
close(cfile);
|
||||
|
||||
ofstream ofile;
|
||||
ofile.open(filenames[i].c_str(), ios::out | ios::trunc);
|
||||
|
||||
if ( !ofile.is_open() )
|
||||
{
|
||||
goto error_no_open;
|
||||
}
|
||||
|
||||
ofile << SERVER_NAME << ":" << random << endl;
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
allocate(&one_uid,
|
||||
GroupPool::ONEADMIN_ID,
|
||||
one_name,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
one_pass,
|
||||
UserPool::CORE_AUTH,
|
||||
true,
|
||||
error_str);
|
||||
|
||||
if ( one_uid != 0 )
|
||||
{
|
||||
goto error_oneadmin;
|
||||
}
|
||||
|
||||
allocate(&server_uid,
|
||||
GroupPool::ONEADMIN_ID,
|
||||
SERVER_NAME,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
SSLTools::sha1_digest(random),
|
||||
"server_cipher",
|
||||
true,
|
||||
error_str);
|
||||
|
||||
if ( server_uid != 1 )
|
||||
{
|
||||
goto error_serveradmin;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_no_file:
|
||||
oss << "Could not get one_auth file location";
|
||||
goto error_common;
|
||||
|
||||
error_file:
|
||||
oss << "Could not open file: " << one_auth;
|
||||
goto error_common;
|
||||
|
||||
error_file_read:
|
||||
oss << "Error reading file: " << one_auth;
|
||||
goto error_common;
|
||||
|
||||
error_token:
|
||||
oss << "Wrong format must be <username>:<password>";
|
||||
goto error_common;
|
||||
|
||||
error_one_name:
|
||||
oss << "The name '" << SERVER_NAME << "' is reserved";
|
||||
goto error_common;
|
||||
|
||||
error_no_open:
|
||||
oss << "Could not create configuration file "<< filenames[i];
|
||||
goto error_common;
|
||||
|
||||
error_oneadmin:
|
||||
oss << "Error creating oneadmin user: " << error_str;
|
||||
goto error_common;
|
||||
|
||||
error_serveradmin:
|
||||
oss << "Error creating server_admin user: " << error_str;
|
||||
|
||||
error_common:
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
throw;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
const string VirtualMachineTemplate::RESTRICTED_ATTRIBUTES[] = {
|
||||
"CONTEXT/FILES",
|
||||
"DISK/SOURCE",
|
||||
"NIC/MAC"
|
||||
"NIC/MAC",
|
||||
"NIC/VLAN_ID"
|
||||
};
|
||||
|
||||
const int VirtualMachineTemplate::RS_ATTRS_LENGTH = 3;
|
||||
|
||||
Reference in new issue
Block a user