mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-19 06:50:07 +03:00
Feature #1304: Improve the Document type sanity check. The previous implementation rebuilt the internal XML, what could destroy unsaved changes
This commit is contained in:
parent
c3300ec136
commit
953a580f37
@ -108,7 +108,7 @@ module OpenNebula
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def delete()
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
return call(DOCUMENT_METHODS[:delete], @pe_id)
|
||||
@ -121,7 +121,7 @@ module OpenNebula
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def update(new_template)
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
super(DOCUMENT_METHODS[:update], new_template)
|
||||
@ -135,7 +135,7 @@ module OpenNebula
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chown(uid, gid)
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
super(DOCUMENT_METHODS[:chown], uid, gid)
|
||||
@ -148,7 +148,7 @@ module OpenNebula
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chmod_octet(octet)
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
super(DOCUMENT_METHODS[:chmod], octet)
|
||||
@ -161,7 +161,7 @@ module OpenNebula
|
||||
# otherwise
|
||||
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
||||
other_m, other_a)
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
super(DOCUMENT_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
||||
@ -175,7 +175,7 @@ module OpenNebula
|
||||
# @return [Integer, OpenNebula::Error] The new Document ID in case
|
||||
# of success, Error otherwise
|
||||
def clone(name)
|
||||
rc = info()
|
||||
rc = check_type()
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
@ -222,5 +222,27 @@ module OpenNebula
|
||||
|
||||
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
||||
end
|
||||
|
||||
def check_type()
|
||||
type = self['TYPE']
|
||||
|
||||
if type.nil? && @pe_id
|
||||
rc = @client.call(DOCUMENT_METHODS[:info], @pe_id)
|
||||
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
|
||||
xmldoc = XMLElement.new
|
||||
xmldoc.initialize_xml(rc, 'DOCUMENT')
|
||||
|
||||
type = xmldoc['TYPE']
|
||||
end
|
||||
|
||||
if !type.nil? && type.to_i != document_type
|
||||
return OpenNebula::Error.new(
|
||||
"[DocumentInfo] Error getting document [#{@pe_id}].")
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user