Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F #1414: delete parameter from template #3165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/ImageTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class ImageTemplate : public Template
return Template::check_restricted(rs_attr, restricted);
}

virtual bool is_restricted(const string& attr)
{
return Template::is_restricted(attr, restricted);
}

static void parse_restricted(vector<const SingleAttribute *>& ra)
{
Template::parse_restricted(ra, restricted);
Expand Down
11 changes: 11 additions & 0 deletions include/PoolObjectSQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ class PoolObjectSQL : public ObjectSQL, public ObjectXML
*/
virtual int append_template(const string& tmpl_str, bool keep_restricted, string& error);

/**
* Delete attributes from this object's template. Object should be updated
* after calling this method
* @param attributes attributes to delete
* @param delete_restricted If true, the restricted attributes of the
* current template can be deleted
* @param error string describing the error if any
* @return 0 on success
*/
virtual int delete_template(const string& attributes, bool delete_restricted, string& error);

/**
* Fills a auth class to perform an authZ/authN request based on the object
* attributes
Expand Down
3 changes: 3 additions & 0 deletions include/RequestManagerUpdateTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class RequestManagerUpdateTemplate: public Request

virtual int append_template(PoolObjectSQL * object, const string & tmpl,
const RequestAttributes &att, string &error_str);

virtual int delete_template(PoolObjectSQL * object, const string & attributes,
const RequestAttributes &att, string &error_str);
};

/* ------------------------------------------------------------------------- */
Expand Down
14 changes: 14 additions & 0 deletions include/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ class Template
return false;
}

/**
* Check if an attribute is restricted
* @param attr the attribute
*
* @return true if the attribute is restricted
*/
virtual bool is_restricted(const string& attr)
{
return false;
}

/**
* @return true if template is empty
*/
Expand Down Expand Up @@ -498,6 +509,9 @@ class Template

bool check_restricted(string& rs_attr,
const std::map<std::string, std::set<std::string> >& ras);

bool is_restricted(const string& attr,
const std::map<std::string, std::set<std::string> >& ras);
/**
* Updates the xml root element name
*
Expand Down
10 changes: 10 additions & 0 deletions include/VirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,16 @@ class VirtualMachine : public PoolObjectSQL
int append_template(const string& tmpl_str, bool keep_restricted,
string& error);

/**
* Delete attributes from the *user template*.
* @param attributes attributes to delete
* @param delete_restricted If true, the restricted attributes of the
* current template can be deleted
* @param error string describing the error if any
* @return 0 on success
*/
int delete_template(const string& attributes, bool delete_restricted, string& error);

