Class: OCCI::Backend::Dummy
- Inherits:
-
Object
- Object
- OCCI::Backend::Dummy
- Defined in:
- lib/occi/backend/dummy.rb
Overview
Constant Summary
- OPERATIONS =
Operation mappings
{}
Instance Method Summary (collapse)
-
- (Object) action_dummy(resource, parameters = nil)
---------------------------------------------------------------------------------------------------------------------.
- - (Object) compute_action_restart(compute, parameters = nil)
-
- (Object) compute_action_start(compute, parameters = nil)
ACTIONS ---------------------------------------------------------------------------------------------------------------------.
- - (Object) compute_action_stop(compute, parameters = nil)
- - (Object) compute_action_suspend(compute, parameters = nil)
-
- (Object) compute_deploy(compute)
TODO: register user defined mixins.
-
- (Dummy) initialize
constructor
A new instance of Dummy.
- - (Object) network_action_down(network, parameters = nil)
- - (Object) network_action_up(network, parameters = nil)
- - (Object) network_deploy(network)
-
- (Object) register_existing_resources
---------------------------------------------------------------------------------------------------------------------.
-
- (Object) resource_delete(resource)
---------------------------------------------------------------------------------------------------------------------.
-
- (Object) resource_update_state(resource)
---------------------------------------------------------------------------------------------------------------------.
- - (Object) storage_action_backup(storage, parameters = nil)
- - (Object) storage_action_offline(storage, parameters = nil)
- - (Object) storage_action_online(storage, parameters = nil)
- - (Object) storage_action_resize(storage, parameters = nil)
- - (Object) storage_action_snapshot(storage, parameters = nil)
- - (Object) storage_deploy(storage)
-
- (Object) store(resource)
---------------------------------------------------------------------------------------------------------------------.
Constructor Details
- (Dummy) initialize
A new instance of Dummy
34 35 36 37 38 39 40 |
# File 'lib/occi/backend/dummy.rb', line 34 def initialize @store = PStore.new('collection') @store.transaction do @store['resources'] ||= [] @store['links'] ||= [] end end |
Instance Method Details
- (Object) action_dummy(resource, parameters = nil)
223 224 225 226 227 |
# File 'lib/occi/backend/dummy.rb', line 223 def action_dummy(resource, parameters=nil) OCCI::Log.debug("Calling method for resource '#{resource.attributes['occi.core.title']}' with parameters: #{parameters.inspect}") resource.links ||= [] resource.links.delete_if { |link| link.rel.include? 'action' } end |
- (Object) compute_action_restart(compute, parameters = nil)
162 163 164 |
# File 'lib/occi/backend/dummy.rb', line 162 def compute_action_restart(compute, parameters=nil) compute_action_start(compute) end |
- (Object) compute_action_start(compute, parameters = nil)
ACTIONS
146 147 148 149 150 151 152 153 |
# File 'lib/occi/backend/dummy.rb', line 146 def compute_action_start(compute, parameters=nil) action_dummy(compute) compute.attributes!.occi!.compute!.state = 'active' compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=stop', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start') compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=restart', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#restart') compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=suspend', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#suspend') store(compute) end |
- (Object) compute_action_stop(compute, parameters = nil)
155 156 157 158 159 160 |
# File 'lib/occi/backend/dummy.rb', line 155 def compute_action_stop(compute, parameters=nil) action_dummy(compute) compute.attributes!.occi!.compute!.state = 'inactive' compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=start', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start') store(compute) end |
- (Object) compute_action_suspend(compute, parameters = nil)
166 167 168 169 170 171 |
# File 'lib/occi/backend/dummy.rb', line 166 def compute_action_suspend(compute, parameters=nil) action_dummy(compute) compute.attributes!.occi!.compute!.state = 'suspended' compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=start', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start') store(compute) end |
- (Object) compute_deploy(compute)
TODO: register user defined mixins
102 103 104 105 106 |
# File 'lib/occi/backend/dummy.rb', line 102 def compute_deploy(compute) compute.id = UUIDTools::UUID..to_s compute_action_start(compute) store(compute) end |
- (Object) network_action_down(network, parameters = nil)
215 216 217 218 219 220 |
# File 'lib/occi/backend/dummy.rb', line 215 def network_action_down(network, parameters=nil) action_dummy(network) network.attributes!.occi!.network!.state = 'down' network.links << OCCI::Core::Link.new(:target => network.location + '?action=up', :rel => 'http://schemas.ogf.org/occi/infrastructure/network/action#up') store(network) end |
- (Object) network_action_up(network, parameters = nil)
208 209 210 211 212 213 |
# File 'lib/occi/backend/dummy.rb', line 208 def network_action_up(network, parameters=nil) action_dummy(network) network.attributes!.occi!.network!.state = 'up' network.links << OCCI::Core::Link.new(:target => network.location + '?action=down', :rel => 'http://schemas.ogf.org/occi/infrastructure/network/action#down') store(network) end |
- (Object) network_deploy(network)
114 115 116 117 118 |
# File 'lib/occi/backend/dummy.rb', line 114 def network_deploy(network) network.id = UUIDTools::UUID..to_s network_action_up(network) store(network) end |
- (Object) register_existing_resources
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/occi/backend/dummy.rb', line 89 def register_existing_resources @store.transaction(read_only=true) do entities = @store['resources'] + @store['links'] entities.each do |entity| kind = OCCI::Registry.get_by_id(entity.kind) kind.entities << entity OCCI::Log.debug("#### Number of entities in kind #{kind.type_identifier}: #{kind.entities.size}") end end end |
- (Object) resource_delete(resource)
135 136 137 138 139 140 |
# File 'lib/occi/backend/dummy.rb', line 135 def resource_delete(resource) OCCI::Log.debug("Deleting resource '#{resource.attributes['occi.core.title']}'...") @store.transaction do @store['resources'].delete_if { |res| res.id == resource.id } end end |
- (Object) resource_update_state(resource)
130 131 132 |
# File 'lib/occi/backend/dummy.rb', line 130 def resource_update_state(resource) OCCI::Log.debug("Updating state of resource '#{resource.attributes['occi.core.title']}'...") end |
- (Object) storage_action_backup(storage, parameters = nil)
193 194 195 |
# File 'lib/occi/backend/dummy.rb', line 193 def storage_action_backup(storage, parameters=nil) # nothing to do, state and actions stay the same after the backup which is instant for the dummy end |
- (Object) storage_action_offline(storage, parameters = nil)
183 184 185 186 187 188 189 190 191 |
# File 'lib/occi/backend/dummy.rb', line 183 def storage_action_offline(storage, parameters=nil) action_dummy(storage) storage.attributes!.occi!.storage!.state = 'offline' storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=online', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#online') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=backup', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#restart') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=snapshot', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#suspend') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=resize', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#resize') store(storage) end |
- (Object) storage_action_online(storage, parameters = nil)
173 174 175 176 177 178 179 180 181 |
# File 'lib/occi/backend/dummy.rb', line 173 def storage_action_online(storage, parameters=nil) action_dummy(storage) storage.attributes!.occi!.storage!.state = 'online' storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=offline', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#offline') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=backup', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#restart') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=snapshot', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#suspend') storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=resize', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#resize') store(storage) end |
- (Object) storage_action_resize(storage, parameters = nil)
201 202 203 204 205 206 |
# File 'lib/occi/backend/dummy.rb', line 201 def storage_action_resize(storage, parameters=nil) puts "Parameters: #{parameters}" storage.attributes!.occi!.storage!.size = parameters[:size].to_i # state and actions stay the same after the resize which is instant for the dummy store(storage) end |
- (Object) storage_action_snapshot(storage, parameters = nil)
197 198 199 |
# File 'lib/occi/backend/dummy.rb', line 197 def storage_action_snapshot(storage, parameters=nil) # nothing to do, state and actions stay the same after the snapshot which is instant for the dummy end |
- (Object) storage_deploy(storage)
108 109 110 111 112 |
# File 'lib/occi/backend/dummy.rb', line 108 def storage_deploy(storage) storage.id = UUIDTools::UUID..to_s storage_action_online(storage) store(storage) end |
- (Object) store(resource)
121 122 123 124 125 126 127 |
# File 'lib/occi/backend/dummy.rb', line 121 def store(resource) OCCI::Log.debug("### DUMMY: Deploying resource with id #{resource.id}") @store.transaction do @store['resources'].delete_if { |res| res.id == resource.id } @store['resources'] << resource end end |