Class: OpenNebula::BackupJob

Inherits:
PoolElement show all
Defined in:
lib/opennebula/backupjob.rb

Overview

Class for representing a Backup Job object

Constant Summary collapse

BACKUPJOB_METHODS =

Constants and Class Methods

{
    :allocate    => 'backupjob.allocate',
    :info        => 'backupjob.info',
    :update      => 'backupjob.update',
    :delete      => 'backupjob.delete',
    :chown       => 'backupjob.chown',
    :chmod       => 'backupjob.chmod',
    :clone       => 'backupjob.clone',
    :rename      => 'backupjob.rename',
    :lock        => 'backupjob.lock',
    :unlock      => 'backupjob.unlock',
    :backup      => 'backupjob.backup',
    :cancel      => 'backupjob.cancel',
    :retry       => 'backupjob.retry',
    :priority    => 'backupjob.priority',
    :schedadd    => 'backupjob.schedadd',
    :scheddelete => 'backupjob.scheddelete',
    :schedupdate => 'backupjob.schedupdate'
}

Instance Attribute Summary

Attributes inherited from PoolElement

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, new_with_id, #replace, #to_str

Methods inherited from XMLElement

#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?

Constructor Details

#initialize(xml, client) ⇒ BackupJob

Class constructor



67
68
69
70
71
72
73
# File 'lib/opennebula/backupjob.rb', line 67

def initialize(xml, client)
    LockableExt.make_lockable(self, BACKUPJOB_METHODS)

    super(xml, client)

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

Creates a BackupJob description with just its identifier this method should be used to create plain BackupJob objects. id the id of the user

Example:

bj = BackupJob.new(BackupJob.build_xml(3),rpc_client)


56
57
58
59
60
61
62
63
64
# File 'lib/opennebula/backupjob.rb', line 56

def self.build_xml(pe_id = nil)
    if pe_id
        obj_xml = "<BACKUPJOB><ID>#{pe_id}</ID></BACKUPJOB>"
    else
        obj_xml = '<BACKUPJOB></BACKUPJOB>'
    end

    XMLElement.build_xml(obj_xml, 'BACKUPJOB')
end

Instance Method Details

#allocate(description) ⇒ nil, OpenNebula::Error

Allocates a new Backup Job in OpenNebula

Parameters:

  • description (String)

    The contents of the BackupJob.

Returns:



104
105
106
# File 'lib/opennebula/backupjob.rb', line 104

def allocate(description)
    super(BACKUPJOB_METHODS[:allocate], description)
end

#backupnil, OpenNebula::Error

Starts the Backup Job

Returns:



173
174
175
# File 'lib/opennebula/backupjob.rb', line 173

def backup
    call(BACKUPJOB_METHODS[:backup], @pe_id)
end

#cancelnil, OpenNebula::Error

Cancel pending Backup Job, removing VMs from waiting list

Returns:



181
182
183
# File 'lib/opennebula/backupjob.rb', line 181

def cancel
    call(BACKUPJOB_METHODS[:cancel], @pe_id)
end

#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error

Changes the Backup Job permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

rubocop:disable Metrics/ParameterLists

Returns:



152
153
154
155
156
# File 'lib/opennebula/backupjob.rb', line 152

def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
          other_m, other_a)
    call(BACKUPJOB_METHODS[:chmod], @pe_id, owner_u, owner_m, owner_a, group_u,
         group_m, group_a, other_u, other_m, other_a)
end

#chmod_octet(octet) ⇒ nil, OpenNebula::Error

Changes the Backup Job permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



142
143
144
# File 'lib/opennebula/backupjob.rb', line 142

def chmod_octet(octet)
    super(BACKUPJOB_METHODS[:chmod], octet)
end

#chown(uid, gid) ⇒ Object

Changes the owner/group

uid

Integer the new owner id. Set to -1 to leave the current one

gid

Integer the new group id. Set to -1 to leave the current one

return

nil in case of success or an Error object



