mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
feauture #3041: take out occi from main repo
This commit is contained in:
parent
fbc9bfbe10
commit
a04a2c379e
install.sh
share
man
pkgs
src/cloud
common/CloudAuth
occi
bin
etc
lib
ImageOCCI.rbImagePoolOCCI.rbOCCIClient.rbOCCIServer.rbUserOCCI.rbUserPoolOCCI.rbVirtualMachineOCCI.rbVirtualMachinePoolOCCI.rbVirtualNetworkOCCI.rbVirtualNetworkPoolOCCI.rbocci-server.rbocci_application.rb
share/examples
test
66
install.sh
66
install.sh
@ -29,7 +29,7 @@
|
||||
usage() {
|
||||
echo
|
||||
echo "Usage: install.sh [-u install_user] [-g install_group] [-k keep conf]"
|
||||
echo " [-d ONE_LOCATION] [-c occi|ec2] [-r] [-h]"
|
||||
echo " [-d ONE_LOCATION] [-c cli|ec2] [-r] [-h]"
|
||||
echo
|
||||
echo "-u: user that will run opennebula, defaults to user executing install.sh"
|
||||
echo "-g: group of the user that will run opennebula, defaults to user"
|
||||
@ -39,7 +39,7 @@ usage() {
|
||||
echo " OpenNebula for the first time"
|
||||
echo "-d: target installation directory, if not defined it'd be root. Must be"
|
||||
echo " an absolute path."
|
||||
echo "-c: install client utilities: OpenNebula cli, occi and ec2 client files"
|
||||
echo "-c: install client utilities: OpenNebula cli and ec2 client files"
|
||||
echo "-s: install OpenNebula Sunstone"
|
||||
echo "-G: install OpenNebula Gate"
|
||||
echo "-f: install OpenNebula Flow"
|
||||
@ -214,7 +214,6 @@ ETC_DIRS="$ETC_LOCATION/vmm_exec \
|
||||
$ETC_LOCATION/auth \
|
||||
$ETC_LOCATION/auth/certificates \
|
||||
$ETC_LOCATION/ec2query_templates \
|
||||
$ETC_LOCATION/occi_templates \
|
||||
$ETC_LOCATION/sunstone-views \
|
||||
$ETC_LOCATION/cli"
|
||||
|
||||
@ -223,7 +222,6 @@ LIB_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/cloud/ \
|
||||
$LIB_LOCATION/ruby/cloud/econe \
|
||||
$LIB_LOCATION/ruby/cloud/econe/views \
|
||||
$LIB_LOCATION/ruby/cloud/occi \
|
||||
$LIB_LOCATION/ruby/cloud/marketplace \
|
||||
$LIB_LOCATION/ruby/cloud/CloudAuth \
|
||||
$LIB_LOCATION/ruby/onedb \
|
||||
@ -356,10 +354,6 @@ LIB_ECO_CLIENT_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/cloud/ \
|
||||
$LIB_LOCATION/ruby/cloud/econe"
|
||||
|
||||
LIB_OCCI_CLIENT_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/opennebula \
|
||||
$LIB_LOCATION/ruby/cloud/occi"
|
||||
|
||||
LIB_MARKET_CLIENT_DIRS="$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/opennebula \
|
||||
$LIB_LOCATION/ruby/cloud/marketplace"
|
||||
@ -373,7 +367,7 @@ LIB_CLI_CLIENT_DIRS="$LIB_LOCATION/ruby/cli \
|
||||
CONF_CLI_DIRS="$ETC_LOCATION/cli"
|
||||
|
||||
if [ "$CLIENT" = "yes" ]; then
|
||||
MAKE_DIRS="$MAKE_DIRS $LIB_ECO_CLIENT_DIRS $LIB_OCCI_CLIENT_DIRS $LIB_MARKET_CLIENT_DIRS \
|
||||
MAKE_DIRS="$MAKE_DIRS $LIB_ECO_CLIENT_DIRS $LIB_MARKET_CLIENT_DIRS \
|
||||
$LIB_OCA_CLIENT_DIRS $LIB_CLI_CLIENT_DIRS $CONF_CLI_DIRS \
|
||||
$ETC_LOCATION"
|
||||
elif [ "$ONEGATE" = "yes" ]; then
|
||||
@ -467,8 +461,6 @@ INSTALL_FILES=(
|
||||
ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe
|
||||
ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views
|
||||
ECO_BIN_FILES:$BIN_LOCATION
|
||||
OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi
|
||||
OCCI_BIN_FILES:$BIN_LOCATION
|
||||
MARKET_LIB_FILES:$LIB_LOCATION/ruby/cloud/marketplace
|
||||
MARKET_BIN_FILES:$BIN_LOCATION
|
||||
MAN_FILES:$MAN_LOCATION
|
||||
@ -486,8 +478,6 @@ INSTALL_CLIENT_FILES=(
|
||||
ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe
|
||||
ECO_BIN_CLIENT_FILES:$BIN_LOCATION
|
||||
COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud
|
||||
OCCI_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/occi
|
||||
OCCI_BIN_CLIENT_FILES:$BIN_LOCATION
|
||||
MARKET_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/marketplace
|
||||
MARKET_BIN_CLIENT_FILES:$BIN_LOCATION
|
||||
CLI_BIN_FILES:$BIN_LOCATION
|
||||
@ -591,8 +581,6 @@ INSTALL_ETC_FILES=(
|
||||
AUTH_ETC_FILES:$ETC_LOCATION/auth
|
||||
ECO_ETC_FILES:$ETC_LOCATION
|
||||
ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates
|
||||
OCCI_ETC_FILES:$ETC_LOCATION
|
||||
OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates
|
||||
CLI_CONF_FILES:$ETC_LOCATION/cli
|
||||
)
|
||||
|
||||
@ -1294,8 +1282,7 @@ COMMON_CLOUD_LIB_FILES="src/cloud/common/CloudServer.rb \
|
||||
|
||||
COMMON_CLOUD_CLIENT_LIB_FILES="src/cloud/common/CloudClient.rb"
|
||||
|
||||
CLOUD_AUTH_LIB_FILES="src/cloud/common/CloudAuth/OCCICloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/SunstoneCloudAuth.rb \
|
||||
CLOUD_AUTH_LIB_FILES="src/cloud/common/CloudAuth/SunstoneCloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/EC2CloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/X509CloudAuth.rb \
|
||||
src/cloud/common/CloudAuth/OneGateCloudAuth.rb \
|
||||
@ -1398,46 +1385,6 @@ ECO_ETC_FILES="src/cloud/ec2/etc/econe.conf"
|
||||
|
||||
ECO_ETC_TEMPLATE_FILES="src/cloud/ec2/etc/templates/m1.small.erb"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# OCCI files
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
OCCI_LIB_FILES="src/cloud/occi/lib/OCCIServer.rb \
|
||||
src/cloud/occi/lib/occi-server.rb \
|
||||
src/cloud/occi/lib/occi_application.rb \
|
||||
src/cloud/occi/lib/OCCIClient.rb \
|
||||
src/cloud/occi/lib/VirtualMachineOCCI.rb \
|
||||
src/cloud/occi/lib/VirtualMachinePoolOCCI.rb \
|
||||
src/cloud/occi/lib/VirtualNetworkOCCI.rb \
|
||||
src/cloud/occi/lib/VirtualNetworkPoolOCCI.rb \
|
||||
src/cloud/occi/lib/UserOCCI.rb \
|
||||
src/cloud/occi/lib/UserPoolOCCI.rb \
|
||||
src/cloud/occi/lib/ImageOCCI.rb \
|
||||
src/cloud/occi/lib/ImagePoolOCCI.rb \
|
||||
src/sunstone/OpenNebulaVNC.rb"
|
||||
|
||||
OCCI_LIB_CLIENT_FILES="src/cloud/occi/lib/OCCIClient.rb"
|
||||
|
||||
OCCI_BIN_FILES="src/cloud/occi/bin/occi-server \
|
||||
src/cloud/occi/bin/occi-compute \
|
||||
src/cloud/occi/bin/occi-network \
|
||||
src/cloud/occi/bin/occi-instance-type \
|
||||
src/cloud/occi/bin/occi-storage"
|
||||
|
||||
OCCI_BIN_CLIENT_FILES="src/cloud/occi/bin/occi-compute \
|
||||
src/cloud/occi/bin/occi-network \
|
||||
src/cloud/occi/bin/occi-instance-type \
|
||||
src/cloud/occi/bin/occi-storage"
|
||||
|
||||
OCCI_ETC_FILES="src/cloud/occi/etc/occi-server.conf"
|
||||
|
||||
OCCI_ETC_TEMPLATE_FILES="src/cloud/occi/etc/templates/common.erb \
|
||||
src/cloud/occi/etc/templates/custom.erb \
|
||||
src/cloud/occi/etc/templates/small.erb \
|
||||
src/cloud/occi/etc/templates/medium.erb \
|
||||
src/cloud/occi/etc/templates/network.erb \
|
||||
src/cloud/occi/etc/templates/large.erb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Marketplace Client
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -1879,10 +1826,7 @@ MAN_FILES="share/man/oneacct.1.gz \
|
||||
share/man/econe-start-instances.1.gz \
|
||||
share/man/econe-stop-instances.1.gz \
|
||||
share/man/econe-terminate-instances.1.gz \
|
||||
share/man/econe-upload.1.gz \
|
||||
share/man/occi-compute.1.gz \
|
||||
share/man/occi-network.1.gz \
|
||||
share/man/occi-storage.1.gz"
|
||||
share/man/econe-upload.1.gz"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Ruby VENDOR files
|
||||
|
@ -47,9 +47,6 @@ env.Man('econe-stop-instances')
|
||||
env.Man('econe-terminate-instances')
|
||||
env.Man('econe-upload')
|
||||
|
||||
env.Man('occi-compute')
|
||||
env.Man('occi-network')
|
||||
env.Man('occi-storage')
|
||||
env.Man('oneacct')
|
||||
env.Man('oneacl')
|
||||
env.Man('onecluster')
|
||||
|
@ -1,76 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||
.TH OPENNEBULA "1" "July 2014" "OpenNebula 4.7.80" "User Commands"
|
||||
.SH NAME
|
||||
OpenNebula \- OCCI Manage Compute
|
||||
.SH SYNOPSIS
|
||||
.B occi-compute
|
||||
\fI<COMMAND> \fR[\fIOPTIONS\fR] [\fIARGUMENTS\fR]
|
||||
.SH DESCRIPTION
|
||||
occi\-compute \- Manages compute resources
|
||||
.SH OPTIONS
|
||||
|
||||
\fB\-\-help\fR, \fB\-h\fR
|
||||
.IP
|
||||
Show help
|
||||
.PP
|
||||
\fB\-\-username\fR <id>, \fB\-U\fR <id>
|
||||
.IP
|
||||
The username of the user
|
||||
.PP
|
||||
\fB\-\-password\fR <key>, \fB\-P\fR <key>
|
||||
.IP
|
||||
The password of the user
|
||||
.PP
|
||||
\fB\-\-url\fR <url>, \fB\-R\fR <url>
|
||||
.IP
|
||||
Set url as the web service url to use
|
||||
.PP
|
||||
\fB\-\-timeout\fR <seconds>, \fB\-T\fR <seconds>
|
||||
.IP
|
||||
Sets a timeout for the http connection
|
||||
.PP
|
||||
\fB\-\-debug\fR, \fB\-D\fR
|
||||
.IP
|
||||
Enables verbosity
|
||||
.PP
|
||||
\fB\-\-verbose\fR
|
||||
.IP
|
||||
Show resources in verbose mode
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
\fBcreate\fR <occi xml file>
|
||||
.IP
|
||||
creates a new compute resource described by the provided
|
||||
<occi xml file>
|
||||
.TP
|
||||
\fBlist\fR
|
||||
.IP
|
||||
lists available compute resources
|
||||
.TP
|
||||
\fBshow\fR <compute id>
|
||||
.IP
|
||||
retrieves the OCCI XML representation of the compute resource
|
||||
identified by <compute id>
|
||||
.TP
|
||||
\fBupdate\fR <occi xml file>
|
||||
.IP
|
||||
updates the representation of the compute resource represented by the
|
||||
provided <occi xml file>
|
||||
.TP
|
||||
\fBdelete\fR <compute id>
|
||||
.IP
|
||||
deletes the compute resource idenfitied by <compute id>
|
||||
.TP
|
||||
\fBattachdisk\fR <compute id> <storage id>
|
||||
.IP
|
||||
attaches an storage to a given compute
|
||||
.TP
|
||||
\fBdetachdisk\fR <compute id> <disk id>
|
||||
.IP
|
||||
detaches the target disk form the compute
|
||||
.SH COPYRIGHT
|
||||
Copyright 2002\-2014, OpenNebula Project (OpenNebula.org), C12G Labs
|
||||
.PP
|
||||
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
|
@ -1,53 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||
.TH OPENNEBULA "1" "July 2014" "OpenNebula 4.7.80" "User Commands"
|
||||
.SH NAME
|
||||
OpenNebula \- OCCI Manage Instance
|
||||
.SH SYNOPSIS
|
||||
.B occi-instance-type
|
||||
\fI<COMMAND> \fR[\fIOPTIONS\fR]
|
||||
.SH DESCRIPTION
|
||||
occi\-instance\-type \- Retrieve instance types
|
||||
.SH OPTIONS
|
||||
|
||||
\fB\-\-help\fR, \fB\-h\fR
|
||||
.IP
|
||||
Show help
|
||||
.PP
|
||||
\fB\-\-username\fR <id>, \fB\-U\fR <id>
|
||||
.IP
|
||||
The username of the user
|
||||
.PP
|
||||
\fB\-\-password\fR <key>, \fB\-P\fR <key>
|
||||
.IP
|
||||
The password of the user
|
||||
.PP
|
||||
\fB\-\-url\fR <url>, \fB\-R\fR <url>
|
||||
.IP
|
||||
Set url as the web service url to use
|
||||
.PP
|
||||
\fB\-\-timeout\fR <seconds>, \fB\-T\fR <seconds>
|
||||
.IP
|
||||
Sets a timeout for the http connection
|
||||
.PP
|
||||
\fB\-\-debug\fR, \fB\-D\fR
|
||||
.IP
|
||||
Enables verbosity
|
||||
.PP
|
||||
\fB\-\-verbose\fR
|
||||
.IP
|
||||
Show resources in verbose mode
|
||||
.PP
|
||||
\fB\-\-plain\fR
|
||||
.IP
|
||||
The password provided will not be hashed
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
\fBlist\fR
|
||||
.IP
|
||||
lists available instance types
|
||||
.SH COPYRIGHT
|
||||
Copyright 2002\-2014, OpenNebula Project (OpenNebula.org), C12G Labs
|
||||
.PP
|
||||
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
|
@ -1,72 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||
.TH OPENNEBULA "1" "July 2014" "OpenNebula 4.7.80" "User Commands"
|
||||
.SH NAME
|
||||
OpenNebula \- OCCI Manage Network
|
||||
.SH SYNOPSIS
|
||||
.B occi-network
|
||||
\fI<COMMAND> \fR[\fIOPTIONS\fR] [\fIARGUMENTS\fR]
|
||||
.SH DESCRIPTION
|
||||
occi\-network \- Manages virtual networks
|
||||
.SH OPTIONS
|
||||
|
||||
\fB\-\-help\fR, \fB\-h\fR
|
||||
.IP
|
||||
Show help
|
||||
.PP
|
||||
\fB\-\-username\fR <id>, \fB\-U\fR <id>
|
||||
.IP
|
||||
The username of the user
|
||||
.PP
|
||||
\fB\-\-password\fR <key>, \fB\-P\fR <key>
|
||||
.IP
|
||||
The password of the user
|
||||
.PP
|
||||
\fB\-\-url\fR <url>, \fB\-R\fR <url>
|
||||
.IP
|
||||
Set url as the web service url to use
|
||||
.PP
|
||||
\fB\-\-timeout\fR <seconds>, \fB\-T\fR <seconds>
|
||||
.IP
|
||||
Sets a timeout for the http connection
|
||||
.PP
|
||||
\fB\-\-debug\fR, \fB\-D\fR
|
||||
.IP
|
||||
Enables verbosity
|
||||
.PP
|
||||
\fB\-\-verbose\fR
|
||||
.IP
|
||||
Show resources in verbose mode
|
||||
.PP
|
||||
\fB\-\-plain\fR
|
||||
.IP
|
||||
The password provided will not be hashed
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
\fBcreate\fR <occi xml file>
|
||||
.IP
|
||||
creates a new virtual network described by the provided
|
||||
<occi xml file>
|
||||
.TP
|
||||
\fBlist\fR
|
||||
.IP
|
||||
lists available virtual networks
|
||||
.TP
|
||||
\fBshow\fR <network id>
|
||||
.IP
|
||||
retrieves the OCCI XML representation of the virtual network
|
||||
identified by <network id>
|
||||
.TP
|
||||
\fBupdate\fR <occi xml file>
|
||||
.IP
|
||||
updates the representation of the network resource represented by the
|
||||
provided <occi xml file>
|
||||
.TP
|
||||
\fBdelete\fR <network id>
|
||||
.IP
|
||||
deletes the virtual network idenfitied by <network id>
|
||||
.SH COPYRIGHT
|
||||
Copyright 2002\-2014, OpenNebula Project (OpenNebula.org), C12G Labs
|
||||
.PP
|
||||
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
|
@ -1,81 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||
.TH OPENNEBULA "1" "July 2014" "OpenNebula 4.7.80" "User Commands"
|
||||
.SH NAME
|
||||
OpenNebula \- OCCI Manage Storage
|
||||
.SH SYNOPSIS
|
||||
.B occi-storage
|
||||
\fI<COMMAND> \fR[\fIOPTIONS\fR] [\fIPARAMETERS\fR]
|
||||
.SH DESCRIPTION
|
||||
occi\-storage \- Manages OCCI storage resource
|
||||
.SH OPTIONS
|
||||
|
||||
\fB\-\-help\fR, \fB\-h\fR
|
||||
.IP
|
||||
Show help
|
||||
.PP
|
||||
\fB\-\-username\fR <id>, \fB\-U\fR <id>
|
||||
.IP
|
||||
The username of the user
|
||||
.PP
|
||||
\fB\-\-password\fR <key>, \fB\-P\fR <key>
|
||||
.IP
|
||||
The password of the user
|
||||
.PP
|
||||
\fB\-\-url\fR <url>, \fB\-R\fR <url>
|
||||
.IP
|
||||
Set url as the web service url to use
|
||||
.PP
|
||||
\fB\-\-timeout\fR <seconds>, \fB\-T\fR <seconds>
|
||||
.IP
|
||||
Sets a timeout for the http connection
|
||||
.PP
|
||||
\fB\-\-debug\fR, \fB\-D\fR
|
||||
.IP
|
||||
Enables verbosity
|
||||
.PP
|
||||
\fB\-\-multipart\fR, \fB\-M\fR
|
||||
.IP
|
||||
Use 'multipart\-post' library instead of Curb/Curl
|
||||
.PP
|
||||
\fB\-\-verbose\fR
|
||||
.IP
|
||||
Show resources in verbose mode
|
||||
.PP
|
||||
\fB\-\-plain\fR
|
||||
.IP
|
||||
The password provided will not be hashed
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
\fBcreate\fR <occi xml file>
|
||||
.IP
|
||||
creates a new storage resource described by the provided
|
||||
<occi xml file>
|
||||
.TP
|
||||
\fBlist\fR
|
||||
.IP
|
||||
lists available storage resources
|
||||
.TP
|
||||
\fBshow\fR <storage id>
|
||||
.IP
|
||||
retrieves the OCCI XML representation of the storage resource
|
||||
identified by <storage id>
|
||||
.TP
|
||||
\fBupdate\fR <occi xml file>
|
||||
.IP
|
||||
updates the representation of the storage resource represented by the
|
||||
provided <occi xml file>
|
||||
.TP
|
||||
\fBdelete\fR <storage id>
|
||||
.IP
|
||||
deletes the storage resource idenfitied by <storage id>
|
||||
.TP
|
||||
\fBclone\fR <storage id> <name>
|
||||
.IP
|
||||
clones the storage resource idenfitied by <storage id> in a new one
|
||||
using the given <name>
|
||||
.SH COPYRIGHT
|
||||
Copyright 2002\-2014, OpenNebula Project (OpenNebula.org), C12G Labs
|
||||
.PP
|
||||
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
|
@ -1,97 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# /etc/rc.d/init.d/opennebula-occi
|
||||
#
|
||||
# Starts the OCCI Server
|
||||
#
|
||||
# chkconfig: 345 66 34
|
||||
# description: Starts the OpenNebula daemon
|
||||
# processname: opennebula-occi
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: opennebula-occi
|
||||
# Required-Start: $local_fs $remote_fs oned
|
||||
# Required-Stop: $local_fs $remote_fs oned
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: start and stop oned
|
||||
# Description: start and stop oned
|
||||
### END INIT INFO
|
||||
|
||||
prog="opennebula-occi"
|
||||
|
||||
OCCI_BIN=/usr/bin/occi-server
|
||||
LOCKFILE=/var/lock/subsys/${prog}
|
||||
PID_FILE=/var/run/${prog}.pid
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
|
||||
RETVAL=0
|
||||
|
||||
check() {
|
||||
# Check that we're a privileged user
|
||||
[ `id -u` = 0 ] || exit 4
|
||||
|
||||
# Check if occid is executable
|
||||
test -x $OCCI_BIN || exit 5
|
||||
}
|
||||
|
||||
start() {
|
||||
check
|
||||
|
||||
echo -n $"Starting OCCI Server: "
|
||||
daemon --user oneadmin $OCCI_BIN start
|
||||
RETVAL=$?
|
||||
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && {
|
||||
touch $LOCKFILE
|
||||
echo $(ps -ef|grep occi-server.rb | awk '{print $2}') > $PID_FILE
|
||||
}
|
||||
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
check
|
||||
|
||||
echo -n $"Stopping OCCI Server daemon: "
|
||||
daemon --user oneadmin $OCCI_BIN stop
|
||||
RETVAL=$?
|
||||
|
||||
[ $RETVAL -eq 0 ] && success || failure
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE $PID_FILE
|
||||
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
status)
|
||||
status $prog
|
||||
RETVAL=$?
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart}"
|
||||
RETVAL=2
|
||||
esac
|
||||
|
||||
exit $RETVAL
|
@ -1,106 +0,0 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: opennebula-occi
|
||||
# Required-Start: $remote_fs
|
||||
# Required-Stop: $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: OCCI Server init script
|
||||
# Description: OpenNebula OCCI service initialisation script
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Tino Vázquez <tinova@opennebula.org>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="OCCI Service"
|
||||
NAME=occi-server
|
||||
DAEMON=/usr/bin/$NAME
|
||||
DAEMON_ARGS=""
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
PID_FILE=/var/run/one/occi-server.pid
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
|
||||
# Load the VERBOSE setting and other rcS variables
|
||||
. /lib/init/vars.sh
|
||||
|
||||
# Define LSB log_* functions.
|
||||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
#
|
||||
do_start()
|
||||
{
|
||||
mkdir -p /var/run/one /var/lock/one /var/log/one
|
||||
chown oneadmin /var/run/one /var/lock/one /var/log/one
|
||||
su oneadmin -s /bin/sh -c "$DAEMON start"
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
do_stop()
|
||||
{
|
||||
su oneadmin -s /bin/sh -c "$DAEMON stop"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
||||
do_start
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
OCCI_PID=`cat $PID_FILE`
|
||||
kill -0 $OCCI_PID > /dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
log_daemon_msg "$NAME is running"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_daemon_msg "$NAME is not running"
|
||||
log_end_msg 1
|
||||
fi
|
||||
;;
|
||||
restart|force-reload)
|
||||
#
|
||||
# If the "reload" option is implemented then remove the
|
||||
# 'force-reload' alias
|
||||
#
|
||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1)
|
||||
do_start
|
||||
case "$?" in
|
||||
0) log_end_msg 0 ;;
|
||||
1) log_end_msg 1 ;; # Old process is still running
|
||||
*) log_end_msg 1 ;; # Failed to start
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# Failed to stop
|
||||
log_end_msg 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
:
|
@ -1,106 +0,0 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: opennebula-occi
|
||||
# Required-Start: $remote_fs
|
||||
# Required-Stop: $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: OCCI Server init script
|
||||
# Description: OpenNebula OCCI service initialisation script
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Tino Vázquez <tinova@opennebula.org>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="OCCI Service"
|
||||
NAME=occi-server
|
||||
DAEMON=/usr/bin/$NAME
|
||||
DAEMON_ARGS=""
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
PID_FILE=/var/run/one/occi-server.pid
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
|
||||
# Load the VERBOSE setting and other rcS variables
|
||||
. /lib/init/vars.sh
|
||||
|
||||
# Define LSB log_* functions.
|
||||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
#
|
||||
do_start()
|
||||
{
|
||||
mkdir -p /var/run/one /var/lock/one /var/log/one
|
||||
chown oneadmin /var/run/one /var/lock/one /var/log/one
|
||||
su oneadmin -s /bin/sh -c "$DAEMON start"
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
do_stop()
|
||||
{
|
||||
su oneadmin -s /bin/sh -c "$DAEMON stop"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
||||
do_start
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
OCCI_PID=`cat $PID_FILE`
|
||||
kill -0 $OCCI_PID > /dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
log_daemon_msg "$NAME is running"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_daemon_msg "$NAME is not running"
|
||||
log_end_msg 1
|
||||
fi
|
||||
;;
|
||||
restart|force-reload)
|
||||
#
|
||||
# If the "reload" option is implemented then remove the
|
||||
# 'force-reload' alias
|
||||
#
|
||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1)
|
||||
do_start
|
||||
case "$?" in
|
||||
0) log_end_msg 0 ;;
|
||||
1) log_end_msg 1 ;; # Old process is still running
|
||||
*) log_end_msg 1 ;; # Failed to start
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# Failed to stop
|
||||
log_end_msg 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
:
|
@ -1,20 +0,0 @@
|
||||
[Unit]
|
||||
Description=OpenNebula OCCI Interface Service
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
After=one.service
|
||||
After=one_scheduler.service
|
||||
BindTo=one.service
|
||||
!ConditionFileExists=/var/lock/one/.occiserver.lock
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c "/usr/bin/occi-server start"
|
||||
ExecStartPost=/usr/bin/touch /var/lock/one/.occiserver.lock
|
||||
ExecStop=/bin/kill -INT $MAINPID
|
||||
PIDFile=/var/run/one/occiserver.pid
|
||||
Type=simple
|
||||
Group=cloud
|
||||
User=oneadmin
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,33 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OCCICloudAuth
|
||||
def do_auth(env, params={})
|
||||
auth = Rack::Auth::Basic::Request.new(env)
|
||||
|
||||
if auth.provided? && auth.basic?
|
||||
username, password = auth.credentials
|
||||
|
||||
one_pass = get_password(username, 'core|public')
|
||||
|
||||
if one_pass && one_pass == password
|
||||
return username
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
end
|
@ -1,249 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
occi-compute - Manages compute resources
|
||||
|
||||
Usage:
|
||||
occi-compute <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
|
||||
Commands:
|
||||
|
||||
* create <occi xml file>
|
||||
creates a new compute resource described by the provided
|
||||
<occi xml file>
|
||||
|
||||
* list
|
||||
lists available compute resources
|
||||
|
||||
* show <compute id>
|
||||
retrieves the OCCI XML representation of the compute resource
|
||||
identified by <compute id>
|
||||
|
||||
* update <occi xml file>
|
||||
updates the representation of the compute resource represented by the
|
||||
provided <occi xml file>
|
||||
|
||||
* delete <compute id>
|
||||
deletes the compute resource idenfitied by <compute id>
|
||||
|
||||
* attachdisk <compute id> <storage id>
|
||||
attaches an storage to a given compute
|
||||
|
||||
* detachdisk <compute id> <disk id>
|
||||
detaches the target disk form the compute
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--verbose
|
||||
Show resources in verbose mode
|
||||
|
||||
EOT
|
||||
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--verbose', GetoptLong::NO_ARGUMENT],
|
||||
['--plain', GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
verbose = false
|
||||
plain = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
when '--verbose'
|
||||
verbose = true
|
||||
when '--plain'
|
||||
plain = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password, timeout, debug, plain)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
case ARGV[0].downcase
|
||||
when 'list'
|
||||
rc = occi_client.get_vms(verbose)
|
||||
|
||||
when 'create'
|
||||
vm_xml = ARGV[1]
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{cmd_name} create: missing OCCI-XML or file not found"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.post_vms(vm_xml)
|
||||
|
||||
when 'show'
|
||||
vm_id = ARGV[1]
|
||||
|
||||
if !vm_id
|
||||
puts "#{cmd_name} show: missing VM-ID parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.get_vm(vm_id)
|
||||
|
||||
when 'update'
|
||||
vm_xml = ARGV[1]
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{cmd_name} update: missing OCCI-XML or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = occi_client.put_vm(vm_xml)
|
||||
|
||||
when 'delete'
|
||||
vm_id = ARGV[1]
|
||||
|
||||
if !vm_id
|
||||
puts "#{cmd_name} delete: missing VM-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = occi_client.delete_vm(vm_id)
|
||||
|
||||
when 'attachdisk'
|
||||
vm_id = ARGV[1]
|
||||
image_id = ARGV[2]
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name} show: missing storage id parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
xml = "<ACTION>"
|
||||
xml << " <PERFORM>ATTACHDISK</PERFORM>"
|
||||
xml << " <PARAMS>"
|
||||
xml << " <STORAGE href=\"#{url}/storage/#{image_id.to_s}\"/>"
|
||||
xml << " </PARAMS>"
|
||||
xml << "</ACTION>"
|
||||
|
||||
rc = occi_client.action_vm(vm_id, xml)
|
||||
|
||||
when 'detachdisk'
|
||||
vm_id = ARGV[1]
|
||||
disk_id = ARGV[2]
|
||||
|
||||
if !disk_id
|
||||
puts "#{cmd_name} show: missing disk id parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
xml = "<ACTION>"
|
||||
xml << " <PERFORM>DETACHDISK</PERFORM>"
|
||||
xml << " <PARAMS>"
|
||||
xml << " <DISK id=\"#{disk_id}\"/>"
|
||||
xml << " </PARAMS>"
|
||||
xml << "</ACTION>"
|
||||
|
||||
rc = occi_client.action_vm(vm_id, xml)
|
||||
|
||||
else
|
||||
puts "Command #{ARGV[0]} not valid."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts rc.to_s()
|
||||
exit(-1)
|
||||
else
|
||||
str, code = print_xml(rc)
|
||||
puts str
|
||||
exit(code)
|
||||
end
|
||||
|
@ -1,154 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
occi-instance-type - Retrieve instance types
|
||||
|
||||
Usage:
|
||||
occi-instance-type <COMMAND> [OPTIONS]
|
||||
|
||||
Commands:
|
||||
|
||||
* list
|
||||
lists available instance types
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--verbose
|
||||
Show resources in verbose mode
|
||||
|
||||
--plain
|
||||
The password provided will not be hashed
|
||||
|
||||
EOT
|
||||
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--verbose', GetoptLong::NO_ARGUMENT],
|
||||
['--plain', GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
verbose = false
|
||||
plain = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
when '--verbose'
|
||||
verbose = true
|
||||
when '--plain'
|
||||
plain = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password, timeout, debug,plain)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
case ARGV[0].downcase
|
||||
when 'list'
|
||||
rc = occi_client.get_instance_types(verbose)
|
||||
else
|
||||
puts "Command #{ARGV[0]} not valid."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts rc.to_s()
|
||||
exit(-1)
|
||||
else
|
||||
str, code = print_xml(rc)
|
||||
puts str
|
||||
exit(code)
|
||||
end
|
||||
|
@ -1,212 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
occi-network - Manages virtual networks
|
||||
|
||||
Usage:
|
||||
occi-network <COMMAND> [OPTIONS] [ARGUMENTS]
|
||||
|
||||
Commands:
|
||||
|
||||
* create <occi xml file>
|
||||
creates a new virtual network described by the provided
|
||||
<occi xml file>
|
||||
|
||||
* list
|
||||
lists available virtual networks
|
||||
|
||||
* show <network id>
|
||||
retrieves the OCCI XML representation of the virtual network
|
||||
identified by <network id>
|
||||
|
||||
* update <occi xml file>
|
||||
updates the representation of the network resource represented by the
|
||||
provided <occi xml file>
|
||||
|
||||
* delete <network id>
|
||||
deletes the virtual network idenfitied by <network id>
|
||||
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--verbose
|
||||
Show resources in verbose mode
|
||||
|
||||
--plain
|
||||
The password provided will not be hashed
|
||||
|
||||
EOT
|
||||
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--verbose', GetoptLong::NO_ARGUMENT],
|
||||
['--plain', GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
verbose = false
|
||||
plain = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
when '--verbose'
|
||||
verbose = true
|
||||
when '--plain'
|
||||
plain = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,timeout,debug,plain)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
|
||||
case ARGV[0].downcase
|
||||
when 'create'
|
||||
network_xml = ARGV[1]
|
||||
|
||||
if !network_xml || !File.exists?(network_xml)
|
||||
puts "#{cmd_name} create: missing OCCI-XML or file not found"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.post_network(network_xml)
|
||||
|
||||
when 'list'
|
||||
rc = occi_client.get_networks(verbose)
|
||||
|
||||
when 'show'
|
||||
network_id = ARGV[1]
|
||||
|
||||
if !network_id
|
||||
puts "#{cmd_name} show: missing NETWORK-ID or file not found"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.get_network(network_id)
|
||||
|
||||
when 'update'
|
||||
network_xml = ARGV[1]
|
||||
|
||||
if !network_xml || !File.exists?(network_xml)
|
||||
puts "#{cmd_name} update: missing OCCI-XML or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = occi_client.put_network(network_xml)
|
||||
|
||||
when 'delete'
|
||||
network_id = ARGV[1]
|
||||
|
||||
if !network_id
|
||||
puts "#{cmd_name} delete: missing NETWORK-ID parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.delete_network(network_id)
|
||||
|
||||
else
|
||||
puts "Command #{ARGV[0]} not valid."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts rc.to_s()
|
||||
exit(-1)
|
||||
else
|
||||
str, code = print_xml(rc)
|
||||
puts str
|
||||
exit(code)
|
||||
end
|
@ -1,134 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
if [ -z "$ONE_LOCATION" ]; then
|
||||
OCCI_PID=/var/run/one/occi-server.pid
|
||||
OCCI_SERVER=/usr/lib/one/ruby/cloud/occi/occi-server.rb
|
||||
OCCI_LOCK_FILE=/var/lock/one/.occi.lock
|
||||
OCCI_LOG=/var/log/one/occi-server.log
|
||||
OCCI_LOG_ERROR=/var/log/one/occi-server.error
|
||||
OCCI_ETC=/etc/one/occi-server.conf
|
||||
else
|
||||
OCCI_PID=$ONE_LOCATION/var/occi-server.pid
|
||||
OCCI_SERVER=$ONE_LOCATION/lib/ruby/cloud/occi/occi-server.rb
|
||||
OCCI_LOCK_FILE=$ONE_LOCATION/var/.occi.lock
|
||||
OCCI_LOG=$ONE_LOCATION/var/occi-server.log
|
||||
OCCI_LOG_ERROR=$ONE_LOCATION/var/occi-server.error
|
||||
OCCI_ETC=$ONE_LOCATION/etc/occi-server.conf
|
||||
fi
|
||||
|
||||
setup()
|
||||
{
|
||||
TMPDIR=$(grep ^:tmpdir: $OCCI_ETC|awk '{print $2}')
|
||||
|
||||
if [ -n "$TMPDIR" ]; then
|
||||
export TMPDIR
|
||||
mkdir -p $TMPDIR
|
||||
fi
|
||||
|
||||
if [ -f $OCCI_LOCK_FILE ]; then
|
||||
if [ -f $OCCI_PID ]; then
|
||||
OCCIPID=`cat $OCCI_PID`
|
||||
ps $OCCIPID > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "OCCI Server is still running (PID:$OCCIPID). Please try 'occi-server stop' first."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "Stale .lock detected. Erasing it."
|
||||
rm $OCCI_LOCK_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
if [ ! -f "$OCCI_SERVER" ]; then
|
||||
echo "Cannot find $OCCI_SERVER."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch $OCCI_LOCK_FILE
|
||||
|
||||
# Start the occi-server daemon
|
||||
ruby $OCCI_SERVER >$OCCI_LOG 2>$OCCI_LOG_ERROR &
|
||||
|
||||
LASTRC=$?
|
||||
LASTPID=$!
|
||||
|
||||
if [ $LASTRC -ne 0 ]; then
|
||||
echo "Error executing occi-server."
|
||||
echo "Check $OCCI_LOG_ERROR and $OCCI_LOG for more information"
|
||||
exit 1
|
||||
else
|
||||
echo $LASTPID > $OCCI_PID
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
ps $LASTPID > /dev/null 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error executing occi-server."
|
||||
echo "Check $OCCI_LOG_ERROR and $OCCI_LOG for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "occi-server started"
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
stop()
|
||||
{
|
||||
if [ ! -f $OCCI_PID ]; then
|
||||
echo "Couldn't find occi-server process pid."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Kill the occi-server daemon. Thin seems to require this twice
|
||||
PID=`cat $OCCI_PID`
|
||||
|
||||
kill -INT $PID > /dev/null 2>&1
|
||||
|
||||
# Remove pid files
|
||||
rm -f $OCCI_PID > /dev/null 2>&1
|
||||
|
||||
echo "occi-server stopped"
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
setup
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
setup
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: occi-server {start|stop|restart}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
|
@ -1,246 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
TEMPLATES_LOCATION=ONE_LOCATION+"/etc/occi_templates"
|
||||
CONF_LOCATION=ONE_LOCATION+"/etc"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
occi-storage - Manages OCCI storage resource
|
||||
|
||||
Usage:
|
||||
occi-storage <COMMAND> [OPTIONS] [PARAMETERS]
|
||||
|
||||
Commands:
|
||||
|
||||
* create <occi xml file>
|
||||
creates a new storage resource described by the provided
|
||||
<occi xml file>
|
||||
|
||||
* list
|
||||
lists available storage resources
|
||||
|
||||
* show <storage id>
|
||||
retrieves the OCCI XML representation of the storage resource
|
||||
identified by <storage id>
|
||||
|
||||
|
||||
* update <occi xml file>
|
||||
updates the representation of the storage resource represented by the
|
||||
provided <occi xml file>
|
||||
|
||||
* delete <storage id>
|
||||
deletes the storage resource idenfitied by <storage id>
|
||||
|
||||
* clone <storage id> <name>
|
||||
clones the storage resource idenfitied by <storage id> in a new one
|
||||
using the given <name>
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
Sets a timeout for the http connection
|
||||
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--multipart, -M
|
||||
Use 'multipart-post' library instead of Curb/Curl
|
||||
|
||||
--verbose
|
||||
Show resources in verbose mode
|
||||
|
||||
--plain
|
||||
The password provided will not be hashed
|
||||
|
||||
EOT
|
||||
|
||||
require 'occi/OCCIClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--multipart', '-M',GetoptLong::NO_ARGUMENT],
|
||||
['--verbose', GetoptLong::NO_ARGUMENT],
|
||||
['--plain', GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
username = nil
|
||||
password = nil
|
||||
auth = nil
|
||||
timeout = nil
|
||||
debug = false
|
||||
curb = true
|
||||
verbose = false
|
||||
plain = false
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--username'
|
||||
username = arg
|
||||
when '--password'
|
||||
password = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--timeout'
|
||||
timeout = arg
|
||||
when '--debug'
|
||||
debug = true
|
||||
when '--multipart'
|
||||
curb = false
|
||||
when '--verbose'
|
||||
verbose = true
|
||||
when '--plain'
|
||||
plain = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,timeout,debug,plain)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
case ARGV[0].downcase
|
||||
when 'create'
|
||||
image_xml = ARGV[1]
|
||||
|
||||
if !image_xml || !File.exists?(image_xml)
|
||||
puts "#{cmd_name} create: missing occi xml or file not found"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.post_image(image_xml, curb)
|
||||
|
||||
when 'list'
|
||||
rc = occi_client.get_images(verbose)
|
||||
|
||||
when 'show'
|
||||
image_id = ARGV[1]
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name} show: missing storage id parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.get_image(image_id)
|
||||
|
||||
when 'update'
|
||||
image_xml = ARGV[1]
|
||||
|
||||
if !image_xml || !File.exists?(image_xml)
|
||||
puts "#{cmd_name} update: missing OCCI-XML or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = occi_client.put_image(image_xml)
|
||||
|
||||
when 'delete'
|
||||
image_id = ARGV[1]
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name} show: missing storage id parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
rc = occi_client.delete_image(image_id)
|
||||
|
||||
when 'clone'
|
||||
image_id = ARGV[1]
|
||||
name = ARGV[2]
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name} clone: missing storage id parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if !name
|
||||
puts "#{cmd_name} clone: missing name parameter"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
xml = "<ACTION>"
|
||||
xml << " <PERFORM>CLONE</PERFORM>"
|
||||
xml << " <PARAMS>"
|
||||
xml << " <NAME>#{name}</NAME>"
|
||||
xml << " </PARAMS>"
|
||||
xml << "</ACTION>"
|
||||
|
||||
rc = occi_client.action_image(image_id, xml)
|
||||
else
|
||||
puts "Command #{ARGV[0]} not valid."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts rc.to_s()
|
||||
exit(-1)
|
||||
else
|
||||
str, code = print_xml(rc)
|
||||
puts str
|
||||
exit(code)
|
||||
end
|
@ -1,81 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#############################################################
|
||||
# Server configuration
|
||||
#############################################################
|
||||
|
||||
# Directory to store temp files when uploading images
|
||||
:tmpdir: /var/tmp
|
||||
|
||||
# OpenNebula sever contact information
|
||||
:one_xmlrpc: http://localhost:2633/RPC2
|
||||
|
||||
# Host and port where OCCI server will run
|
||||
:host: 127.0.0.1
|
||||
:port: 4567
|
||||
|
||||
# SSL proxy that serves the API (set if is being used)
|
||||
#:ssl_server: fqdm.of.the.server
|
||||
|
||||
#############################################################
|
||||
# Auth
|
||||
#############################################################
|
||||
|
||||
# Authentication driver for incomming requests
|
||||
# occi, for OpenNebula's user-password scheme
|
||||
# x509, for x509 certificates based authentication
|
||||
# opennebula, use the driver defined for the user in OpenNebula
|
||||
:auth: occi
|
||||
|
||||
# Authentication driver to communicate with OpenNebula core
|
||||
# cipher, for symmetric cipher encryption of tokens
|
||||
# x509, for x509 certificate encryption of tokens
|
||||
:core_auth: cipher
|
||||
|
||||
#############################################################
|
||||
# Log
|
||||
#############################################################
|
||||
|
||||
# Log debug level
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
:debug_level: 3
|
||||
|
||||
#############################################################
|
||||
# Resources
|
||||
#############################################################
|
||||
|
||||
# Cluster associated with the OCCI resources, by default no Cluster is defined
|
||||
#:cluster_id:
|
||||
|
||||
# Datastore in which the Images uploaded through OCCI will be allocated, by default 1
|
||||
#:datastore_id:
|
||||
|
||||
# VM types allowed and its template file (inside templates directory)
|
||||
:instance_types:
|
||||
:small:
|
||||
:template: small.erb
|
||||
:cpu: 1
|
||||
:memory: 1024
|
||||
:medium:
|
||||
:template: medium.erb
|
||||
:cpu: 4
|
||||
:memory: 4096
|
||||
:large:
|
||||
:template: large.erb
|
||||
:cpu: 8
|
||||
:memory: 8192
|
||||
|
@ -1,44 +0,0 @@
|
||||
#
|
||||
# This template is processed by the OCCI Server to include specific data for the
|
||||
# instance, you should not need to modify the ruby code.
|
||||
# You can add common attributes for your cloud templates (e.g. OS)
|
||||
#
|
||||
|
||||
<% if @vm_info['NAME'] %>
|
||||
NAME = "<%= @vm_info['NAME'] %>"
|
||||
<% end %>
|
||||
|
||||
<% @vm_info.each('DISK') do |disk| %>
|
||||
<% if disk.attr('STORAGE','href') %>
|
||||
DISK = [ IMAGE_ID = <%= disk.attr('STORAGE','href').split('/').last %>
|
||||
]
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% @vm_info.each('NIC') do |nic| %>
|
||||
<% if nic.attr('NETWORK','href') %>
|
||||
NIC = [ NETWORK_ID = <%= nic.attr('NETWORK','href').split('/').last %>
|
||||
<% if nic['IP'] %>
|
||||
,IP = <%= nic['IP'] %>
|
||||
<% end %>
|
||||
]
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @vm_info.has_elements?('CONTEXT') %>
|
||||
CONTEXT = [
|
||||
<% first = true %>
|
||||
<% @vm_info.each('CONTEXT/*') do |cont| %>
|
||||
<% if cont.text %>
|
||||
<% if first %>
|
||||
<%= cont.name %> = "<%= cont.text %>"
|
||||
<% first = false %>
|
||||
<% else %>
|
||||
,<%= cont.name %> = "<%= cont.text %>"
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
]
|
||||
<% end %>
|
||||
|
||||
INSTANCE_TYPE = <%= @itype %>
|
@ -1,14 +0,0 @@
|
||||
#
|
||||
# Virtual Machine Template generated for custom instance types.
|
||||
# The CPU and MEMORY parameters will be specified in the body of the request.
|
||||
# You can also add specific attributes for your cloud in this file (e.g. OS).
|
||||
#
|
||||
|
||||
# Default values for VM capacity
|
||||
<%
|
||||
DEFAULT_CPU = 1
|
||||
DEFAULT_MEMORY = 128
|
||||
%>
|
||||
|
||||
CPU = "<%= @vm_info['CPU'].nil? ? DEFAULT_CPU : @vm_info['CPU'] %>"
|
||||
MEMORY = "<%= @vm_info['MEMORY'].nil? ? DEFAULT_MEMORY : @vm_info['MEMORY'] %>"
|
@ -1,8 +0,0 @@
|
||||
#
|
||||
# Virtual Machine Template generated for large instance types. Adjust this
|
||||
# by setting the desired capacity (CPU,MEMORY) or adding specific
|
||||
# attributes for your cloud (e.g. OS).
|
||||
#
|
||||
|
||||
CPU = 8
|
||||
MEMORY = 8192
|
@ -1,9 +0,0 @@
|
||||
#
|
||||
# Virtual Machine Template generated for medium instance types. Adjust this
|
||||
# by setting the desired capacity (CPU,MEMORY) or adding specific
|
||||
# attributes for your cloud (e.g. OS).
|
||||
#
|
||||
|
||||
CPU = 4
|
||||
MEMORY = 4096
|
||||
|
@ -1,25 +0,0 @@
|
||||
#
|
||||
# This template is processed by the OCCI Server to include specific data for
|
||||
# the VNET, you should not need to modify the ruby code.
|
||||
# You can add common attributes for your VNET templates (e.g. VLAN, PHYDEV)
|
||||
#
|
||||
|
||||
NAME = "<%= @vnet_info['NAME'] %>"
|
||||
TYPE = RANGED
|
||||
|
||||
NETWORK_ADDRESS = <%= @vnet_info['ADDRESS'] %>
|
||||
<% if @vnet_info['SIZE'] != nil %>
|
||||
NETWORK_SIZE = <%= @vnet_info['SIZE']%>
|
||||
<% end %>
|
||||
|
||||
<% if @vnet_info['DESCRIPTION'] != nil %>
|
||||
DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>"
|
||||
<% end %>
|
||||
|
||||
<% if @vnet_info['PUBLIC'] != nil %>
|
||||
PUBLIC = "<%= @vnet_info['PUBLIC'] %>"
|
||||
<% end %>
|
||||
|
||||
#BRIDGE = NAME_OF_DEFAULT_BRIDGE
|
||||
#PHYDEV = NAME_OF_PHYSICAL_DEVICE
|
||||
#VLAN = YES|NO
|
@ -1,9 +0,0 @@
|
||||
#
|
||||
# Virtual Machine Template generated for small instance types. Adjust this
|
||||
# by setting the desired capacity (CPU,MEMORY) or adding specific
|
||||
# attributes for your cloud (e.g. OS).
|
||||
#
|
||||
|
||||
CPU = 1
|
||||
MEMORY = 1024
|
||||
|
@ -1,115 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class ImageOCCI < Image
|
||||
OCCI_IMAGE = %q{
|
||||
<STORAGE href="<%= base_url %>/storage/<%= self.id.to_s %>">
|
||||
<ID><%= self.id.to_s %></ID>
|
||||
<NAME><%= self.name %></NAME>
|
||||
<USER href="<%= base_url %>/user/<%= self['UID'] %>" name="<%= self['UNAME'] %>"/>
|
||||
<GROUP><%= self['GNAME'] %></GROUP>
|
||||
<STATE><%= self.state_str %></STATE>
|
||||
<% if self['TYPE'] != nil %>
|
||||
<TYPE><%= self.type_str %></TYPE>
|
||||
<% end %>
|
||||
<% if self['TEMPLATE/DESCRIPTION'] != nil %>
|
||||
<DESCRIPTION><%= self['TEMPLATE/DESCRIPTION'] %></DESCRIPTION>
|
||||
<% end %>
|
||||
<SIZE><%= self['SIZE'] %></SIZE>
|
||||
<% if self['FSTYPE'] != nil and !self['FSTYPE'].empty? %>
|
||||
<FSTYPE><%= self['FSTYPE'] %></FSTYPE>
|
||||
<% end %>
|
||||
<PUBLIC><%= self.public? ? "YES" : "NO" %></PUBLIC>
|
||||
<PERSISTENT><%= self['PERSISTENT'] == "0" ? "NO" : "YES"%></PERSISTENT>
|
||||
</STORAGE>
|
||||
}
|
||||
|
||||
|
||||
ONE_IMAGE = %q{
|
||||
NAME = "<%= @image_info['NAME'] %>"
|
||||
<% if @image_info['DESCRIPTION'] != nil %>
|
||||
DESCRIPTION = "<%= @image_info['DESCRIPTION'] %>"
|
||||
<% end %>
|
||||
<% if @image_file != nil %>
|
||||
PATH = "<%= @image_file %>"
|
||||
<% end %>
|
||||
<% if @image_info['PUBLIC'] != nil %>
|
||||
PUBLIC = "<%= @image_info['PUBLIC'] %>"
|
||||
<% end %>
|
||||
<% if @image_info['PERSISTENT'] != nil %>
|
||||
PERSISTENT = "<%= @image_info['PERSISTENT'] %>"
|
||||
<% end %>
|
||||
<% if @image_info['TYPE'] != nil %>
|
||||
TYPE = <%= @image_info['TYPE'] %>
|
||||
<% end %>
|
||||
<% if @image_info['FSTYPE'] != nil %>
|
||||
FSTYPE = <%= @image_info['FSTYPE'] %>
|
||||
<% end %>
|
||||
<% if @image_info['SIZE'] != nil %>
|
||||
SIZE = <%= @image_info['SIZE'] %>
|
||||
<% end %>
|
||||
}.gsub(/^ /, '')
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client, xml_info=nil, file=nil)
|
||||
super(xml, client)
|
||||
@image_info = nil
|
||||
@image_file = file
|
||||
|
||||
if file && file[:tempfile]
|
||||
@image_file = file[:tempfile].path
|
||||
end
|
||||
|
||||
if xml_info != nil
|
||||
xmldoc = XMLElement.build_xml(xml_info, 'STORAGE')
|
||||
@image_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the OCCI representation of an Image
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi_im = ERB.new(OCCI_IMAGE)
|
||||
occi_im_text = occi_im.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_im_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def to_one_template
|
||||
if @image_info == nil
|
||||
error_msg = "Missing STORAGE section in the XML body"
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error
|
||||
end
|
||||
|
||||
if @image_info['NAME'] == nil
|
||||
error_msg = "Missing Image NAME in the XML DISK section"
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error
|
||||
end
|
||||
|
||||
one = ERB.new(ONE_IMAGE)
|
||||
return one.result(binding)
|
||||
end
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'ImageOCCI'
|
||||
|
||||
class ImagePoolOCCI < ImagePool
|
||||
OCCI_IMAGE_POOL = %q{
|
||||
<STORAGE_COLLECTION>
|
||||
<% self.each{ |im| %>
|
||||
<% if verbose %>
|
||||
<%= im.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<STORAGE href="<%= base_url %>/storage/<%= im.id.to_s %>" name="<%= im.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</STORAGE_COLLECTION>
|
||||
}
|
||||
|
||||
# Creates the OCCI representation of a Virtual Machine Pool
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi = ERB.new(OCCI_IMAGE_POOL)
|
||||
occi_text = occi.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
ImageOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
||||
|
@ -1,359 +0,0 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'rubygems'
|
||||
require 'rexml/document'
|
||||
require 'uri'
|
||||
|
||||
require 'CloudClient'
|
||||
|
||||
|
||||
module OCCIClient
|
||||
|
||||
#####################################################################
|
||||
# Client Library to interface with the OpenNebula OCCI Service
|
||||
#####################################################################
|
||||
class Client
|
||||
|
||||
attr_accessor :endpoint
|
||||
|
||||
######################################################################
|
||||
# Initialize client library
|
||||
######################################################################
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil,
|
||||
timeout=nil, debug_flag=true, plain=false)
|
||||
@debug = debug_flag
|
||||
@timeout = timeout
|
||||
|
||||
# Server location
|
||||
if endpoint_str
|
||||
@endpoint = endpoint_str
|
||||
elsif ENV["OCCI_URL"]
|
||||
@endpoint = ENV["OCCI_URL"]
|
||||
else
|
||||
@endpoint = "http://localhost:4567"
|
||||
end
|
||||
|
||||
# Autentication
|
||||
if user && pass
|
||||
@occiauth = [user, pass]
|
||||
else
|
||||
@occiauth = CloudClient::get_one_auth
|
||||
end
|
||||
|
||||
if !@occiauth
|
||||
raise "No authorization data present"
|
||||
end
|
||||
|
||||
@occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1]) unless plain
|
||||
end
|
||||
|
||||
#################################
|
||||
# Pool Resource Request Methods #
|
||||
#################################
|
||||
|
||||
def get_root
|
||||
get('/')
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Retieves the available Instance types
|
||||
######################################################################
|
||||
def get_instance_types(verbose=false)
|
||||
get('/instance_type', verbose)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Post a new VM to the VM Pool
|
||||
# :xmlfile
|
||||
######################################################################
|
||||
def post_vms(xmlfile)
|
||||
post('/compute', xmlfile)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Retieves the pool of Virtual Machines
|
||||
######################################################################
|
||||
def get_vms(verbose=false)
|
||||
get('/compute', verbose)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Post a new Network to the VN Pool
|
||||
# :xmlfile xml description of the Virtual Network
|
||||
######################################################################
|
||||
def post_network(xmlfile)
|
||||
post('/network', xmlfile)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Retieves the pool of Virtual Networks
|
||||
######################################################################
|
||||
def get_networks(verbose=false)
|
||||
get('/network', verbose)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Post a new Image to the Image Pool
|
||||
# :xmlfile
|
||||
######################################################################
|
||||
def post_image(xmlfile, curb=true)
|
||||
xml = File.read(xmlfile)
|
||||
|
||||
begin
|
||||
image_info = REXML::Document.new(xml).root
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
if image_info.elements['URL']
|
||||
file_path = image_info.elements['URL'].text
|
||||
|
||||
m = file_path.match(/^\w+:\/\/(.*)$/)
|
||||
|
||||
if m
|
||||
file_path="/"+m[1]
|
||||
end
|
||||
elsif !image_info.elements['TYPE'] == "DATABLOCK"
|
||||
return CloudClient::Error.new("Cannot find URL")
|
||||
end
|
||||
|
||||
if curb
|
||||
if !CURL_LOADED
|
||||
error_msg = "curb gem not loaded"
|
||||
error = CloudClient::Error.new(error_msg)
|
||||
return error
|
||||
end
|
||||
|
||||
curl=Curl::Easy.new(@endpoint+"/storage")
|
||||
|
||||
curl.http_auth_types = Curl::CURLAUTH_BASIC
|
||||
curl.userpwd = "#{@occiauth[0]}:#{@occiauth[1]}"
|
||||
curl.verbose = true if @debug
|
||||
curl.multipart_form_post = true
|
||||
|
||||
begin
|
||||
postfields = Array.new
|
||||
postfields << Curl::PostField.content('occixml', xml)
|
||||
|
||||
if file_path
|
||||
postfields << Curl::PostField.file('file', file_path)
|
||||
end
|
||||
|
||||
curl.http_post(*postfields)
|
||||
rescue Exception => e
|
||||
return CloudClient::Error.new(e.message)
|
||||
end
|
||||
|
||||
return curl.body_str
|
||||
else
|
||||
if !MULTIPART_LOADED
|
||||
error_msg = "multipart-post gem not loaded"
|
||||
error = CloudClient::Error.new(error_msg)
|
||||
return error
|
||||
end
|
||||
|
||||
params=Hash.new
|
||||
|
||||
if file_path
|
||||
file=File.open(file_path)
|
||||
params["file"]=UploadIO.new(file,
|
||||
'application/octet-stream', file_path)
|
||||
end
|
||||
|
||||
params['occixml'] = xml
|
||||
|
||||
url = URI.parse(@endpoint+"/storage")
|
||||
|
||||
req = Net::HTTP::Post::Multipart.new(url.path, params)
|
||||
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
file.close if file_path
|
||||
|
||||
if CloudClient::is_error?(res)
|
||||
return res
|
||||
else
|
||||
return res.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Retieves the pool of Images owned by the user
|
||||
######################################################################
|
||||
def get_images(verbose=false)
|
||||
get('/storage', verbose)
|
||||
end
|
||||
|
||||
|
||||
####################################
|
||||
# Entity Resource Request Methods #
|
||||
####################################
|
||||
|
||||
######################################################################
|
||||
# :id VM identifier
|
||||
######################################################################
|
||||
def get_vm(id)
|
||||
get('/compute/'+id.to_s)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Puts a new Compute representation in order to change its state
|
||||
# :xmlfile Compute OCCI xml representation
|
||||
######################################################################
|
||||
def put_vm(xmlfile)
|
||||
put('/compute/', xmlfile)
|
||||
end
|
||||
|
||||
####################################################################
|
||||
# :id Compute identifier
|
||||
####################################################################
|
||||
def delete_vm(id)
|
||||
delete('/compute/'+id.to_s)
|
||||
end
|
||||
|
||||
def action_vm(id, xml)
|
||||
post('/compute/'+id.to_s+'/action', xml, false)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Retrieves a Virtual Network
|
||||
# :id Virtual Network identifier
|
||||
######################################################################
|
||||
def get_network(id)
|
||||
get('/network/'+id.to_s)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Puts a new Network representation in order to change its state
|
||||
# :xmlfile Network OCCI xml representation
|
||||
######################################################################
|
||||
def put_network(xmlfile)
|
||||
put('/network/', xmlfile)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# :id VM identifier
|
||||
######################################################################
|
||||
def delete_network(id)
|
||||
delete('/network/'+id.to_s)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Retieves an Image
|
||||
# :image_uuid Image identifier
|
||||
######################################################################
|
||||
def get_image(id)
|
||||
get('/storage/'+id.to_s)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# Puts a new Storage representation in order to change its state
|
||||
# :xmlfile Storage OCCI xml representation
|
||||
######################################################################
|
||||
def put_image(xmlfile)
|
||||
put('/storage/', xmlfile)
|
||||
end
|
||||
|
||||
######################################################################
|
||||
# :id VM identifier
|
||||
######################################################################
|
||||
def delete_image(id)
|
||||
delete('/storage/'+id.to_s)
|
||||
end
|
||||
|
||||
def action_image(id, xml)
|
||||
post('/storage/'+id.to_s+'/action', xml, false)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get(path, verbose=false)
|
||||
path += "?verbose=true" if verbose
|
||||
url = URI.parse(@endpoint+path)
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
do_request(url, req)
|
||||
end
|
||||
|
||||
def post(path, xmlfile, file=true)
|
||||
url = URI.parse(@endpoint+path)
|
||||
req = Net::HTTP::Post.new(url.path)
|
||||
|
||||
if file
|
||||
req.body=File.read(xmlfile)
|
||||
else
|
||||
req.body=xmlfile
|
||||
end
|
||||
|
||||
do_request(url, req)
|
||||
end
|
||||
|
||||
def delete(path)
|
||||
url = URI.parse(@endpoint+path)
|
||||
req = Net::HTTP::Delete.new(url.path)
|
||||
|
||||
do_request(url, req)
|
||||
end
|
||||
|
||||
def put(path, xmlfile)
|
||||
xml = File.read(xmlfile)
|
||||
|
||||
# Get ID from XML
|
||||
begin
|
||||
info = REXML::Document.new(xml).root
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
if info.elements['ID'] == nil
|
||||
return CloudClient::Error.new("Cannot find RESOURCE ID")
|
||||
end
|
||||
|
||||
resource_id = info.elements['ID'].text
|
||||
|
||||
url = URI.parse(@endpoint+path + resource_id)
|
||||
req = Net::HTTP::Put.new(url.path)
|
||||
|
||||
req.body = xml
|
||||
|
||||
do_request(url, req)
|
||||
end
|
||||
|
||||
def do_request(url, req)
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = CloudClient::http_start(url, @timeout) do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
if CloudClient::is_error?(res)
|
||||
return res
|
||||
else
|
||||
return res.body
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,645 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# Common cloud libs
|
||||
require 'CloudServer'
|
||||
|
||||
# OCA
|
||||
include OpenNebula
|
||||
|
||||
# OCCI libs
|
||||
require 'VirtualMachineOCCI'
|
||||
require 'VirtualMachinePoolOCCI'
|
||||
require 'VirtualNetworkOCCI'
|
||||
require 'VirtualNetworkPoolOCCI'
|
||||
require 'ImageOCCI'
|
||||
require 'ImagePoolOCCI'
|
||||
require 'UserOCCI'
|
||||
require 'UserPoolOCCI'
|
||||
|
||||
require 'pp'
|
||||
|
||||
##############################################################################
|
||||
# The OCCI Server provides an OCCI implementation based on the
|
||||
# OpenNebula Engine
|
||||
##############################################################################
|
||||
|
||||
COLLECTIONS = ["compute", "instance_type", "network", "storage", "user"]
|
||||
|
||||
# FLAG that will filter the elements retrieved from the Pools
|
||||
POOL_FILTER = Pool::INFO_ALL
|
||||
|
||||
# Secs to sleep between checks to see if image upload© to repo is finished
|
||||
IMAGE_POLL_SLEEP_TIME = 5
|
||||
|
||||
class OCCIServer < CloudServer
|
||||
# Server initializer
|
||||
# config_file:: _String_ path of the config file
|
||||
# template:: _String_ path to the location of the templates
|
||||
def initialize(client, config, logger)
|
||||
super(config, logger)
|
||||
|
||||
if config[:ssl_server]
|
||||
@base_url=config[:ssl_server]
|
||||
else
|
||||
@base_url="http://#{config[:host]}:#{config[:port]}"
|
||||
end
|
||||
|
||||
@client = client
|
||||
end
|
||||
|
||||
# Prepare the OCCI XML Response
|
||||
# resource:: _Pool_ or _PoolElement_ that represents a OCCI resource
|
||||
# [return] _String_,_Integer_ Resource Representation or error, status code
|
||||
def to_occi_xml(resource, opts)
|
||||
xml_response = resource.to_occi(@base_url, opts[:verbose])
|
||||
return xml_response, 500 if OpenNebula.is_error?(xml_response)
|
||||
|
||||
return xml_response, opts[:code]
|
||||
end
|
||||
|
||||
############################################################################
|
||||
############################################################################
|
||||
# POOL RESOURCE METHODS
|
||||
############################################################################
|
||||
############################################################################
|
||||
|
||||
def get_collections(request)
|
||||
xml_resp = "<COLLECTIONS>"
|
||||
|
||||
COLLECTIONS.sort.each { |c|
|
||||
xml_resp << "<#{c.upcase}_COLLECTION href=\"#{@base_url}/#{c}\"/>"
|
||||
}
|
||||
|
||||
xml_resp << "</COLLECTIONS>"
|
||||
|
||||
return xml_resp, 200
|
||||
end
|
||||
|
||||
|
||||
INSTANCE_TYPE = %q{
|
||||
<INSTANCE_TYPE href="<%= @base_url %>/instance_type/<%=name%>" name="<%= name %>">
|
||||
<ID><%= name.to_s %></ID>
|
||||
<NAME><%= name.to_s %></NAME>
|
||||
<% opts.sort{|k1,k2| k1[0].to_s<=>k2[0].to_s}.each { |elem, value|
|
||||
next if elem==:template
|
||||
str = elem.to_s.upcase %>
|
||||
<<%= str %>><%= value %></<%= str %>>
|
||||
<% } %>
|
||||
</INSTANCE_TYPE>
|
||||
}
|
||||
|
||||
def get_instance_types(request)
|
||||
xml_resp = "<INSTANCE_TYPE_COLLECTION>"
|
||||
|
||||
@config[:instance_types].sort { |k1,k2|
|
||||
k1[0].to_s<=>k2[0].to_s
|
||||
}.each { |name, opts|
|
||||
if request.params['verbose']
|
||||
begin
|
||||
occi_it = ERB.new(INSTANCE_TYPE)
|
||||
occi_it = occi_it.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error, CloudServer::HTTP_ERROR_CODE[error.errno]
|
||||
end
|
||||
|
||||
xml_resp << occi_it.gsub(/\n\s*/,'')
|
||||
else
|
||||
xml_resp << "<INSTANCE_TYPE href=\"#{@base_url}/instance_type/#{name.to_s}\" name=\"#{name}\"/>"
|
||||
end
|
||||
}
|
||||
|
||||
xml_resp << "</INSTANCE_TYPE_COLLECTION>"
|
||||
|
||||
return xml_resp, 200
|
||||
end
|
||||
|
||||
def get_instance_type(request, params)
|
||||
name = params[:id].to_sym
|
||||
unless @config[:instance_types].keys.include?(name)
|
||||
error = OpenNebula::Error.new("INSTANCE_TYPE #{name} not found")
|
||||
return error, 404
|
||||
else
|
||||
opts = @config[:instance_types][name]
|
||||
begin
|
||||
occi_it = ERB.new(INSTANCE_TYPE)
|
||||
occi_it = occi_it.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error, CloudServer::HTTP_ERROR_CODE[error.errno]
|
||||
end
|
||||
|
||||
return occi_it.gsub(/\n\s*/,''), 200
|
||||
end
|
||||
end
|
||||
|
||||
# Gets the pool representation of COMPUTES
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Pool Representation or error, status code
|
||||
def get_computes(request)
|
||||
# --- Get User's VMs ---
|
||||
vmpool = VirtualMachinePoolOCCI.new(
|
||||
@client,
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = vmpool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vmpool, :code=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
|
||||
# Gets the pool representation of NETWORKS
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Network pool representation or error,
|
||||
# => status code
|
||||
def get_networks(request)
|
||||
# --- Get User's VNETs ---
|
||||
network_pool = VirtualNetworkPoolOCCI.new(
|
||||
@client,
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = network_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network_pool, :code=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
# Gets the pool representation of STORAGES
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Image pool representation or error,
|
||||
# status code
|
||||
def get_storages(request)
|
||||
# --- Get User's Images ---
|
||||
image_pool = ImagePoolOCCI.new(
|
||||
@client,
|
||||
POOL_FILTER)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = image_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(image_pool, :code=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
# Gets the pool representation of USERs
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ User pool representation or error,
|
||||
# status code
|
||||
def get_users(request)
|
||||
# --- Get Users Pool ---
|
||||
user_pool = UserPoolOCCI.new(@client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = user_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(user_pool, :code=>200, :verbose=>request.params['verbose'])
|
||||
end
|
||||
|
||||
############################################################################
|
||||
############################################################################
|
||||
# ENTITY RESOURCE METHODS
|
||||
############################################################################
|
||||
############################################################################
|
||||
|
||||
############################################################################
|
||||
# COMPUTE Methods
|
||||
############################################################################
|
||||
|
||||
# Post a new compute to the COMPUTE pool
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ COMPUTE Representation or error, status code
|
||||
def post_compute(request)
|
||||
# --- Create the new Instance ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml,
|
||||
@client,
|
||||
request.body.read,
|
||||
@config[:instance_types],
|
||||
@config[:template_location])
|
||||
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
template = vm.to_one_template
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = vm.allocate(template)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
vm.info
|
||||
return to_occi_xml(vm, :code=>201)
|
||||
end
|
||||
|
||||
# Get the representation of a COMPUTE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ COMPUTE representation or error,
|
||||
# status code
|
||||
def get_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = vm.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(vm, :code=>200)
|
||||
end
|
||||
|
||||
# Deletes a COMPUTE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Delete confirmation msg or error,
|
||||
# status code
|
||||
def delete_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Finalize the VM ---
|
||||
result = vm.finalize
|
||||
if OpenNebula.is_error?(result)
|
||||
return result, CloudServer::HTTP_ERROR_CODE[result.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
|
||||
# Attach a disk to an existing COMPUTE
|
||||
# @param [Hash] request hash containing the data of the request
|
||||
# @param [Hash] params hash containing the params of the request
|
||||
# @param [OpenNebula::XMLElement] action_xml contains the body of the request
|
||||
# @return [[String, OpenNebula:Error], Integer]
|
||||
def attach_disk(request, params, action_xml)
|
||||
# --- Get the VM ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
image_href = action_xml.attr('PARAMS/STORAGE','href')
|
||||
if !image_href
|
||||
error = OpenNebula::Error.new("You have to specify an STORAGE " <<
|
||||
"to be attached")
|
||||
return error, CloudServer::HTTP_ERROR_CODE[error.errno]
|
||||
end
|
||||
|
||||
image_id = image_href.split('/').last
|
||||
target = action_xml['PARAMS/TARGET']
|
||||
|
||||
if target
|
||||
template = "DISK = [ IMAGE_ID = #{image_id}, TARGET = #{target} ]"
|
||||
else
|
||||
template = "DISK = [ IMAGE_ID = #{image_id}, DEV_PREFIX = sd ]"
|
||||
end
|
||||
|
||||
# --- Attach DISK ---
|
||||
result = vm.attachdisk(template)
|
||||
if OpenNebula.is_error?(result)
|
||||
return result, CloudServer::HTTP_ERROR_CODE[result.errno]
|
||||
end
|
||||
|
||||
vm.info
|
||||
|
||||
return to_occi_xml(vm, :code=>202)
|
||||
end
|
||||
|
||||
# Detach a DISK from an existing COMOUTE
|
||||
# @param [Hash] request hash containing the data of the request
|
||||
# @param [Hash] params hash containing the params of the request
|
||||
# @param [OpenNebula::XMLElement] action_xml contains the body of the request
|
||||
# @return [[String, OpenNebula:Error], Integer]
|
||||
def detach_disk(request, params, action_xml)
|
||||
# --- Get the VM ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
disk_id = action_xml.attr('PARAMS/DISK','id')
|
||||
if !disk_id
|
||||
error = OpenNebula::Error.new("You have to specify a DISK " <<
|
||||
"to be detached")
|
||||
return error, CloudServer::HTTP_ERROR_CODE[error.errno]
|
||||
end
|
||||
|
||||
# --- Detach DISK ---
|
||||
result = vm.detachdisk(disk_id.to_i)
|
||||
if OpenNebula.is_error?(result)
|
||||
return result, CloudServer::HTTP_ERROR_CODE[result.errno]
|
||||
end
|
||||
|
||||
vm.info
|
||||
|
||||
return to_occi_xml(vm, :code=>202)
|
||||
end
|
||||
|
||||
# Updates a COMPUTE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Update confirmation msg or error,
|
||||
# status code
|
||||
def put_compute(request, params)
|
||||
# --- Get the VM ---
|
||||
vm = VirtualMachineOCCI.new(
|
||||
VirtualMachine.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = vm.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
result, code = vm.update_from_xml(request.body)
|
||||
|
||||
if OpenNebula.is_error?(result)
|
||||
return result, code
|
||||
else
|
||||
vm.info
|
||||
return to_occi_xml(vm, :code=>code)
|
||||
end
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# NETWORK Methods
|
||||
############################################################################
|
||||
|
||||
# Post a new network to the NETWORK pool
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Network Representation or error, status code
|
||||
def post_network(request)
|
||||
# --- Create the new Instance ---
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml,
|
||||
@client,
|
||||
request.body,
|
||||
@config[:template_location])
|
||||
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
template = network.to_one_template
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = network.allocate(template, @config[:cluster_id]||ClusterPool::NONE_CLUSTER_ID)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
network.info
|
||||
return to_occi_xml(network, :code=>201)
|
||||
end
|
||||
|
||||
# Retrieves a NETWORK resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ NETWORK occi representation or error,
|
||||
# status code
|
||||
def get_network(request, params)
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = network.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(network, :code=>200)
|
||||
end
|
||||
|
||||
# Deletes a NETWORK resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Delete confirmation msg or error,
|
||||
# status code
|
||||
def delete_network(request, params)
|
||||
network = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Delete the VNET ---
|
||||
rc = network.delete
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
|
||||
# Updates a NETWORK resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Update confirmation msg or error,
|
||||
# status code
|
||||
def put_network(request, params)
|
||||
xmldoc = XMLElement.build_xml(request.body, 'NETWORK')
|
||||
vnet_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
|
||||
vnet = VirtualNetworkOCCI.new(
|
||||
VirtualNetwork.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = nil
|
||||
if vnet_info['PUBLIC'] == 'YES'
|
||||
rc = vnet.publish
|
||||
elsif vnet_info['PUBLIC'] == 'NO'
|
||||
rc = vnet.unpublish
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
vnet.info
|
||||
return to_occi_xml(vnet, :code=>202)
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# STORAGE Methods
|
||||
############################################################################
|
||||
|
||||
# Post a new image to the STORAGE pool
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Image representation or error, status code
|
||||
def post_storage(request)
|
||||
# --- Check OCCI XML from POST ---
|
||||
if request.params['occixml'] == nil
|
||||
error_msg = "OCCI XML representation of Image" +
|
||||
" not present in the request"
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error, 400
|
||||
end
|
||||
|
||||
# --- Create and Add the new Image ---
|
||||
occixml = request.params['occixml']
|
||||
occixml = occixml[:tempfile].read if occixml.class == Hash
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml,
|
||||
@client,
|
||||
occixml,
|
||||
request.params['file'])
|
||||
|
||||
# --- Generate the template and Allocate the new Instance ---
|
||||
template = image.to_one_template
|
||||
return template, 500 if OpenNebula.is_error?(template)
|
||||
|
||||
rc = image.allocate(template, @config[:datastore_id]||1)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
image.info
|
||||
#wait until image is ready to return
|
||||
while (image.state_str == 'LOCKED') && (image['RUNNING_VMS'] == '0') do
|
||||
sleep IMAGE_POLL_SLEEP_TIME
|
||||
image.info
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
return to_occi_xml(image, :code=>201)
|
||||
end
|
||||
|
||||
# Get a STORAGE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ STORAGE occi representation or error,
|
||||
# status code
|
||||
def get_storage(request, params)
|
||||
# --- Get the Image ---
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = image.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
return to_occi_xml(image, :code=>200)
|
||||
end
|
||||
|
||||
# Clone a STORAGE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ STORAGE occi representation or error,
|
||||
# status code
|
||||
def clone_storage(request, params, action_xml)
|
||||
# --- Get the Image ---
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = image.clone(action_xml["PARAMS/NAME"])
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
new_image = ImageOCCI.new(
|
||||
Image.build_xml(rc),
|
||||
@client)
|
||||
|
||||
new_image.info
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
return to_occi_xml(new_image, :code=>201)
|
||||
end
|
||||
|
||||
# Deletes a STORAGE resource (Not yet implemented)
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Delete confirmation msg or error,
|
||||
# status code
|
||||
def delete_storage(request, params)
|
||||
# --- Get the Image ---
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Delete the Image ---
|
||||
rc = image.delete
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return "", 204
|
||||
end
|
||||
|
||||
# Updates a STORAGE resource
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ Update confirmation msg or error,
|
||||
# status code
|
||||
def put_storage(request, params)
|
||||
xmldoc = XMLElement.build_xml(request.body, 'STORAGE')
|
||||
image_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
|
||||
image = ImageOCCI.new(
|
||||
Image.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
rc = nil
|
||||
if image_info['PERSISTENT'] && image_info['PUBLIC']
|
||||
error_msg = "It is not allowed more than one change per request"
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
elsif image_info['PERSISTENT'] == 'YES'
|
||||
rc = image.persistent
|
||||
elsif image_info['PERSISTENT'] == 'NO'
|
||||
rc = image.nonpersistent
|
||||
elsif image_info['PUBLIC'] == 'YES'
|
||||
rc = image.publish
|
||||
elsif image_info['PUBLIC'] == 'NO'
|
||||
rc = image.unpublish
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
image.info
|
||||
return to_occi_xml(image, :code=>202)
|
||||
end
|
||||
|
||||
# Get the representation of a USER
|
||||
# request:: _Hash_ hash containing the data of the request
|
||||
# [return] _String_,_Integer_ USER representation or error,
|
||||
# status code
|
||||
def get_user(request, params)
|
||||
# --- Get the USER ---
|
||||
user = UserOCCI.new(
|
||||
User.build_xml(params[:id]),
|
||||
@client)
|
||||
|
||||
# --- Prepare XML Response ---
|
||||
rc = user.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
end
|
||||
|
||||
return to_occi_xml(user, :code=>200)
|
||||
end
|
||||
end
|
@ -1,46 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class UserOCCI < User
|
||||
FORCE_USAGE = true
|
||||
|
||||
OCCI_USER = %q{
|
||||
<USER href="<%= base_url %>/user/<%= self.id.to_s %>">
|
||||
<ID><%= self.id.to_s %></ID>
|
||||
<NAME><%= self.name %></NAME>
|
||||
<GROUP><%= self['GNAME'] %></GROUP>
|
||||
<%= self.element_xml('DATASTORE_QUOTA') %>
|
||||
<%= self.element_xml('NETWORK_QUOTA') %>
|
||||
<%= self.element_xml('VM_QUOTA') %>
|
||||
<%= self.element_xml('IMAGE_QUOTA') %>
|
||||
</USER>
|
||||
}
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client)
|
||||
super(xml, client)
|
||||
end
|
||||
|
||||
# Creates the OCCI representation of a User
|
||||
def to_occi(base_url, verbose=false)
|
||||
occi = ERB.new(OCCI_USER)
|
||||
return occi.result(binding).gsub(/\n\s*/,'')
|
||||
end
|
||||
end
|
@ -1,48 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'UserOCCI'
|
||||
|
||||
class UserPoolOCCI < UserPool
|
||||
OCCI_USER_POOL = %q{
|
||||
<USER_COLLECTION>
|
||||
<% self.each{ |user| %>
|
||||
<% if verbose %>
|
||||
<%= user.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<USER href="<%= base_url %>/user/<%= user.id.to_s %>" name="<%= user.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</USER_COLLECTION>
|
||||
}
|
||||
|
||||
# Creates the OCCI representation of a User Pool
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi = ERB.new(OCCI_USER_POOL)
|
||||
occi_text = occi.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
UserOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
@ -1,227 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualMachineOCCI < VirtualMachine
|
||||
OCCI_VM = %q{
|
||||
<COMPUTE href="<%= base_url %>/compute/<%= self.id.to_s %>">
|
||||
<ID><%= self.id.to_s%></ID>
|
||||
<USER href="<%= base_url %>/user/<%= self['UID'] %>" name="<%= self['UNAME'] %>"/>
|
||||
<GROUP><%= self['GNAME'] %></GROUP>
|
||||
<CPU><%= self['TEMPLATE/CPU'] %></CPU>
|
||||
<MEMORY><%= self['TEMPLATE/MEMORY'] %></MEMORY>
|
||||
<NAME><%= self.name%></NAME>
|
||||
<% if self['USER_TEMPLATE/INSTANCE_TYPE'] %>
|
||||
<INSTANCE_TYPE href="<%= base_url %>/instance_type/<%= self['USER_TEMPLATE/INSTANCE_TYPE'] %>"><%= self['USER_TEMPLATE/INSTANCE_TYPE'] %></INSTANCE_TYPE>
|
||||
<% end %>
|
||||
<STATE><%= self.state_str %></STATE>
|
||||
<% self.each('TEMPLATE/DISK') do |disk| %>
|
||||
<DISK id="<%= disk['DISK_ID']%>">
|
||||
<% if disk['SAVE_AS'] %>
|
||||
<SAVE_AS href="<%= base_url %>/storage/<%= disk['SAVE_AS'] %>"/>
|
||||
<% end %>
|
||||
<STORAGE href="<%= base_url %>/storage/<%= disk['IMAGE_ID'] %>" name="<%= disk['IMAGE'] %>"/>
|
||||
<TYPE><%= disk['TYPE'] %></TYPE>
|
||||
<TARGET><%= disk['TARGET'] %></TARGET>
|
||||
</DISK>
|
||||
<% end %>
|
||||
<% self.each('TEMPLATE/NIC') do |nic| %>
|
||||
<NIC>
|
||||
<NETWORK href="<%= base_url %>/network/<%= nic['NETWORK_ID'] %>" name="<%= nic['NETWORK'] %>"/>
|
||||
<% if nic['IP'] %>
|
||||
<IP><%= nic['IP'] %></IP>
|
||||
<% end %>
|
||||
<% if nic['MAC'] %>
|
||||
<MAC><%= nic['MAC'] %></MAC>
|
||||
<% end %>
|
||||
</NIC>
|
||||
<% end %>
|
||||
<% if self.has_elements?('TEMPLATE/CONTEXT') %>
|
||||
<CONTEXT>
|
||||
<% self.each('TEMPLATE/CONTEXT/*') do |cont| %>
|
||||
<% if cont.text %>
|
||||
<<%= cont.name %>><%= cont.text %></<%= cont.name %>>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</CONTEXT>
|
||||
<% end %>
|
||||
</COMPUTE>
|
||||
}
|
||||
|
||||
OCCI_ACTION = {
|
||||
"STOPPED" => { :from => ["ACTIVE"], :action => :stop},
|
||||
"SUSPENDED" => { :from => ["ACTIVE"], :action => :suspend},
|
||||
"RESUME" => { :from => ["STOPPED", "SUSPENDED", "POWEROFF"], :action => :resume},
|
||||
"CANCEL" => { :from => ["ACTIVE"], :action => :cancel},
|
||||
"REBOOT" => { :from => ["ACTIVE"], :action => :reboot},
|
||||
"RESET" => { :from => ["ACTIVE"], :action => :reset},
|
||||
"SHUTDOWN" => { :from => ["ACTIVE"], :action => :shutdown},
|
||||
"RESTART" => { :from => ["ACTIVE"], :action => :restart},
|
||||
"RESUBMIT" => { :from => ["ACTIVE", "FAILED"], :action => :resubmit},
|
||||
"POWEROFF" => { :from => ["ACTIVE"], :action => :poweroff},
|
||||
"DONE" => { :from => VM_STATE, :action => :finalize}
|
||||
}
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client, xml_info=nil, types=nil, base=nil)
|
||||
super(xml, client)
|
||||
@vm_info = nil
|
||||
@template = nil
|
||||
@common_template = base + '/common.erb' if base
|
||||
|
||||
if xml_info != nil
|
||||
xmldoc = XMLElement.build_xml(xml_info, 'COMPUTE')
|
||||
@vm_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
end
|
||||
|
||||
if @vm_info != nil
|
||||
if href = @vm_info.attr('INSTANCE_TYPE','href')
|
||||
@itype = href.split('/').last
|
||||
else
|
||||
@itype = @vm_info['INSTANCE_TYPE']
|
||||
end
|
||||
|
||||
if @itype != nil and types[@itype.to_sym] != nil
|
||||
@template = base + "/#{types[@itype.to_sym][:template]}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def to_one_template()
|
||||
if @vm_info == nil
|
||||
error_msg = "Missing COMPUTE section in the XML body"
|
||||
return OpenNebula::Error.new(error_msg)
|
||||
end
|
||||
|
||||
if @template == nil
|
||||
return OpenNebula::Error.new("Bad instance type")
|
||||
end
|
||||
|
||||
begin
|
||||
template = ERB.new(File.read(@common_template)).result(binding)
|
||||
template << ERB.new(File.read(@template)).result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return template
|
||||
end
|
||||
|
||||
# Creates the VMI representation of a Virtual Machine
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi_vm = ERB.new(OCCI_VM)
|
||||
occi_vm_text = occi_vm.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_vm_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
# Update de resource from an XML representation of the COMPUTE
|
||||
# @param [String] xml_compute XML representation of the COMPUTE
|
||||
# @return [[nil, OpenNebula::Error], HTTP_CODE] If there is no error
|
||||
# the first component is nil.
|
||||
def update_from_xml(xml_compute)
|
||||
xmldoc = XMLElement.build_xml(xml_compute, 'COMPUTE')
|
||||
vm_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
|
||||
action = nil
|
||||
args = []
|
||||
|
||||
# Check if a state change is required
|
||||
occi_state = vm_info['STATE']
|
||||
|
||||
if occi_state
|
||||
# If a state is provided
|
||||
occi_state.upcase!
|
||||
if OCCI_ACTION.keys.include?(occi_state)
|
||||
# If the requested state is one the OCCI action states
|
||||
shash = OCCI_ACTION[occi_state]
|
||||
if shash[:from].include?(state_str)
|
||||
# Action to be performed
|
||||
action = shash[:action]
|
||||
elsif occi_state != state_str
|
||||
# If the requested state is different from the resource
|
||||
# state but it does not belong to the "from" state array
|
||||
error_msg = "The state of the resource cannot be changed" \
|
||||
" from #{state_str} to #{occi_state}."
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error, 403
|
||||
end
|
||||
elsif !VM_STATE.include?(occi_state)
|
||||
# The requested state is not one of the OCCI action states nor
|
||||
# a resource state
|
||||
error_msg = "Invalid state: \"#{occi_state}\""
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error, 400
|
||||
end
|
||||
end
|
||||
|
||||
# Check if a disk image save as is required
|
||||
image_name = nil
|
||||
vm_info.each('DISK/SAVE_AS') { |save_as|
|
||||
image_name = save_as.attr('.', 'name')
|
||||
if image_name
|
||||
if action
|
||||
# Return erro if an action has been defined before
|
||||
if action == :save_as
|
||||
error_msg = "Only one disk can be saved per request"
|
||||
else
|
||||
error_msg = "Changig the state of the resource and" \
|
||||
" saving a disk is not allowed in the same request"
|
||||
end
|
||||
error = OpenNebula::Error.new(error_msg)
|
||||
return error, 403
|
||||
else
|
||||
# if no action is defined yet and a save_as is requested
|
||||
action = :save_as
|
||||
disk_id = save_as.attr('..', 'id')
|
||||
|
||||
# Params for the save_as action:
|
||||
# save_as(disk_id, image_name)
|
||||
args << disk_id.to_i
|
||||
args << image_name
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
# Perform the requested action
|
||||
if action
|
||||
rc = self.send(action, *args)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc, CloudServer::HTTP_ERROR_CODE[rc.errno]
|
||||
else
|
||||
return nil, 202
|
||||
end
|
||||
else
|
||||
# There is no change requested
|
||||
return nil, 200
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'VirtualMachineOCCI'
|
||||
|
||||
class VirtualMachinePoolOCCI < VirtualMachinePool
|
||||
OCCI_VM_POOL = %q{
|
||||
<COMPUTE_COLLECTION>
|
||||
<% self.each{ |vm| %>
|
||||
<% if verbose %>
|
||||
<%= vm.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<COMPUTE href="<%= base_url %>/compute/<%= vm.id.to_s %>" name="<%= vm.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</COMPUTE_COLLECTION>
|
||||
}
|
||||
|
||||
|
||||
# Creates the OCCI representation of a Virtual Machine Pool
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi = ERB.new(OCCI_VM_POOL)
|
||||
occi_text = occi.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
VirtualMachineOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
||||
|
@ -1,102 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula'
|
||||
require 'ipaddr'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
class VirtualNetworkOCCI < VirtualNetwork
|
||||
OCCI_NETWORK = %q{
|
||||
<NETWORK href="<%= base_url %>/network/<%= self.id.to_s %>">
|
||||
<ID><%= self.id.to_s %></ID>
|
||||
<NAME><%= self.name %></NAME>
|
||||
<USER href="<%= base_url %>/user/<%= self['UID'] %>" name="<%= self['UNAME'] %>"/>
|
||||
<GROUP><%= self['GNAME'] %></GROUP>
|
||||
<% if self['TEMPLATE/DESCRIPTION'] != nil %>
|
||||
<DESCRIPTION><%= self['TEMPLATE/DESCRIPTION'] %></DESCRIPTION>
|
||||
<% end %>
|
||||
<% if network_address != nil %>
|
||||
<ADDRESS><%= network_address %></ADDRESS>
|
||||
<% end %>
|
||||
<% if network_size != nil %>
|
||||
<SIZE><%= network_size %></SIZE>
|
||||
<% end %>
|
||||
<USED_LEASES><%= self['TOTAL_LEASES'] %></USED_LEASES>
|
||||
<PUBLIC><%= self.public? ? "YES" : "NO" %></PUBLIC>
|
||||
</NETWORK>
|
||||
}
|
||||
|
||||
# Class constructor
|
||||
#
|
||||
def initialize(xml, client, xml_info=nil, base=nil)
|
||||
super(xml, client)
|
||||
@vnet_info = nil
|
||||
@common_template = base + '/network.erb' if base
|
||||
|
||||
if xml_info != nil
|
||||
xmldoc = XMLElement.build_xml(xml_info, 'NETWORK')
|
||||
@vnet_info = XMLElement.new(xmldoc) if xmldoc != nil
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the OCCI representation of a Virtual Network
|
||||
def to_occi(base_url, verbose=false)
|
||||
network_address = nil
|
||||
network_size = nil
|
||||
|
||||
if self['RANGE/IP_START']
|
||||
network_address = self['RANGE/IP_START']
|
||||
|
||||
ip_start = IPAddr.new(network_address, Socket::AF_INET)
|
||||
ip_end = IPAddr.new(self['RANGE/IP_END'], Socket::AF_INET)
|
||||
|
||||
network_size = ip_end.to_i - ip_start.to_i
|
||||
end
|
||||
|
||||
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
||||
pub = "YES"
|
||||
else
|
||||
pub = "NO"
|
||||
end
|
||||
|
||||
begin
|
||||
occi = ERB.new(OCCI_NETWORK)
|
||||
occi_text = occi.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def to_one_template()
|
||||
if @vnet_info == nil
|
||||
error_msg = "Missing NETWORK section in the XML body"
|
||||
return OpenNebula::Error.new(error_msg), 400
|
||||
end
|
||||
|
||||
begin
|
||||
template = ERB.new(File.read(@common_template)).result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return template
|
||||
end
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'VirtualNetworkOCCI'
|
||||
|
||||
class VirtualNetworkPoolOCCI < VirtualNetworkPool
|
||||
OCCI_NETWORK_POOL = %q{
|
||||
<NETWORK_COLLECTION>
|
||||
<% self.each{ |vn| %>
|
||||
<% if verbose %>
|
||||
<%= vn.to_occi(base_url) %>
|
||||
<% else %>
|
||||
<NETWORK href="<%= base_url %>/network/<%= vn.id.to_s %>" name="<%= vn.name %>"/>
|
||||
<% end %>
|
||||
<% } %>
|
||||
</NETWORK_COLLECTION>
|
||||
}
|
||||
|
||||
|
||||
# Creates the OCCI representation of a Virtual Machine Pool
|
||||
def to_occi(base_url, verbose=false)
|
||||
begin
|
||||
occi = ERB.new(OCCI_NETWORK_POOL)
|
||||
occi_text = occi.result(binding)
|
||||
rescue Exception => e
|
||||
error = OpenNebula::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return occi_text.gsub(/\n\s*/,'')
|
||||
end
|
||||
|
||||
def factory(element_xml)
|
||||
VirtualNetworkOCCI.new(element_xml,@client)
|
||||
end
|
||||
end
|
@ -1,272 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
##############################################################################
|
||||
# The OCCI Server provides compatible server based on the
|
||||
# OpenNebula Engine
|
||||
##############################################################################
|
||||
|
||||
##############################################################################
|
||||
# Environment Configuration for the Cloud Server
|
||||
##############################################################################
|
||||
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"
|
||||
else
|
||||
VAR_LOCATION = ONE_LOCATION + "/var"
|
||||
LOG_LOCATION = ONE_LOCATION + "/var"
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc"
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth"
|
||||
OCCI_LOG = LOG_LOCATION + "/occi-server.log"
|
||||
CONFIGURATION_FILE = ETC_LOCATION + "/occi-server.conf"
|
||||
|
||||
TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates"
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud" # For the Repository Manager
|
||||
|
||||
################################################
|
||||
# Required libraries
|
||||
################################################
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'yaml'
|
||||
require 'erb'
|
||||
require 'tempfile'
|
||||
require 'fileutils'
|
||||
require 'json'
|
||||
|
||||
require 'OCCIServer'
|
||||
require 'CloudAuth'
|
||||
require 'occi_application'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
################################################################################
|
||||
# Configuration
|
||||
################################################################################
|
||||
|
||||
begin
|
||||
$occi_app = OCCIApplication.new
|
||||
rescue Exception => e
|
||||
STDERR.puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
# The logging will be configured in Rack, not in Sinatra
|
||||
disable :logging
|
||||
|
||||
use Rack::CommonLogger, $occi_app.logger
|
||||
|
||||
# Set the host and port
|
||||
set :bind, $occi_app.conf[:host]
|
||||
set :port, $occi_app.conf[:port]
|
||||
|
||||
set :run, false
|
||||
|
||||
##############################################################################
|
||||
# Helpers
|
||||
##############################################################################
|
||||
|
||||
before do
|
||||
cache_control :no_store
|
||||
content_type 'application/xml', :charset => 'utf-8'
|
||||
|
||||
begin
|
||||
username = $occi_app.cloud_auth.auth(request.env, params)
|
||||
rescue Exception => e
|
||||
$occi_app.logger.error {e.message}
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
if username.nil? #unable to authenticate
|
||||
$occi_app.logger.error {"User not authorized"}
|
||||
error 401, ""
|
||||
else
|
||||
@occi_server = $occi_app.new_occi_server(username)
|
||||
end
|
||||
end
|
||||
|
||||
# Response treatment
|
||||
helpers do
|
||||
def logger
|
||||
$occi_app.logger
|
||||
end
|
||||
|
||||
def treat_response(result, rc)
|
||||
if OpenNebula::is_error?(result)
|
||||
logger.error {result.message}
|
||||
content_type 'text/plain', :charset => 'utf-8'
|
||||
halt rc, result.message
|
||||
end
|
||||
|
||||
status rc
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
##############################################################################
|
||||
# Actions
|
||||
##############################################################################
|
||||
|
||||
get '/' do
|
||||
result,rc = @occi_server.get_collections(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Pool Resources methods
|
||||
###################################################
|
||||
|
||||
get '/instance_type' do
|
||||
result,rc = @occi_server.get_instance_types(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/compute' do
|
||||
result,rc = @occi_server.post_compute(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/compute' do
|
||||
result,rc = @occi_server.get_computes(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/network' do
|
||||
result,rc = @occi_server.post_network(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/network' do
|
||||
result,rc = @occi_server.get_networks(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/storage' do
|
||||
result,rc = @occi_server.post_storage(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/storage' do
|
||||
result,rc = @occi_server.get_storages(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/user' do
|
||||
result,rc = @occi_server.get_users(request)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
###################################################
|
||||
# Entity Resources Methods
|
||||
###################################################
|
||||
|
||||
get '/compute/:id' do
|
||||
result,rc = @occi_server.get_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/compute/:id/action' do
|
||||
xml = XMLElement.new
|
||||
xml.initialize_xml(request.body, "ACTION")
|
||||
|
||||
result,rc = case xml['PERFORM'].downcase
|
||||
when 'attachdisk' then
|
||||
@occi_server.attach_disk(request, params, xml)
|
||||
when 'detachdisk' then
|
||||
@occi_server.detach_disk(request, params, xml)
|
||||
else
|
||||
content_type 'text/plain', :charset => 'utf-8'
|
||||
halt 403, "Action #{xml['PERFORM']} not supported"
|
||||
end
|
||||
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/compute/:id' do
|
||||
result,rc = @occi_server.delete_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/compute/:id' do
|
||||
result,rc = @occi_server.put_compute(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/network/:id' do
|
||||
result,rc = @occi_server.get_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/network/:id' do
|
||||
result,rc = @occi_server.delete_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/network/:id' do
|
||||
result,rc = @occi_server.put_network(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/storage/:id' do
|
||||
result,rc = @occi_server.get_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
post '/storage/:id/action' do
|
||||
xml = XMLElement.new
|
||||
xml.initialize_xml(request.body, "ACTION")
|
||||
|
||||
result, rc = case xml['PERFORM'].downcase
|
||||
when 'clone' then
|
||||
@occi_server.clone_storage(request, params, xml)
|
||||
else
|
||||
halt 403, "Action #{xml['PERFORM']} not supported"
|
||||
end
|
||||
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
delete '/storage/:id' do
|
||||
result,rc = @occi_server.delete_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
put '/storage/:id' do
|
||||
result,rc = @occi_server.put_storage(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/user/:id' do
|
||||
result,rc = @occi_server.get_user(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
get '/instance_type/:id' do
|
||||
result,rc = @occi_server.get_instance_type(request, params)
|
||||
treat_response(result,rc)
|
||||
end
|
||||
|
||||
Sinatra::Application.run!
|
@ -1,90 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'CloudServer'
|
||||
|
||||
class OCCIApplication
|
||||
#Configuration constants
|
||||
OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth"
|
||||
OCCI_LOG = LOG_LOCATION + "/occi-server.log"
|
||||
CONF_FILE = ETC_LOCATION + "/occi-server.conf"
|
||||
|
||||
TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates"
|
||||
|
||||
#Attribute accesors
|
||||
attr_reader :conf
|
||||
attr_reader :logger
|
||||
attr_reader :cloud_auth
|
||||
|
||||
def initialize()
|
||||
begin
|
||||
load_configuration
|
||||
|
||||
init_logger
|
||||
|
||||
init_auth
|
||||
|
||||
if CloudServer.is_port_open?(@conf[:host], @conf[:port])
|
||||
raise "Port #{@conf[:port]} busy."
|
||||
end
|
||||
rescue
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
def new_occi_server(username)
|
||||
OCCIServer.new(@cloud_auth.client(username), @conf, @logger)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Load the configuration for the OCCI Server
|
||||
def load_configuration
|
||||
begin
|
||||
@conf = YAML.load_file(CONFIGURATION_FILE)
|
||||
rescue Exception => e
|
||||
raise "Error parsing file #{CONFIGURATION_FILE}: #{e.message}"
|
||||
end
|
||||
|
||||
@conf[:template_location] = TEMPLATE_LOCATION
|
||||
@conf[:debug_level] ||= 3
|
||||
|
||||
CloudServer.print_configuration(@conf)
|
||||
end
|
||||
|
||||
#Initialize the log system
|
||||
def init_logger
|
||||
@logger = CloudLogger::CloudLogger.new(OCCI_LOG)
|
||||
|
||||
@logger.level = CloudLogger::DEBUG_LEVEL[@conf[:debug_level].to_i]
|
||||
@logger.formatter = proc do |severity, datetime, progname, msg|
|
||||
CloudLogger::MSG_FORMAT % [
|
||||
datetime.strftime( CloudLogger::DATE_FORMAT),
|
||||
severity[0..0],
|
||||
msg ]
|
||||
end
|
||||
end
|
||||
|
||||
#Initialize the auth system
|
||||
def init_auth
|
||||
begin
|
||||
ENV["ONE_CIPHER_AUTH"] = OCCI_AUTH
|
||||
@cloud_auth = CloudAuth.new(@conf, @logger)
|
||||
rescue => e
|
||||
raise "Error initializing authentication system: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
<COMPUTE>
|
||||
<NAME>MyCompute</NAME>
|
||||
<INSTANCE_TYPE>large</INSTANCE_TYPE>
|
||||
<DISK>
|
||||
<STORAGE href="http://www.opennebula.org/storage/4"/>
|
||||
</DISK>
|
||||
<NIC>
|
||||
<NETWORK href="http://www.opennebula.org/network/2"/>
|
||||
</NIC>
|
||||
</COMPUTE>
|
@ -1,5 +0,0 @@
|
||||
<NETWORK>
|
||||
<NAME>MyServiceNetwork</NAME>
|
||||
<ADDRESS>192.168.1.1</ADDRESS>
|
||||
<SIZE>200</SIZE>
|
||||
</NETWORK>
|
@ -1,6 +0,0 @@
|
||||
<STORAGE>
|
||||
<NAME>Ubuntu Desktop</NAME>
|
||||
<DESCRIPTION>Ubuntu 10.04 desktop for students.</DESCRIPTION>
|
||||
<TYPE>OS</TYPE>
|
||||
<URL>file:///images/ubuntu/jaunty.img</URL>
|
||||
</STORAGE>
|
@ -1 +0,0 @@
|
||||
<COMPUTE_COLLECTION></COMPUTE_COLLECTION>
|
@ -1,20 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0">
|
||||
<ID>0</ID>
|
||||
<USER href="http://localhost:4567/user/2" name="my_first_occi_user"/>
|
||||
<GROUP>oneadmin</GROUP>
|
||||
<CPU>1</CPU>
|
||||
<MEMORY>1024</MEMORY>
|
||||
<NAME>Compute</NAME>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small">small</INSTANCE_TYPE>
|
||||
<STATE>PENDING</STATE>
|
||||
<DISK id="0">
|
||||
<STORAGE href="http://localhost:4567/storage/0" name="Storage"/>
|
||||
<TYPE>FILE</TYPE>
|
||||
<TARGET>hda</TARGET>
|
||||
</DISK>
|
||||
<NIC>
|
||||
<NETWORK href="http://localhost:4567/network/0" name="Network"/>
|
||||
<IP>192.168.1.1</IP>
|
||||
<MAC>02:00:c0:a8:01:01</MAC>
|
||||
</NIC>
|
||||
</COMPUTE>
|
@ -1,20 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0">
|
||||
<ID>0</ID>
|
||||
<USER href="http://localhost:4567/user/2" name="my_first_occi_user"/>
|
||||
<GROUP>oneadmin</GROUP>
|
||||
<CPU>1</CPU>
|
||||
<MEMORY>1024</MEMORY>
|
||||
<NAME>Compute</NAME>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small">small</INSTANCE_TYPE>
|
||||
<STATE>DONE</STATE>
|
||||
<DISK id="0">
|
||||
<STORAGE href="http://localhost:4567/storage/0" name="Storage"/>
|
||||
<TYPE>FILE</TYPE>
|
||||
<TARGET>hda</TARGET>
|
||||
</DISK>
|
||||
<NIC>
|
||||
<NETWORK href="http://localhost:4567/network/0" name="Network"/>
|
||||
<IP>192.168.1.1</IP>
|
||||
<MAC>02:00:c0:a8:01:01</MAC>
|
||||
</NIC>
|
||||
</COMPUTE>
|
@ -1,20 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/1">
|
||||
<ID>1</ID>
|
||||
<USER href="http://localhost:4567/user/3" name="my_second_occi_user"/>
|
||||
<GROUP>users</GROUP>
|
||||
<CPU>1</CPU>
|
||||
<MEMORY>1024</MEMORY>
|
||||
<NAME>Compute2</NAME>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small">small</INSTANCE_TYPE>
|
||||
<STATE>PENDING</STATE>
|
||||
<DISK id="0">
|
||||
<STORAGE href="http://localhost:4567/storage/1" name="Storage2"/>
|
||||
<TYPE>FILE</TYPE>
|
||||
<TARGET>hda</TARGET>
|
||||
</DISK>
|
||||
<NIC>
|
||||
<NETWORK href="http://localhost:4567/network/1" name="Network2"/>
|
||||
<IP>192.168.2.1</IP>
|
||||
<MAC>02:00:c0:a8:02:01</MAC>
|
||||
</NIC>
|
||||
</COMPUTE>
|
@ -1,20 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/1">
|
||||
<ID>1</ID>
|
||||
<USER href="http://localhost:4567/user/3" name="my_second_occi_user"/>
|
||||
<GROUP>users</GROUP>
|
||||
<CPU>1</CPU>
|
||||
<MEMORY>1024</MEMORY>
|
||||
<NAME>Compute2</NAME>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small">small</INSTANCE_TYPE>
|
||||
<STATE>DONE</STATE>
|
||||
<DISK id="0">
|
||||
<STORAGE href="http://localhost:4567/storage/1" name="Storage2"/>
|
||||
<TYPE>FILE</TYPE>
|
||||
<TARGET>hda</TARGET>
|
||||
</DISK>
|
||||
<NIC>
|
||||
<NETWORK href="http://localhost:4567/network/1" name="Network2"/>
|
||||
<IP>192.168.2.1</IP>
|
||||
<MAC>02:00:c0:a8:02:01</MAC>
|
||||
</NIC>
|
||||
</COMPUTE>
|
@ -1,20 +0,0 @@
|
||||
<INSTANCE_TYPE_COLLECTION>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/large" name="large">
|
||||
<ID>large</ID>
|
||||
<NAME>large</NAME>
|
||||
<CPU>8</CPU>
|
||||
<MEMORY>8192</MEMORY>
|
||||
</INSTANCE_TYPE>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/medium" name="medium">
|
||||
<ID>medium</ID>
|
||||
<NAME>medium</NAME>
|
||||
<CPU>4</CPU>
|
||||
<MEMORY>4096</MEMORY>
|
||||
</INSTANCE_TYPE>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small" name="small">
|
||||
<ID>small</ID>
|
||||
<NAME>small</NAME>
|
||||
<CPU>1</CPU>
|
||||
<MEMORY>1024</MEMORY>
|
||||
</INSTANCE_TYPE>
|
||||
</INSTANCE_TYPE_COLLECTION>
|
@ -1,5 +0,0 @@
|
||||
<INSTANCE_TYPE_COLLECTION>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/large" name="large"/>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/medium" name="medium"/>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/small" name="small"/>
|
||||
</INSTANCE_TYPE_COLLECTION>
|
@ -1 +0,0 @@
|
||||
<NETWORK_COLLECTION></NETWORK_COLLECTION>
|
@ -1,11 +0,0 @@
|
||||
<NETWORK href="http://localhost:4567/network/0">
|
||||
<ID>0</ID>
|
||||
<NAME>Network</NAME>
|
||||
<USER href="http://localhost:4567/user/2" name="my_first_occi_user"/>
|
||||
<GROUP>oneadmin</GROUP>
|
||||
<DESCRIPTION>Network of the user my_first_occi_user</DESCRIPTION>
|
||||
<ADDRESS>192.168.1.1</ADDRESS>
|
||||
<SIZE>125</SIZE>
|
||||
<USED_LEASES>0</USED_LEASES>
|
||||
<PUBLIC>NO</PUBLIC>
|
||||
</NETWORK>
|
@ -1,11 +0,0 @@
|
||||
<NETWORK href="http://localhost:4567/network/1">
|
||||
<ID>1</ID>
|
||||
<NAME>Network2</NAME>
|
||||
<USER href="http://localhost:4567/user/3" name="my_second_occi_user"/>
|
||||
<GROUP>users</GROUP>
|
||||
<DESCRIPTION>Network of the user my_second_occi_user</DESCRIPTION>
|
||||
<ADDRESS>192.168.2.1</ADDRESS>
|
||||
<SIZE>125</SIZE>
|
||||
<USED_LEASES>0</USED_LEASES>
|
||||
<PUBLIC>NO</PUBLIC>
|
||||
</NETWORK>
|
7
src/cloud/occi/test/fixtures/root.xml
vendored
7
src/cloud/occi/test/fixtures/root.xml
vendored
@ -1,7 +0,0 @@
|
||||
<COLLECTIONS>
|
||||
<COMPUTE_COLLECTION href="http://localhost:4567/compute"/>
|
||||
<INSTANCE_TYPE_COLLECTION href="http://localhost:4567/instance_type"/>
|
||||
<NETWORK_COLLECTION href="http://localhost:4567/network"/>
|
||||
<STORAGE_COLLECTION href="http://localhost:4567/storage"/>
|
||||
<USER_COLLECTION href="http://localhost:4567/user"/>
|
||||
</COLLECTIONS>
|
@ -1 +0,0 @@
|
||||
<STORAGE_COLLECTION></STORAGE_COLLECTION>
|
@ -1,13 +0,0 @@
|
||||
<STORAGE href="http://localhost:4567/storage/0">
|
||||
<ID>0</ID>
|
||||
<NAME>Storage</NAME>
|
||||
<USER href="http://localhost:4567/user/2" name="my_first_occi_user"/>
|
||||
<GROUP>oneadmin</GROUP>
|
||||
<STATE>READY</STATE>
|
||||
<TYPE>DATABLOCK</TYPE>
|
||||
<DESCRIPTION>Storage of the user my_first_occi_user</DESCRIPTION>
|
||||
<SIZE>100</SIZE>
|
||||
<FSTYPE>ext3</FSTYPE>
|
||||
<PUBLIC>NO</PUBLIC>
|
||||
<PERSISTENT>NO</PERSISTENT>
|
||||
</STORAGE>
|
@ -1,13 +0,0 @@
|
||||
<STORAGE href="http://localhost:4567/storage/1">
|
||||
<ID>1</ID>
|
||||
<NAME>Storage2</NAME>
|
||||
<USER href="http://localhost:4567/user/3" name="my_second_occi_user"/>
|
||||
<GROUP>users</GROUP>
|
||||
<STATE>READY</STATE>
|
||||
<TYPE>DATABLOCK</TYPE>
|
||||
<DESCRIPTION>Storage of the user my_second_occi_user</DESCRIPTION>
|
||||
<SIZE>100</SIZE>
|
||||
<FSTYPE>ext3</FSTYPE>
|
||||
<PUBLIC>NO</PUBLIC>
|
||||
<PERSISTENT>NO</PERSISTENT>
|
||||
</STORAGE>
|
1
src/cloud/occi/test/fixtures/user/user.xml
vendored
1
src/cloud/occi/test/fixtures/user/user.xml
vendored
@ -1 +0,0 @@
|
||||
<USER href="http://localhost:4567/user/0"><ID>0</ID><NAME>oneadmin</NAME><QUOTA><CPU>0</CPU><MEMORY>0</MEMORY><NUM_VMS>0</NUM_VMS><STORAGE>0</STORAGE></QUOTA><USAGE><CPU>0</CPU><MEMORY>0</MEMORY><NUM_VMS>0</NUM_VMS><STORAGE>0</STORAGE></USAGE></USER>
|
@ -1 +0,0 @@
|
||||
<USER_COLLECTION><USER href="http://localhost:4567/user/0" name="oneadmin"/><USER href="http://localhost:4567/user/1" name="my_first_occi_user"/></USER_COLLECTION>
|
@ -1 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0"><ID>0</ID><CPU>1</CPU><MEMORY>512</MEMORY><NAME>one-0</NAME><STATE>ACTIVE</STATE><DISK id="0"><STORAGE href="http://localhost:4567/storage/0" name="first_image"/><TYPE>DISK</TYPE><TARGET>hda</TARGET></DISK><DISK id="1"><STORAGE href="http://localhost:4567/storage/1" name="second_image"/><TYPE>DISK</TYPE><TARGET>hde</TARGET></DISK></COMPUTE>
|
@ -1 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0"><ID>0</ID><CPU>1</CPU><MEMORY>512</MEMORY><NAME>one-0</NAME><STATE>SUSPENDED</STATE><DISK id="0"><STORAGE href="http://localhost:4567/storage/0" name="first_image"/><SAVE_AS name="save_as1"/><TYPE>DISK</TYPE><TARGET>hda</TARGET></DISK><DISK id="1"><STORAGE href="http://localhost:4567/storage/1" name="second_image"/><TYPE>DISK</TYPE><TARGET>hde</TARGET></DISK></COMPUTE>
|
@ -1 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0"><ID>0</ID><CPU>1</CPU><MEMORY>512</MEMORY><NAME>one-0</NAME><STATE>ACTIVE</STATE><DISK id="0"><STORAGE href="http://localhost:4567/storage/0" name="first_image"/><SAVE_AS name="save_as1"/><TYPE>DISK</TYPE><TARGET>hda</TARGET></DISK><DISK id="1"><STORAGE href="http://localhost:4567/storage/1" name="second_image"/><TYPE>DISK</TYPE><TARGET>hde</TARGET></DISK></COMPUTE>
|
@ -1 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0"><ID>0</ID><CPU>1</CPU><MEMORY>512</MEMORY><NAME>one-0</NAME><STATE>ACTIVE</STATE><DISK id="0"><STORAGE href="http://localhost:4567/storage/0" name="first_image"/><TYPE>DISK</TYPE><TARGET>hda</TARGET></DISK><DISK id="1"><SAVE_AS name="save_as2"/><STORAGE href="http://localhost:4567/storage/1" name="second_image"/><TYPE>DISK</TYPE><TARGET>hde</TARGET></DISK></COMPUTE>
|
@ -1 +0,0 @@
|
||||
<COMPUTE href="http://localhost:4567/compute/0"><ID>0</ID><CPU>1</CPU><MEMORY>512</MEMORY><NAME>one-0</NAME><STATE>ACTIVE</STATE><DISK id="0"><STORAGE href="http://localhost:4567/storage/0" name="first_image"/><SAVE_AS name="save_as1"/><TYPE>DISK</TYPE><TARGET>hda</TARGET></DISK><DISK id="1"><STORAGE href="http://localhost:4567/storage/1" name="second_image"/><SAVE_AS name="save_as2"/><TYPE>DISK</TYPE><TARGET>hde</TARGET></DISK></COMPUTE>
|
@ -1,283 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
# The following methods are helpers defined in spec_helper
|
||||
# - compare_xml
|
||||
# - get_fixture
|
||||
# - network_template
|
||||
# - storage_template
|
||||
# - compute_template
|
||||
|
||||
describe 'OCCI tests' do
|
||||
before(:all) do
|
||||
@user_oneadmin = "my_first_occi_user"
|
||||
`oneuser create #{@user_oneadmin} my_pass`.scan(/^ID: (\d+)/) { |uid|
|
||||
`oneuser show #{uid.first}`.scan(/PASSWORD\s*:\s*(\w*)/) { |password|
|
||||
@user_pass = password.first.strip
|
||||
}
|
||||
|
||||
`oneuser chgrp #{uid.first} 0`
|
||||
}
|
||||
|
||||
@user_users = "my_second_occi_user"
|
||||
`oneuser create #{@user_users} my_pass2`.scan(/^ID: (\d+)/) { |uid|
|
||||
`oneuser show #{uid.first}`.scan(/PASSWORD\s*:\s*(\w*)/) { |password|
|
||||
@user_pass2 = password.first.strip
|
||||
}
|
||||
}
|
||||
|
||||
# Define BRIDGE attirbute in network.erb, otherwise the NETWORK creation will
|
||||
`sed -i.bck "s%^#\\(BRIDGE = \\).*$%\\1 br0%" $ONE_LOCATION/etc/occi_templates/network.erb`
|
||||
end
|
||||
|
||||
describe "with a user of the oneadmin group" do
|
||||
before(:each) do
|
||||
basic_authorize(@user_oneadmin, @user_pass)
|
||||
end
|
||||
|
||||
it "should retrieve the list of collections" do
|
||||
get '/'
|
||||
compare_xml(last_response.body, get_fixture('/root.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should retrieve the list of INSTANCE_TYPEs" do
|
||||
get '/instance_type'
|
||||
compare_xml(last_response.body, get_fixture('/instance_type/list.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should retrieve the extended list of INSTANCE_TYPEs" do
|
||||
get '/instance_type', {'verbose'=>true}
|
||||
compare_xml(last_response.body, get_fixture('/instance_type/extended.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
context "for NETWORK" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/network'
|
||||
compare_xml(last_response.body, get_fixture('/network/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new NETWORK" do
|
||||
network = {
|
||||
:name => "Network",
|
||||
:description => "Network of the user #{@user_oneadmin}",
|
||||
:address => "192.168.1.0",
|
||||
:size => "100",
|
||||
:pubic => "YES"
|
||||
}
|
||||
|
||||
post '/network', network_template(network)
|
||||
compare_xml(last_response.body, get_fixture('/network/first_net.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the NETWORK with ID 0" do
|
||||
get '/network/0'
|
||||
compare_xml(last_response.body, get_fixture('/network/first_net.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
context "for STORAGE" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/storage'
|
||||
compare_xml(last_response.body, get_fixture('/storage/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new STORAGE, type DATABLOCK. This request waits until the IMAGE is ready in OpenNebula" do
|
||||
storage = {
|
||||
:name => "Storage",
|
||||
:description => "Storage of the user #{@user_oneadmin}",
|
||||
:type => "DATABLOCK",
|
||||
:size => "100",
|
||||
:fstype => "ext3"
|
||||
}
|
||||
|
||||
post '/storage', {'occixml' => storage_template(storage)}
|
||||
compare_xml(last_response.body, get_fixture('/storage/first_storage.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the STORAGE with ID 0" do
|
||||
get '/storage/0'
|
||||
compare_xml(last_response.body, get_fixture('/storage/first_storage.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
context "for COMPUTE" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/compute'
|
||||
compare_xml(last_response.body, get_fixture('/compute/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new COMPUTE using the previous NETWORK (ID=0) and STORAGE(ID=0)" do
|
||||
compute = {
|
||||
:name => "Compute",
|
||||
:instance_type => "small",
|
||||
:disk => [ {:storage => '0'} ],
|
||||
:nic => [ {:network => '0'} ]
|
||||
}
|
||||
|
||||
post '/compute', compute_template(compute)
|
||||
compare_xml(last_response.body, get_fixture('/compute/first_compute.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the COMPUTE with ID 0" do
|
||||
get '/compute/0'
|
||||
compare_xml(last_response.body, get_fixture('/compute/first_compute.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should terminate (DONE) the COMPUTE with ID 0" do
|
||||
compute = {
|
||||
:id => "0",
|
||||
:state => "DONE"
|
||||
}
|
||||
|
||||
put '/compute/0', compute_action(compute)
|
||||
compare_xml(last_response.body, get_fixture('/compute/first_compute_done.xml'))
|
||||
last_response.status.should == 202
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a user of the users group" do
|
||||
before(:each) do
|
||||
basic_authorize(@user_users, @user_pass2)
|
||||
end
|
||||
|
||||
it "should retrieve the list of collections" do
|
||||
get '/'
|
||||
compare_xml(last_response.body, get_fixture('/root.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should retrieve the list of INSTANCE_TYPEs" do
|
||||
get '/instance_type'
|
||||
compare_xml(last_response.body, get_fixture('/instance_type/list.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should retrieve the extended list of INSTANCE_TYPEs" do
|
||||
get '/instance_type', {'verbose'=>true}
|
||||
compare_xml(last_response.body, get_fixture('/instance_type/extended.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
context "for NETWORK" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/network'
|
||||
compare_xml(last_response.body, get_fixture('/network/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new NETWORK" do
|
||||
network = {
|
||||
:name => "Network2",
|
||||
:description => "Network of the user #{@user_users}",
|
||||
:address => "192.168.2.0",
|
||||
:size => "100",
|
||||
:pubic => "YES"
|
||||
}
|
||||
|
||||
post '/network', network_template(network)
|
||||
compare_xml(last_response.body, get_fixture('/network/second_net.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the NETWORK with ID 1" do
|
||||
get '/network/1'
|
||||
compare_xml(last_response.body, get_fixture('/network/second_net.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
context "for STORAGE" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/storage'
|
||||
compare_xml(last_response.body, get_fixture('/storage/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new STORAGE, type DATABLOCK. This request waits until the IMAGE is ready in OpenNebula" do
|
||||
storage = {
|
||||
:name => "Storage2",
|
||||
:description => "Storage of the user #{@user_users}",
|
||||
:type => "DATABLOCK",
|
||||
:size => "100",
|
||||
:fstype => "ext3"
|
||||
}
|
||||
|
||||
post '/storage', {'occixml' => storage_template(storage)}
|
||||
compare_xml(last_response.body, get_fixture('/storage/second_storage.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the STORAGE with ID 1" do
|
||||
get '/storage/1'
|
||||
compare_xml(last_response.body, get_fixture('/storage/second_storage.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
context "for COMPUTE" do
|
||||
it "should retrieve the empty list" do
|
||||
get '/compute'
|
||||
compare_xml(last_response.body, get_fixture('/compute/empty.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should create a new COMPUTE using the previous NETWORK (ID=1) and STORAGE(ID=1)" do
|
||||
compute = {
|
||||
:name => "Compute2",
|
||||
:instance_type => "small",
|
||||
:disk => [ {:storage => '1'} ],
|
||||
:nic => [ {:network => '1'} ]
|
||||
}
|
||||
|
||||
post '/compute', compute_template(compute)
|
||||
compare_xml(last_response.body, get_fixture('/compute/second_compute.xml'))
|
||||
last_response.status.should == 201
|
||||
end
|
||||
|
||||
it "should retrieve the COMPUTE with ID 1" do
|
||||
get '/compute/1'
|
||||
compare_xml(last_response.body, get_fixture('/compute/second_compute.xml'))
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should terminate (DONE) the COMPUTE with ID 1" do
|
||||
compute = {
|
||||
:id => "1",
|
||||
:state => "DONE"
|
||||
}
|
||||
|
||||
put '/compute/1', compute_action(compute)
|
||||
compare_xml(last_response.body, get_fixture('/compute/second_compute_done.xml'))
|
||||
last_response.status.should == 202
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,4 +0,0 @@
|
||||
--colour
|
||||
--format progress
|
||||
--loadby mtime
|
||||
--reverse
|
@ -1,193 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
FIXTURES_PATH = File.join(File.dirname(__FILE__),'../fixtures')
|
||||
TEMPLATES_PATH = File.join(File.dirname(__FILE__),'../templates')
|
||||
|
||||
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
||||
|
||||
# Load the testing libraries
|
||||
require 'rubygems'
|
||||
require 'rspec'
|
||||
require 'rack/test'
|
||||
|
||||
require 'rexml/document'
|
||||
|
||||
# Load the Sinatra app
|
||||
require 'occi-server'
|
||||
|
||||
# Make Rack::Test available to all spec contexts
|
||||
RSpec.configure do |conf|
|
||||
conf.include Rack::Test::Methods
|
||||
end
|
||||
|
||||
# Set the Sinatra environment
|
||||
set :environment, :test
|
||||
|
||||
# Add an app method for RSpec
|
||||
def app
|
||||
Sinatra::Application
|
||||
end
|
||||
|
||||
|
||||
|
||||
def get_fixture(path)
|
||||
File.read(FIXTURES_PATH + path).strip
|
||||
end
|
||||
|
||||
|
||||
def compare_xml(a, b)
|
||||
a = REXML::Document.new(a.to_s)
|
||||
b = REXML::Document.new(b.to_s)
|
||||
|
||||
normalized = Class.new(REXML::Formatters::Pretty) do
|
||||
def write_text(node, output)
|
||||
super(node.to_s.strip, output)
|
||||
end
|
||||
end
|
||||
|
||||
normalized.new(indentation=0,ie_hack=false).write(node=a, a_normalized='')
|
||||
normalized.new(indentation=0,ie_hack=false).write(node=b, b_normalized='')
|
||||
|
||||
a_normalized.should == b_normalized
|
||||
end
|
||||
|
||||
|
||||
OCCI_NETWORK = %q{
|
||||
<NETWORK>
|
||||
<% if hash[:name] %>
|
||||
<NAME><%= hash[:name] %></NAME>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:description] %>
|
||||
<DESCRIPTION><%= hash[:description] %></DESCRIPTION>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:address] %>
|
||||
<ADDRESS><%= hash[:address] %></ADDRESS>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:size] %>
|
||||
<SIZE><%= hash[:size] %></SIZE>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:public] %>
|
||||
<PUBLIC><%= hash[:public] %></PUBLIC>
|
||||
<% end %>
|
||||
</NETWORK>
|
||||
}
|
||||
|
||||
def network_template(hash)
|
||||
ERB.new(OCCI_NETWORK).result(binding)
|
||||
end
|
||||
|
||||
OCCI_IMAGE = %q{
|
||||
<STORAGE>
|
||||
<% if hash[:name] %>
|
||||
<NAME><%= hash[:name] %></NAME>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:type] %>
|
||||
<TYPE><%= hash[:type] %></TYPE>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:description] %>
|
||||
<DESCRIPTION><%= hash[:description] %></DESCRIPTION>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:size] %>
|
||||
<SIZE><%= hash[:size] %></SIZE>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:fstype] %>
|
||||
<FSTYPE><%= hash[:fstype] %></FSTYPE>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:public] %>
|
||||
<PUBLIC><%= hash[:public] %></PUBLIC>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:persistent] %>
|
||||
<PERSISTENT><%= hash[:persistent] %></PERSISTENT>
|
||||
<% end %>
|
||||
</STORAGE>
|
||||
}
|
||||
|
||||
def storage_template(hash)
|
||||
ERB.new(OCCI_IMAGE).result(binding)
|
||||
end
|
||||
|
||||
OCCI_VM = %q{
|
||||
<COMPUTE>
|
||||
<% if hash[:name] %>
|
||||
<NAME><%= hash[:name] %></NAME>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:instance_type] %>
|
||||
<INSTANCE_TYPE href="http://localhost:4567/instance_type/<%= hash[:instance_type] %>"/>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:disk] %>
|
||||
<% hash[:disk].each { |disk| %>
|
||||
<DISK>
|
||||
<% if disk[:storage] %>
|
||||
<STORAGE href="http://localhost:4567/storage/<%= disk[:storage] %>"/>
|
||||
<% end %>
|
||||
</DISK>
|
||||
<% } %>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:nic] %>
|
||||
<% hash[:nic].each { |nic| %>
|
||||
<NIC>
|
||||
<% if nic[:network] %>
|
||||
<NETWORK href="http://localhost:4567/network/<%= nic[:network] %>"/>
|
||||
<% end %>
|
||||
<% if nic[:ip] %>
|
||||
<IP><%= nic[:ip] %></IP>
|
||||
<% end %>
|
||||
</NIC>
|
||||
<% } %>
|
||||
<% end %>
|
||||
|
||||
<% if hash[:context] %>
|
||||
<CONTEXT>
|
||||
<% hash[:context].each { |key, value| %>
|
||||
<<%= key.to_s.upcase %>><%= value %></<%= key.to_s.upcase %>>
|
||||
<% } %>
|
||||
</CONTEXT>
|
||||
<% end %>
|
||||
</COMPUTE>
|
||||
}
|
||||
|
||||
OCCI_VM_ACTION = %q{
|
||||
<COMPUTE>
|
||||
<% if hash[:id] %>
|
||||
<ID><%= hash[:id] %></ID>
|
||||
<% end %>
|
||||
<% if hash[:state] %>
|
||||
<STATE><%= hash[:state] %></STATE>
|
||||
<% end %>
|
||||
</COMPUTE>
|
||||
}
|
||||
|
||||
def compute_template(hash)
|
||||
ERB.new(OCCI_VM).result(binding)
|
||||
end
|
||||
|
||||
def compute_action(hash)
|
||||
ERB.new(OCCI_VM_ACTION).result(binding)
|
||||
end
|
@ -1,73 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe 'OCCI User tests' do
|
||||
before(:all) do
|
||||
@username_1 = "my_first_occi_user"
|
||||
@userpass_1 = "my_first_occi_pass"
|
||||
`oneuser create #{@username_1} #{@userpass_1}`
|
||||
end
|
||||
|
||||
it "should list the user collection" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
get '/user'
|
||||
|
||||
last_response.status.should eql(200)
|
||||
|
||||
xml_body = last_response.body
|
||||
|
||||
user_collection = File.read(FIXTURES_PATH + '/user/user_collection.xml')
|
||||
|
||||
xml_body.strip.should eql(user_collection.strip)
|
||||
end
|
||||
|
||||
|
||||
it "should check the error if the user collection is retrieved by a non oneadmin user" do
|
||||
basic_authorize('my_first_occi_user','c08c5a6c535b6060b7b2af34e0d2f0ffb7e63b28')
|
||||
get '/user'
|
||||
|
||||
last_response.status.should eql(403)
|
||||
end
|
||||
|
||||
it "should show the user information, no quotas and no usage" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
get '/user/0'
|
||||
|
||||
last_response.status.should eql(200)
|
||||
|
||||
xml_body = last_response.body
|
||||
|
||||
user = File.read(FIXTURES_PATH + '/user/user.xml')
|
||||
|
||||
xml_body.strip.should eql(user.strip)
|
||||
end
|
||||
|
||||
it "should get a 404 error when trying to get a non existing user" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
get '/user/99'
|
||||
|
||||
last_response.status.should eql(404)
|
||||
end
|
||||
|
||||
it "should get a 403 error when trying to get a different user" do
|
||||
basic_authorize('my_first_occi_user','c08c5a6c535b6060b7b2af34e0d2f0ffb7e63b28')
|
||||
get '/user/0'
|
||||
|
||||
last_response.status.should eql(403)
|
||||
end
|
||||
end
|
@ -1,77 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe 'OCCI User tests' do
|
||||
# PREREQUISITES
|
||||
# OpenNebula installed and running using dummy drivers
|
||||
|
||||
before(:all) do
|
||||
# Starting the drivers
|
||||
sleep 2
|
||||
|
||||
system("onehost create myhost im_dummy vmm_dummy tm_dummy").should == true
|
||||
|
||||
system("oneimage create #{TEMPLATES_PATH+"/image1.template"}").should == true
|
||||
system("oneimage create #{TEMPLATES_PATH+"/image2.template"}").should == true
|
||||
|
||||
# Copying the images
|
||||
sleep 1
|
||||
|
||||
system("onevm create #{TEMPLATES_PATH+"/vm.template"}").should == true
|
||||
system("onevm deploy 0 0").should == true
|
||||
end
|
||||
|
||||
it "should show the new compute" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
get '/compute/0'
|
||||
|
||||
last_response.body.should == File.read(FIXTURES_PATH+"/vm_save_as/newcompute.xml")
|
||||
end
|
||||
|
||||
it "should get an error when trying to change the resource state and save a disk " do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
body = File.read(FIXTURES_PATH+"/vm_save_as/save_a_disk_and_change_state.xml")
|
||||
put '/compute/0', body
|
||||
|
||||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
it "should get an error when trying to save two disks" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
body = File.read(FIXTURES_PATH+"/vm_save_as/save_two_disks.xml")
|
||||
put '/compute/0', body
|
||||
|
||||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
it "should save the first disk" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
body = File.read(FIXTURES_PATH+"/vm_save_as/save_first_disk.xml")
|
||||
put '/compute/0', body
|
||||
|
||||
last_response.status.should == 202
|
||||
end
|
||||
|
||||
it "should save the second disk" do
|
||||
basic_authorize('oneadmin','4478db59d30855454ece114e8ccfa5563d21c9bd')
|
||||
body = File.read(FIXTURES_PATH+"/vm_save_as/save_second_disk.xml")
|
||||
put '/compute/0', body
|
||||
|
||||
last_response.status.should == 202
|
||||
end
|
||||
end
|
@ -1,2 +0,0 @@
|
||||
NAME = first_image
|
||||
PATH = /etc/hosts
|
@ -1,3 +0,0 @@
|
||||
NAME = second_image
|
||||
PATH = /etc/hosts
|
||||
TYPE = DATABLOCK
|
@ -1,10 +0,0 @@
|
||||
CPU = 1
|
||||
MEMORY = 512
|
||||
|
||||
DISK = [
|
||||
IMAGE_ID = 0
|
||||
]
|
||||
|
||||
DISK = [
|
||||
IMAGE_ID = 1
|
||||
]
|
@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
if [ -z $ONE_LOCATION ]; then
|
||||
echo "ONE_LOCATION not defined."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
VAR_LOCATION="$ONE_LOCATION/var"
|
||||
|
||||
if [ "$(ls -A $VAR_LOCATION)" ]; then
|
||||
echo "$VAR_LOCATION is not empty."
|
||||
# exit -1
|
||||
fi
|
||||
|
||||
for j in `ls ./spec/*_spec.rb` ; do
|
||||
find $VAR_LOCATION -mindepth 1 ! \( -path "$VAR_LOCATION/remotes*" -o -path "$VAR_LOCATION/images" \) -delete
|
||||
|
||||
PID=$$
|
||||
|
||||
oned -f &
|
||||
sleep 2s;
|
||||
|
||||
rspec $j -f s
|
||||
CODE=$?
|
||||
|
||||
pkill -P $PID oned
|
||||
sleep 2s;
|
||||
pkill -9 -P $PID oned
|
||||
|
||||
if [ $CODE != 0 ] ; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user