[[TOC(Software/bAM/*, depth=3)]]
== Inventory Aggregate Manager ==
Inventory AM consist of a database with a [http://mytestbed.net/projects/omf/wiki/NewInventoryDesign database schema] that can hold information for arbitrary type of resource and a set of services that are used to manage it
=== Resources and Relationships ===
Resources are physical entities in a testbed that are assumed to be named with fully qualified domain name (fqdn) (for resources that can have one) or with arbitrary string (for resources that are not IP addressable)and can have any number of attributes. Resource can be in relation with any other resource with, so far, 2 types of relationships:
 ||= Type =||= Relationship =||= Description =||
 || 1 || belong_to    || The subject resource belongs to the object resource   ||
 || 2 || installed_in || The subject resource is installed in the object resource ||
Typically, type 1 is used to designate that the node belongs to a testbed, and type 2 for devices that are installed into a node (at the moment type of relationship is not used for any particular function by the inventory).
To facilitate better classification, inventory services are using string based '''resource type'''. So far, defined resources types are: testbed, node and device (these types are only used by other services).
=== Attributes ===
Attributes are name-value pairs of strings. Attribute names are prefixed to support globbing.
Attribute prefixes:
 * CM_ - Attributes used by the CMC AM ( CM_TYPE, CM_IP, CM_PORT, CM_USER_NAME, CM_PASSWORD )
 * INF_ - Core infrastructure attributes used by the PXE and Frisbee service ( INF_CONTROL_IP )
 * INV_ - Attributes gathered by the inventory process 
=== Inventory Service Group ===
{{{
  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  
}}}
==== resource_add - Add Resource ====
{{{
  Add resource
  
     
        name of the resource or fully qualified resource name
     
     
         type of the resource
     
     
        xml-encoded hash of resource parameters
     
  
}}}
==== resource_delete - Delete Resource ====
{{{
  Remove set of resources
  
    
       set of resource names
    
  
}}}
==== resource_list - List Resources ====
{{{
  Get all available resources of given type that belongs to given parent resource with all attributes
  
    
      Fully qualified resource name
    
    
      Type name, currently suported testbed, node and device
    
  
}}}
==== relation_add - Add Relationship Between Resources ====
{{{
  Add relation between two resources
  
    
      parent resource name
    
    
      child resource name
    
  
}}}
==== attribute_add - Add an attribute ====
{{{
  Add attribute to resource
  
    
      Resource name
    
    
      Name of attribute
    
    
      Value of attribute 
    
  
}}}
==== attribute_delete - Delete an attribute ====
{{{
  Delete all attributes matching attribute pattern for all nodes matching node name pattern (rn)
  
    
      Resource name or resource name pattern
    
    
      Attribute pattern
    
  
}}}
==== attribute_modify - Modify an attribute value ====
{{{
  Modify attribute's value
  
    
      Resource name
    
    
      Attribute name
    
    
      New value of attribute 
    
  
}}}
==== attribute_list - List attributes ====
{{{
  Get node with names matching name pattern with attributes matching attribute name pattern and value matching attribute value pattern
  
    
      Set of resource names or resource name pattern
    
    
      Attribute name pattern
    
    
      Attribute value pattern
    
  
}}}
==== attribute_listChildren - List attributes of children ====
{{{
  Get node with names matching name pattern with child (device) attributes matching attribute name pattern and value matching attribute value pattern
   
    
       Set of resource names or resource name pattern
    
    
      Child attribute name pattern
    
    
      Child attribute value pattern
    
  
}}}
=== Usage Examples ===
Create testbed, add node to it and add basic attributes
{{{
# Define the testbed
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/resource_add?name=sb10.orbit-lab.org&type=testbed'
# Add a node
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/resource_add?name=node1-1.sb10.orbit-lab.org&type=node'
# Create the parent/child relationship between the testbed and the node
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/relation_add?parent=sb10.orbit-lab.org&child=node1-1.sb10.orbit-lab.org'
# Add basic attributes
# CM is CM3 (mandatory)
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_add?name=node1-1.sb10.orbit-lab.org&attribute=CM_type&value=3'
# IP Address for this CM (mandatory)
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_add?name=node1-1.sb10.orbit-lab.org&attribute=CM_ip&value=10.22.1.1'
# IP Port for this CM (mandatory)
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_add?name=node1-1.sb10.orbit-lab.org&attribute=CM_port&value=1'
# Disk from the node boots (for imaging)
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_add?name=node1-1.sb10.orbit-lab.org&attribute=INF_default_disk&value=/dev/sda'
  ...
}}}
Replace inventory information
{{{
# First, delete all devices that belong to the node
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/resource_delete?set=node1-1.sb10.orbit-lab.org-*'
# Then delete all attributes collected by the inventory process running on the node
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_delete?name=node1-1.sb10.orbit-lab.org&attribute=INV_*'
# Add first device named "node1-1.sb10.orbit-lab.org-e0" (and add it to the node)
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/resource_add?name=node1-1.sb10.orbit-lab.org--e0&type=device'
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/relation_add?parent=node1-1.sb10.orbit-lab.org&child=node1-1.sb10.orbit-lab.org-e0'
# Add attributes for the new device
  wget -qO- 'http://new.orbit-lab.org:5054/inventory/attribute_add?name=node1-1.sb10.orbit-lab.org--e0&attribute=INV_MAC_0&value=00:01:02:03:04:05'
}}}