1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Authorized ports to access VMs can no be specified in EC2. Sample configurations for EC2 drivers added

git-svn-id: http://svn.opennebula.org/trunk@64 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-07-18 22:14:06 +00:00
parent 9ad19c4387
commit 537a7058d5
5 changed files with 95 additions and 53 deletions

View File

@ -56,6 +56,16 @@ IM_MAD = [
# default = "etc/im_kvm/im_kvm.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Information Driver Manager sample configuration
#-------------------------------------------------------------------------------
# IM_MAD = [
# name = "im_ec2",
# executable = "bin/one_im_ec2",
# arguments = "etc/im_ec2/im_ec2.conf",
# default = "etc/im_ec2/im_ec2.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Virtualization Driver Configuration
#-------------------------------------------------------------------------------
@ -85,6 +95,15 @@ VM_MAD = [
# type = "kvm" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Virtualization Driver Manager sample configuration
#-------------------------------------------------------------------------------
# VM_MAD = [
# name = "vmm_ec2",
# executable = "bin/one_vmm_ec2",
# default = "etc/vmm_ec2/vmm_ec2.conf",
# type = "ec2" ]
#-------------------------------------------------------------------------------

View File

@ -47,7 +47,7 @@ class IM < ONEMad
end
STDOUT.puts "MONITOR SUCCESS " + args[1].to_s +
" HOSTNAME=#{args[2]},TOTALMEMORY=#{totalmemory},TOTALCPU=#{totalcpu},CPUSPEED=1000"
"HOSTNAME=#{args[2]},TOTALMEMORY=#{totalmemory},TOTALCPU=#{totalcpu},CPUSPEED=1000,FREEMEMORY=#{totalmemory},FREECPU=#{totalcpu}"
STDOUT.flush
end

View File

@ -27,53 +27,54 @@ int EC2Driver::deployment_description(
ofstream file;
vector<const Attribute *> attrs;
const VectorAttribute * ec2;
string aminame = "";
string keypair = "";
string elasticip = "";
string a_ports = "";
string itype = "";
// -------------------------------------------------------------------------
file.open(file_name.c_str(), ios::out);
if (file.fail() == true)
{
goto error_file;
}
// -------------------------------------------------------------------------
if ( vm->get_template_attribute("EC2",attrs) == 0 )
{
goto error_ec2;
}
ec2 = static_cast<const VectorAttribute *>(attrs[0]);
// ------------------------------------------------------------------------
// AMI - Amazon Machine Image
// ------------------------------------------------------------------------
aminame = ec2->vector_value("AMI");
if (aminame.empty())
{
goto error_aminame;
}
file << "aminame=" << aminame << "\n" << endl;
// ------------------------------------------------------------------------
// KEY PAIR - IdRsa key pair
// ------------------------------------------------------------------------
keypair = ec2->vector_value("KEYPAIR");
if (keypair.empty())
{
get_default("EC2","KEYPAIR",keypair);
if ( keypair.empty() )
{
goto error_keypair;
@ -87,22 +88,38 @@ int EC2Driver::deployment_description(
// ------------------------------------------------------------------------
elasticip = ec2->vector_value("ELASTICIP");
if (!elasticip.empty())
{
file << "elasticip=" << elasticip << "\n" << endl;
}
// ------------------------------------------------------------------------
// AUTHORIZED PORTS
// ------------------------------------------------------------------------
a_ports = ec2->vector_value("AUTHORIZEDPORTS");
if (a_ports.empty())
{
get_default("EC2","AUTHORIZEDPORTS",a_ports);
}
if (!a_ports.empty())
{
file << "authorizedports=" << a_ports << "\n" << endl;
}
// ------------------------------------------------------------------------
// INSTANCE TYPE
// ------------------------------------------------------------------------
itype = ec2->vector_value("INSTANCETYPE");
if (itype.empty())
{
get_default("EC2","INSTANCETYPE",itype);
if ( itype.empty() )
{
goto error_itype;
@ -110,32 +127,32 @@ int EC2Driver::deployment_description(
}
file << "instancetype=" << itype << "\n" << endl;
file.close();
return 0;
error_file:
vm->log("VMM", Log::ERROR, "Could not open EC2 deployment file.");
return -1;
return -1;
error_ec2:
vm->log("VMM", Log::ERROR, "No EC2 attributes found.");
file.close();
file.close();
return -1;
error_aminame:
vm->log("VMM", Log::ERROR, "No AMI name attribute defined.");
file.close();
file.close();
return -1;
error_keypair:
vm->log("VMM", Log::ERROR, "No keypair defined and no default provided.");
file.close();
file.close();
return -1;
error_itype:
vm->log("VMM", Log::ERROR, "No AMI type defined and no default provided.");
file.close();
file.close();
return -1;
}

View File

@ -40,40 +40,43 @@ require 'one_mad'
require 'open3'
class DM < ONEMad
def initialize
super(5, 4)
end
def action_init(args)
send_message("INIT", "SUCCESS")
end
def action_deploy(args)
pkeypair = ""
paminame = ""
pinstance = ""
pports = ""
File.read(args[3]).split(/\n/).each{|line|
result = line.split(/=/)
pkeypair = result[1] if result[0] == "keypair"
paminame = result[1] if result[0] == "aminame"
pinstance = result[1] if result[0] == "instancetype"
}
pports = result[1] if result[0] == "authorizedports"
}
std_action("DEPLOY", "#{EC2_LOCATION}bin/ec2-run-instances #{paminame} -k #{pkeypair} -t #{pinstance}", args)
Open3.popen3("#{EC2_LOCATION}bin/ec2-authorize default -p 22; echo ExitCode: $? 1>&2")
Open3.popen3("#{EC2_LOCATION}bin/ec2-authorize default -p #{pports}; echo ExitCode: $? 1>&2") if !pports.empty?
end
def action_shutdown(args)
std_action("SHUTDOWN", "#{EC2_LOCATION}bin/ec2-terminate-instances #{args[3]}", args)
@ -87,19 +90,19 @@ class DM < ONEMad
end
def action_checkpoint(args)
send_message("CHECKPOINT", "FAILURE", args[1], "action not supported for EC2")
end
def action_save(args)
send_message("SAVE", "FAILURE", args[1], "action not supported for EC2")
end
def action_restore(args)
send_message("RESTORE", "FAILURE", args[1], "action not supported for EC2")
end
@ -109,7 +112,7 @@ class DM < ONEMad
std = Open3.popen3("#{EC2_LOCATION}bin/ec2-describe-instances #{args[3]}; echo ExitCode: $? 1>&2")
stdout=std[1].read
stderr=std[2].read
stderr=std[2].read
exit_code=get_exit_code(stderr)
@ -122,31 +125,31 @@ class DM < ONEMad
ip_address = result[3]
break
end
}
}
end
send_message("POLL", "SUCCESS", args[1],"USEDCPU=0.0 NETTX=0 NETRX=0 USEDMEMORY=0 IP=#{ip_address}")
end
###########################
# Common action functions #
###########################
def std_action(action, command, args)
std= Open3.popen3("#{command} ; echo ExitCode: $? 1>&2")
stdout=std[1].read
stderr=std[2].read
stderr=std[2].read
exit_code=get_exit_code(stderr)
if exit_code=="0"
domain_name=""
if action=="DEPLOY"
domain_name = "id_not_found"
stdout.split(/\n/).each{|line|
@ -155,7 +158,7 @@ class DM < ONEMad
domain_name = result[1]
break
end
}
}
pelasticip=""
@ -165,13 +168,13 @@ class DM < ONEMad
if result[0] == "elasticip"
pelasticip = result[1]
pelasticip = result[1]
Open3.popen3("#{EC2_LOCATION}bin/ec2-associate-address #{pelasticip} -i #{domain_name}; echo ExitCode: $? 1>&2")
break
end
}
}
else
domain_name=get_domain_name(stdout)
@ -183,7 +186,7 @@ class DM < ONEMad
end
end
#########################################
# Get information form xm create output #
#########################################
@ -198,7 +201,7 @@ class DM < ONEMad
return -1
end
end
# From STDERR if exit code == 1
def get_error_message(str)
#puts "escanenado el mensaje del error ..." + str
@ -214,7 +217,7 @@ class DM < ONEMad
return nil if !tmp[0]
tmp[0][0]
end
end
dm=DM.new

View File

@ -1,7 +1,10 @@
# Default configuration attributes for the KVM driver
# (all domains will use these values as defaults)
# Valid atributes are:
# - ec2[keypair,instancetype]
#Example: EC2 = [ keypair="gsg-keypair", instancetype="m1.small"]
# - ec2[keypair,authorizedports,instancetype]
#Example:
# EC2 = [ keypair = "gsg-keypair",
# authorizedports = 22,
# instancetype = "m1.small"]
EC2 = [ instancetype="m1.small" ]