Class: Dcmgr::VNet::Netfilter::NetfilterCache

Inherits:
Cache
  • Object
show all
Includes:
Logger
Defined in:
lib/dcmgr/vnet/netfilter/cache.rb

Instance Method Summary collapse

Methods included from Logger

create, default_logdev, included

Constructor Details

#initialize(node) ⇒ NetfilterCache

Returns a new instance of NetfilterCache.



10
11
12
13
14
# File 'lib/dcmgr/vnet/netfilter/cache.rb', line 10

def initialize(node)
  # Initialize the values needed to do rpc requests
  @node = node
  @rpc ||= Isono::NodeModules::RpcChannel.new(@node)
end

Instance Method Details

#add_instance(inst_map) ⇒ Object

Adds a newly started instance to the existing cache



33
34
35
36
37
38
39
40
# File 'lib/dcmgr/vnet/netfilter/cache.rb', line 33

def add_instance(inst_map)
  if @cache.is_a? Hash
    logger.info "adding instance '#{inst_map[:uuid]} to cache'"
    @cache << inst_map
  else
  
  end
end

#get(force_update = false) ⇒ Object

Returns the cache if force_update is set to true, the cache will be updated from the database



24
25
26
27
28
29
30
# File 'lib/dcmgr/vnet/netfilter/cache.rb', line 24

def get(force_update = false)
  self.update if @cache.nil? || force_update
  
  # Always return a duplicate of the cache. We don't want any external program messing with the original contents.
  #TODO: Do this in a faster way than marshall
  Marshal.load( Marshal.dump(@cache) )
end

#remove_instance(inst_id) ⇒ Object

Removes a terminated instance from the existing cache



43
44
45
46
# File 'lib/dcmgr/vnet/netfilter/cache.rb', line 43

def remove_instance(inst_id)
  logger.info "removing Instance '#{inst_id}' from cache"
  @cache[:instances].delete_if {|inst_map| inst_map[:uuid] == inst_id }
end

#updateObject

Makes a call to the database and updates the Cache



17
18
19
20
# File 'lib/dcmgr/vnet/netfilter/cache.rb', line 17

def update
  logger.info "updating cache from database"
  @cache = @rpc.request('hva-collector', 'get_netfilter_data', @node.node_id)
end