Module: BackendApi::Network

Defined in:
app/models/backend_api/network.rb

Instance Method Summary collapse

Instance Method Details

#network_create(network) ⇒ String

Instantiates a new network instance from ::Occi::Infrastructure::Network. ID given in the occi.core.id attribute is optional and can be changed inside this method. Final occi.core.id must be returned as a String. If the requested instance cannot be created, an error describing the problem must be raised, @see Backends::Errors.

Examples:

network = ::Occi::Infrastructure::Network.new
network_id = network_create(network)
    #=> "65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf"

Parameters:

  • network (::Occi::Infrastructure::Network)

    network instance containing necessary attributes

Returns:

  • (String)

    final identifier of the new network instance


65
66
67
68
69
# File 'app/models/backend_api/network.rb', line 65

def network_create(network)
  fail Errors::ArgumentError, '\'network\' is a mandatory argument' if network.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a network instance!' unless network.kind_of? ::Occi::Infrastructure::Network
  backend_instances['network'].create(network)
end

#network_delete(network_id) ⇒ true, false

Deletes a specific network instance, instance to be deleted is specified by an ID, this ID must match the occi.core.id attribute of the deleted instance. If the requested instance cannot be deleted, an error describing the problem must be raised, @see Backends::Errors.

Examples:

network_delete("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf") #=> true

Parameters:

  • network_id (String)

    an identifier of a network instance to be deleted

Returns:

  • (true, false)

    result of the operation


99
100
101
102
# File 'app/models/backend_api/network.rb', line 99

def network_delete(network_id)
  fail Errors::ArgumentError, '\'network_id\' is a mandatory argument' if network_id.blank?
  backend_instances['network'].delete(network_id)
end

#network_delete_all(mixins = nil) ⇒ true, false

Deletes all network instances, instances to be deleted must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance. If the requested instances cannot be deleted, an error describing the problem must be raised, @see Backends::Errors.

Examples:

network_delete_all #=> true

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
network_delete_all(mixins)  #=> true

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (true, false)

    result of the operation


84
85
86
# File 'app/models/backend_api/network.rb', line 84

def network_delete_all(mixins = nil)
  backend_instances['network'].delete_all(mixins)
end

#network_get(network_id) ⇒ ::Occi::Infrastructure::Network?

Gets a specific network instance as ::Occi::Infrastructure::Network. ID given as an argument must match the occi.core.id attribute inside the returned ::Occi::Infrastructure::Network instance, however it is possible to implement internal mapping to a platform-specific identifier.

Examples:

network = network_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf')
    #=> #<::Occi::Infrastructure::Network>

Parameters:

  • network_id (String)

    OCCI identifier of the requested network instance

Returns:

  • (::Occi::Infrastructure::Network, nil)

    a network instance or `nil`


47
48
49
50
# File 'app/models/backend_api/network.rb', line 47

def network_get(network_id)
  fail Errors::ArgumentError, '\'network_id\' is a mandatory argument' if network_id.blank?
  backend_instances['network'].get(network_id)
end

#network_get_extensions::Occi::Collection

Returns a collection of custom mixins introduced (and specific for) the enabled backend. Only mixins and actions are allowed.

Returns:

  • (::Occi::Collection)

    collection of extensions (custom mixins and/or actions)


198
199
200
# File 'app/models/backend_api/network.rb', line 198

def network_get_extensions
  backend_instances['network'].get_extensions || ::Occi::Collection.new
end

#network_list(mixins = nil) ⇒ ::Occi::Core::Resources

Gets all network instances, instances must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance. Returned collection must contain ::Occi::Infrastructure::Network instances wrapped in ::Occi::Core::Resources.

Examples:

networks = network_list #=> #<::Occi::Core::Resources>
networks.first #=> #<::Occi::Infrastructure::Network>

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
networks = network_list(mixins) #=> #<::Occi::Core::Resources>

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (::Occi::Core::Resources)

    a collection of network instances


32
33
34
# File 'app/models/backend_api/network.rb', line 32

def network_list(mixins = nil)
  backend_instances['network'].list(mixins) || ::Occi::Core::Resources.new
end

#network_list_ids(mixins = nil) ⇒ Array<String>

Gets all network instance IDs, no details, no duplicates. Returned identifiers must correspond to those found in the occi.core.id attribute of ::Occi::Infrastructure::Network instances.

Examples:

network_list_ids #=> []
network_list_ids #=> ["65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf",
                         "ggf4f65adfadf-adgg4ad-daggad-fydd4fadyfdfd"]

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (Array<String>)

    IDs for all available network instances


