Class: OMF::SFA::Resource::OComponent

Inherits:
OResource
  • Object
show all
Extended by:
Base::ClassMethods
Includes:
Base::InstanceMethods
Defined in:
lib/omf-sfa/resource/ocomponent.rb

Overview

Components are resources with a management interface.

Direct Known Subclasses

Channel, Interface, Node

Instance Method Summary collapse

Methods included from Base::ClassMethods

_sfa_add_ns, _sfa_prefix_for_namespace, _to_sfa_xml, default_component_manager_id, default_domain, descendants, from_sfa, sfa, sfa_add_namespace, sfa_add_namespaces_to_document, sfa_cast_property_value, sfa_class, sfa_def_for, sfa_defs, sfa_suppress_id, sfa_suppress_id?, sfa_suppress_uuid, sfa_suppress_uuid?, to_rspec

Methods included from Base::InstanceMethods

#_to_sfa_property_hash, #_to_sfa_xml, #_xml_name, #component_id, #component_manager_id, #default_domain, #from_sfa, #resource_type, #sfa_class, #sfa_id, #sfa_property, #to_sfa_hash, #to_sfa_hash_short, #to_sfa_short_xml, #to_sfa_xml

Methods inherited from OResource

#_dirty_self?, #_oprops_to_hash, #all_resources, #default_href_prefix, #dirty_self?, #each_resource, #group?, #href, href_resolver, init, json_create, #oproperties_as_hash, #oproperty, oproperty, #oproperty_array_get, #oproperty_get, #oproperty_set, prop_all, #remove_from_all_groups, #resource_type, #status, #to_hash, #to_hash_brief, #to_hash_long, #to_json, #uuid

Instance Method Details

#_from_sfa_exo_sliver__geni_sliver_info_property_xml(resource_el, props, context) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/omf-sfa/resource/ocomponent.rb', line 96

def _from_sfa_exo_sliver__geni_sliver_info_property_xml(resource_el, props, context)
  resource_el.children.filter("//*[local-name()='geni_sliver_info']").each do |si|
    #puts ">>>> #{si.attributes}"
    if value = si["expiration_time"]
      self.expiration_time = Time.parse(value)
    end
    if value = si["state"]
      self.status = value
    end
  end
end

#_to_sfa_property_xml(pname, value, res_el, pdef, obj2id, opts) ⇒ Object

Override xml serialization of ‘leases’



86
87
88
89
90
91
92
93
94
# File 'lib/omf-sfa/resource/ocomponent.rb', line 86

def _to_sfa_property_xml(pname, value, res_el, pdef, obj2id, opts)
  if pname == 'leases'
    value.each do |lease|
      lease.to_sfa_ref_xml(res_el, obj2id, opts)
    end
    return
  end
  super
end

#cloneObject



108
109
110
111
112
113
114
115
116
# File 'lib/omf-sfa/resource/ocomponent.rb', line 108

def clone
  clone = super
  # we don't want to clone the following attributes
  # from the base resource
  clone.provides = []
  clone.component_leases = []
  clone.leases = []
  clone
end

#component_nameObject

def component_id

res = oproperty_get(:id)

end



59
60
61
62
# File 'lib/omf-sfa/resource/ocomponent.rb', line 59

def component_name
  # the name property may have the full component name including domain and type
  self.name.split('+')[-1]
end

#create_from_xml(modifier_el, opts) ⇒ Object



70
71
72
73
74
# File 'lib/omf-sfa/resource/ocomponent.rb', line 70

def create_from_xml(modifier_el, opts)
  if modifier_el.children.length > 0
    warn "'update_from_xml' not implememted '#{modifier_el}'"
  end
end

#destroyObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/omf-sfa/resource/ocomponent.rb', line 118

def destroy
  #debug "OCOMPONENT destroy #{self}"
  if !self.provides.empty?
    raise OMF::SFA::AM::MissingImplementationException.new("Don't know yet how to delete resource which still provides other resources")
  end
  provider = self.provided_by

  if provider
    pa = provider.provides
    pa.delete self
    provider.provides = pa
    # This assumes that base resources can only provide one virtual resource
    # TODO: This doesn't really test if the provider is a base resource
    provider.available = true
    provider.save
  end

  self.component_leases.each do |l|
    # unlink the resource with all its leases
    raise "Couldn't unlink resource with lease: #{l}" unless l.destroy
  end

  super
end

#destroy!Object



147
148
149
150
151
# File 'lib/omf-sfa/resource/ocomponent.rb', line 147

def destroy!
  #debug "OCOMPONENT destroy! #{self}"
  #destroy #no need for this. OResource.destroy! will call OComponent.destroy -> OResource.destroy
  super
end

#independent_component?Boolean

Return true if this is an independent component or not. Independent components are listed as assignable, reservable resources, while dependent ones are are tied to some other resource and need to ‘stick’ with their master. Interface is such an example.

Returns:

  • (Boolean)


81
82
83
# File 'lib/omf-sfa/resource/ocomponent.rb', line 81

def independent_component?
  true
end

#update_from_xml(modifier_el, opts) ⇒ Object



64
65
66
67
68
# File 'lib/omf-sfa/resource/ocomponent.rb', line 64

def update_from_xml(modifier_el, opts)
  if modifier_el.children.length > 0
    warn "'update_from_xml' not implememted '#{modifier_el}'"
  end
end