/**
* This function gets an attribute from the user template
* @param name of the attribute
Expand Down
5 changes: 5 additions & 0 deletions include/VirtualMachineTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class VirtualMachineTemplate : public Template
return Template::check_restricted(rs_attr, restricted);
}

virtual bool is_restricted(const string& attr)
{
return Template::is_restricted(attr, restricted);
}

static void parse_restricted(vector<const SingleAttribute *>& ra)
{
Template::parse_restricted(ra, restricted);
Expand Down
5 changes: 5 additions & 0 deletions include/VirtualNetworkTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class VirtualNetworkTemplate : public Template
return Template::check_restricted(rs_attr, restricted);
}

virtual bool is_restricted(const string& attr)
{
return Template::is_restricted(attr, restricted);
}

static void parse_restricted(vector<const SingleAttribute *>& ra)
{
Template::parse_restricted(ra, restricted);
Expand Down
26 changes: 22 additions & 4 deletions share/onegate/onegate
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ Available commands

$ onegate vm update [VMID] --data KEY=VALUE[\\nKEY2=VALUE2]

$ onegate vm update [VMID] --erase KEY

$ onegate vm ACTION VMID
$ onegate resume [VMID]
$ onegate stop [VMID]
Expand Down Expand Up @@ -526,6 +528,10 @@ OptionParser.new do |opts|
options[:data] = data
end

opts.on("-e", "--erase DATA", "Data to be removed from the VM") do |data|
options[:erase] = data
end

opts.on("-r", "--role ROLE", "Service role") do |role|
options[:role] = role
end
Expand Down Expand Up @@ -567,15 +573,27 @@ when "vm"
OneGate::VirtualMachine.print(json_hash)
end
when "update"
if !options[:data]
puts "You have to provide the data as a param (--data)"
if !options[:data] && !options[:erase]
puts "You have to provide the data as a param (--data, --erase)"
exit -1
end

data = {}

if options[:data]
data[:data] = options[:data]
data[:type] = 1
else
data[:data] = options[:erase]
data[:type] = 2
end

data = URI.encode_www_form(data)

if ARGV[2]
response = client.put("/vms/"+ARGV[2], options[:data])
response = client.put("/vms/" + ARGV[2], data)
else
response = client.put("/vm", options[:data])
response = client.put("/vm", data)
end

if CloudClient::is_error?(response)
Expand Down
21 changes: 21 additions & 0 deletions src/cli/one_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ module OpenNebulaHelper
:description => "Append new attributes to the current template"
}

DELETE_TEMPLATE = {
:name => "delete_template",
:large => "--delete-template list",
:description => "Comma separated attributes to delete " \
"from the current template.",
:format => String
}

# Command line VM template options
TEMPLATE_NAME_VM={
:name => 'name',
Expand Down Expand Up @@ -1183,6 +1191,19 @@ def OpenNebulaHelper.update_template_helper(append, id, resource, path, xpath, u
end
end

def OpenNebulaHelper.get_update(args, obj, options, xpath = 'TEMPLATE')
if options[:append]
{ :type => 1,
:data => append_template(args[0], obj, args[1], xpath) }
elsif options[:delete_template]
{ :type => 2,
:data => options[:delete_template] }
else
{ :type => 0,
:data => update_template(args[0], obj, args[1], xpath) }
end
end

def OpenNebulaHelper.editor_input(contents=nil)
require 'tempfile'

Expand Down
17 changes: 8 additions & 9 deletions src/cli/onecluster
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,17 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :clusterid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end

helper.set_client(options)
obj = helper.retrieve_resource(obj.id)

obj.update(str, options[:append])
obj = helper.retrieve_resource(obj.id)
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, type)
end
end

Expand Down
17 changes: 8 additions & 9 deletions src/cli/onedatastore
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,17 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :datastoreid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end

helper.set_client(options)
obj = helper.retrieve_resource(obj.id)

obj.update(str, options[:append])
obj = helper.retrieve_resource(obj.id)
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, type)
end
end

Expand Down
17 changes: 8 additions & 9 deletions src/cli/onegroup
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :groupid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end

helper.set_client(options)
obj = helper.retrieve_resource(obj.id)

obj.update(str, options[:append])
obj = helper.retrieve_resource(obj.id)
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, type)
end
end

Expand Down
19 changes: 9 additions & 10 deletions src/cli/onehost
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ CommandParser::CmdParser.new(ARGV) do
end
rc = host.allocate(args[0], options[:im], options[:vm], cid)
if !OpenNebula.is_error?(rc) && !options[:type].nil?
host.update(str, true)
host.update(str, 1)
end

rc
Expand Down Expand Up @@ -186,18 +186,17 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :hostid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'updated') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end

helper.set_client(options)
obj = helper.retrieve_resource(obj.id)

obj.update(str, options[:append])
obj = helper.retrieve_resource(obj.id)
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, type)
end
end

Expand Down
17 changes: 8 additions & 9 deletions src/cli/oneimage
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,17 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :imageid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end

helper.set_client(options)
obj = helper.retrieve_resource(obj.id)

obj.update(str, options[:append])
obj = helper.retrieve_resource(obj.id)
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, type)
end
end

Expand Down
13 changes: 6 additions & 7 deletions src/cli/onemarket
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :marketplaceid, [:file, nil],
:options => OpenNebulaHelper::APPEND do
:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, options[:append])
obj.update(str, type)
end
end

Expand Down
14 changes: 6 additions & 8 deletions src/cli/onemarketapp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ CommandParser::CmdParser.new(ARGV) do
EOT

command :update, update_desc, :appid, [:file, nil],
:options => OpenNebulaHelper::APPEND do

:options => [OpenNebulaHelper::APPEND,
OpenNebulaHelper::DELETE_TEMPLATE] do
helper.perform_action(args[0], options, 'modified') do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end
data = OpenNebulaHelper.get_update(args, obj, options)
str = data[:data]
type = data[:type]

obj.update(str, options[:append])
obj.update(str, type)
end
end

Expand Down
Loading