14
15
16
# File 'app/models/backend_api/network.rb', line 14

def network_list_ids(mixins = nil)
  backend_instances['network'].list_ids(mixins) || []
end

#network_partial_update(network_id, attributes = nil, mixins = nil, links = nil) ⇒ true, false

Partially updates an existing network instance, instance to be updated is specified by network_id. If the requested instance cannot be updated, an error describing the problem must be raised, @see Backends::Errors.

Examples:

attributes = ::Occi::Core::Attributes.new
mixins = ::Occi::Core::Mixins.new
links = ::Occi::Core::Links.new
network_partial_update(network_id, attributes, mixins, links) #=> true

Parameters:

  • network_id (String)

    unique identifier of a network instance to be updated

  • attributes (::Occi::Core::Attributes) (defaults to: nil)

    a collection of attributes to be updated

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a collection of mixins to be added

  • links (::Occi::Core::Links) (defaults to: nil)

    a collection of links to be added

Returns:

  • (true, false)

    result of the operation


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/backend_api/network.rb', line 120

def network_partial_update(network_id, attributes = nil, mixins = nil, links = nil)
  fail Errors::ArgumentError, '\'network_id\' is a mandatory argument' if network_id.blank?
  attributes ||= ::Occi::Core::Attributes.new
  mixins ||= ::Occi::Core::Mixins.new
  links ||= ::Occi::Core::Links.new

  unless attributes.kind_of?(::Occi::Core::Attributes) && mixins.kind_of?(::Occi::Core::Mixins) && links.kind_of?(::Occi::Core::Links)
    fail Errors::ArgumentTypeMismatchError, 'Action requires attributes, mixins or links to be updated!'
  end

  backend_instances['network'].partial_update(
    network_id, attributes,
    mixins, links
  )
end

#network_trigger_action(network_id, action_instance) ⇒ true, false

Triggers an action on an existing network instance, the network instance in question is identified by a network instance ID, action is identified by the action.term attribute of the action instance passed as an argument. If the requested action cannot be triggered, an error describing the problem must be raised, @see Backends::Errors.

Examples:

action_instance = ::Occi::Core::ActionInstance.new
network_trigger_action("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf", action_instance)
  #=> true

Parameters:

  • network_id (String)

    network instance identifier

  • action_instance (::Occi::Core::ActionInstance)

    action to be triggered

Returns:

  • (true, false)

    result of the operation


187
188
189
190
191
192
# File 'app/models/backend_api/network.rb', line 187

def network_trigger_action(network_id, action_instance)
  fail Errors::ArgumentError, '\'network_id\' is a mandatory argument' if network_id.blank?
  fail Errors::ArgumentError, '\'action_instance\' is a mandatory argument' if action_instance.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires an action instance!' unless action_instance.kind_of? ::Occi::Core::ActionInstance
  backend_instances['network'].trigger_action(network_id, action_instance)
end

#network_trigger_action_on_all(action_instance, mixins = nil) ⇒ true, false

Triggers an action on all existing network instance, instances must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance, action is identified by the action.term attribute of the action instance passed as an argument. If the requested action cannot be triggered, an error describing the problem must be raised, @see Backends::Errors.

Examples:

action_instance = ::Occi::Core::ActionInstance.new
mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
network_trigger_action_on_all(action_instance, mixin) #=> true

Parameters:

  • action_instance (::Occi::Core::ActionInstance)

    action to be triggered

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (true, false)

    result of the operation


167
168
169
170
171
# File 'app/models/backend_api/network.rb', line 167

def network_trigger_action_on_all(action_instance, mixins = nil)
  fail Errors::ArgumentError, '\'action_instance\' is a mandatory argument' if action_instance.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires an action instance!' unless action_instance.kind_of? ::Occi::Core::ActionInstance
  backend_instances['network'].trigger_action_on_all(action_instance, mixins)
end

#network_update(network) ⇒ true, false

Updates an existing network instance, instance to be updated is specified using the occi.core.id attribute of the instance passed as an argument. If the requested instance cannot be updated, an error describing the problem must be raised, @see Backends::Errors.

Examples:

network = ::Occi::Infrastructure::Network.new
network_update(network) #=> true

Parameters:

  • network (::Occi::Infrastructure::Network)

    instance containing updated information

Returns:

  • (true, false)

    result of the operation


147
148
149
150
151
# File 'app/models/backend_api/network.rb', line 147

def network_update(network)
  fail Errors::ArgumentError, '\'network\' is a mandatory argument' if network.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a network instance!' unless network.kind_of? ::Occi::Infrastructure::Network
  backend_instances['network'].update(network)
end