Dear all,

I'm having some trouble defining a view with entity relationships.

Here is an example on what i need to do:
{
   "_id": "node01",
   "_rev": "2-eec9e84f8146d05f8116a5e064cf87e9",
   "type": "node",
   "amemory": 14543,
   "cmemory": 49118,
   "cproc": 16,
   "cpuload": 2.379,
   "netaddress": "10.40.130.146",
   "power": "on",
   "primary_state": "UP",
   "secondary_state": "Unknown:sshd",
   "os": "esxi4-stateless",
   "alias": "node01",
   "vlans": "[vlan611]",
   "variables": [
       {
           "provision_status": 2
       },
       {
           "another_variable": "something"
       }
   ],
   "aproc": 16,
   "vmcount": 6,
   "cpupercent": 14.8677794448612,
   "acores": 8,
   "ccores": 8,
   "threads": 16,
   "cpuclock": 2666,
   "numvms": 13,
   "hvtype": "esx",
   "htenabled": true
}

And then...
{
   "_id": "esxi4-stateless",
   "_rev": "2-fe0aeb05ac93d5f5a08d4befc68f10a6",
   "type": "os",
   "oslist": [
       "SOE-RHEL-5_5-2H10_0-Statelite-pm",
       "esxi4-stateless",
       "rhel53-statelite-pm",
       "rhel54-statelite-pm"
   ],
   "vmoslist": [
       "rhel48-stateful",
       "rhel53-stateful",
       "rhel53-stateful-cluster",
       "rhel54-stateful",
       "SOE-RHEL-5_5-2H10_0-Stateful",
       "rhel54-stateful-cluster",
       "rhel53-statelite-vm",
       "rhel54-statelite-vm",
       "SOE-RHEL-5_5-2H10_0-Statelite-vm",
       "win2k3-stateful-32-std",
       "win2k3-stateful-32-ent",
       "win2k3-stateful-32-ent-cluster",
       "win2k3-stateful-64-std",
       "win2k3-stateful-64-ent",
       "win2k3-stateful-64-ent-cluster",
       "win2k8-stateful-64-std",
       "win2k8-stateful-64-ent",
       "win2k8-stateful-64-ent-cluster",
       "win2k8R2-stateful-64-std",
       "win2k8R2-stateful-64-ent",
       "win2k8R2-stateful-64-ent-cluster",
       "P2V-WIN,P2V-RHEL"
   ]
}

And my view looks like:
function(doc) {
        if (doc.type == "node")
        {
                emit(doc._id,
                        {
                                node: doc._id,
                                STATE: doc.secondary_state,
                                OS: doc.oslist,
                                ALIAS: doc.alias,
                                FEATURE: doc.vlans,
                                "GMETRIC[numvms]": doc.numvms,
                                NETADDR: doc.netaddress,
                                VARATTR: { "HVTYPE":doc.hvtype},
                                VARIABLE: doc.variables,
                        }
                );
        }
}

So my question is, how do i get the oslist and vmoslist from the
document whose _id = my register's doc.os key ?

I basically need to understand how i can query the entire database,
getting all the nodes and, while i'm querying all the nodes, get the
appropriate oslist and vmoslist (so i do not have to store these
fields more than once since they only vary based on "os" key).

I've been reading the EntityRelationship wiki page
(http://wiki.apache.org/couchdb/EntityRelationship) but i really do
not understand how can i map without specifying a key.
In the "phone directory example", i would have to specify the
individual key i want to get in order to map relations between
documents and that's not what i want to do.

Any thoughts?

Thank you,
Luis

Reply via email to