132
133
134
# File 'lib/opennebula/backupjob.rb', line 132

def chown(uid, gid)
    super(BACKUPJOB_METHODS[:chown], uid, gid)
end

#deletenil, OpenNebula::Error

Deletes the BackupJob

Returns:



112
113
114
# File 'lib/opennebula/backupjob.rb', line 112

def delete
    call(BACKUPJOB_METHODS[:delete], @pe_id)
end

#gidObject

Returns the group identifier

return

Integer the element’s group ID



236
237
238
# File 'lib/opennebula/backupjob.rb', line 236

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given Backup Job.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/opennebula/backupjob.rb', line 80

def info
    return Error.new('ID not defined') unless @pe_id

    rc = @client.call(BACKUPJOB_METHODS[:info], @pe_id)

    if !OpenNebula.is_error?(rc)
        initialize_xml(rc, 'BACKUPJOB')
        rc = nil

        @pe_id = self['ID'].to_i if self['ID']
        @name  = self['NAME'] if self['NAME']
    end

    rc
end

#owner_idObject



240
241
242
# File 'lib/opennebula/backupjob.rb', line 240

def owner_id
    self['UID'].to_i
end

#priority(pr) ⇒ nil, OpenNebula::Error

Change priority of Backup Job

Returns:



197
198
199
# File 'lib/opennebula/backupjob.rb', line 197

def priority(pr)
    call(BACKUPJOB_METHODS[:priority], @pe_id, pr)
end

#public?Boolean

Returns:

  • (Boolean)


244
245
246
# File 'lib/opennebula/backupjob.rb', line 244

def public?
    self['PERMISSIONS/GROUP_U'] == '1' || self['PERMISSIONS/OTHER_U'] == '1'
end

#rename(name) ⇒ nil, OpenNebula::Error

Renames this Backup Job

Parameters:

  • name (String)

    New name for the Backup Job.

Returns:



165
166
167
# File 'lib/opennebula/backupjob.rb', line 165

def rename(name)
    call(BACKUPJOB_METHODS[:rename], @pe_id, name)
end

#retrynil, OpenNebula::Error

Retry backup for VMs in error list

Returns:



189
190
191
# File 'lib/opennebula/backupjob.rb', line 189

def retry
    call(BACKUPJOB_METHODS[:retry], @pe_id)
end

#sched_action_add(sched_template) ⇒ nil, OpenNebula::Error

Add Scheduled action

Parameters:

  • sched_template (String)

    Template with SCHED_ACTIONs

Returns:



206
207
208
# File 'lib/opennebula/backupjob.rb', line 206

def sched_action_add(sched_template)
    call(BACKUPJOB_METHODS[:schedadd], @pe_id, sched_template)
end

#sched_action_delete(sched_id) ⇒ nil, OpenNebula::Error

Delete Scheduled Action

Parameters:

  • sched_id (Int)

    id of the SCHED_ACTION

Returns:



215
216
217
# File 'lib/opennebula/backupjob.rb', line 215

def sched_action_delete(sched_id)
    call(BACKUPJOB_METHODS[:scheddelete], @pe_id, sched_id.to_i)
end

#sched_action_update(sched_id, sched_template) ⇒ nil, OpenNebula::Error

Update Scheduled Action

Parameters:

  • sched_id (Int)

    id of the SCHED_ACTION

  • sched_template (String)

    Template containing a SCHED_ACTION

Returns:



225
226
227
228
# File 'lib/opennebula/backupjob.rb', line 225

def sched_action_update(sched_id, sched_template)
    call(BACKUPJOB_METHODS[:schedupdate], @pe_id,
         sched_id.to_i, sched_template)
end

#update(new_template, append = false) ⇒ nil, OpenNebula::Error

Replaces the Backup Job contents

Parameters:

  • new_template (String)

    New template contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



124
125
126
# File 'lib/opennebula/backupjob.rb', line 124

def update(new_template, append = false)
    super(BACKUPJOB_METHODS[:update], new_template, append ? 1 : 0)
end