+####################
+def test05_sat (args=[1,2]):
+ for i in args:
+ name = sat_name(i)
+ try:
+ sat_id=s[i].GetSliceAttributeTypes ([name])[0]
+ except:
+ description="custom sat on plc%d"%i
+ min_role_id=10
+ sat_id=s[i].AddSliceAttributeType ({ 'name':name,
+ 'description': description,
+ 'min_role_id' : min_role_id})
+ if sat_id:
+ print '%02d:== created SliceAttributeType = %d'%(i,sat_id)
+
+# for test, we create 4 slice_attributes
+# on slice1 - sat=custom_made (see above) - all nodes
+# on slice1 - sat=custom_made (see above) - node=n1
+# on slice1 - sat='net_max' - all nodes
+# on slice1 - sat='net_max' - node=n1
+
+def test05_sa_atom (slice_name,sat_name,value,node,i):
+ sa_id=s[i].GetSliceAttributes({'name':sat_name,
+ 'value':value})
+ if not sa_id:
+ if node:
+ sa_id=s[i].AddSliceAttribute(slice_name,
+ sat_name,
+ value,
+ node)
+ else:
+ print 'slice_name',slice_name,'sat_name',sat_name
+ sa_id=s[i].AddSliceAttribute(slice_name,
+ sat_name,
+ value)
+ if sa_id:
+ print '%02d:== created SliceAttribute = %d'%(i,sa_id),
+ print 'On slice',slice_name,'and node',node
+
+def test05_sa (args=[1,2]):
+ for i in args:
+ test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/all nodes',None,i)
+ test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/node1',node_name(i,1),i)
+ test05_sa_atom (slice_name(i,1),'vref','predefined sat/all nodes',None,i)
+ test05_sa_atom (slice_name(i,1),'vref','predefined sat/node1',node_name(i,1),i)
+
+##############################
+# readable dumps
+##############################
+def p_site (s):
+ print s['site_id'],s['peer_id'],s['login_base'],s['name'],s['node_ids']
+
+def p_key (k):
+ print k['key_id'],k['peer_id'],k['key']
+
+def p_person (p):
+ print p['person_id'],p['peer_id'],p['email'],'keys:',p['key_ids'],'sites:',p['site_ids']
+
+def p_node(n):
+ print n['node_id'],n['peer_id'],n['hostname'],'sls=',n['slice_ids'],'site=',n['site_id']
+
+def p_slice(s):
+ print s['slice_id'],s['peer_id'],s['name'],'nodes=',s['node_ids'],'persons=',s['person_ids']
+ print '---','sas=',s['slice_attribute_ids'],s['name'],'crp=',s['creator_person_id']
+ print "--- 'expires':",s['expires']
+
+def p_sat(sat):
+ print sat['attribute_type_id'], sat['name'], sat['min_role_id'], sat['description']
+
+def p_sa (sa):
+ print sa['slice_attribute_id'],sa['name'],'AT_id:',sa['attribute_type_id']
+ print '---','v=',sa['value'],'sl=',sa['slice_id'],'n=',sa['node_id']
+
+import pprint
+pretty_printer=pprint.PrettyPrinter(5)
+
+def p_sliver (margin,x):
+ print margin,'SLIVERS for : hostname',x['hostname']
+ print margin,'%d config files'%len(x['conf_files'])
+ for sv in x['slivers']:
+ p_sliver_slice(margin,sv,x['hostname'])
+
+def p_sliver_slice(margin,sliver,hostname):
+ print margin,'SLIVER on hostname %s, s='%hostname,sliver['name']
+ print margin,'KEYS',
+ pretty_printer.pprint(sliver['keys'])
+ print margin,'ATTRIBUTES',
+ pretty_printer.pprint(sliver['attributes'])
+
+def dump (args=[1,2]):
+ for i in args:
+ print '%02d:============================== DUMPING'%i
+ print '%02d: SITES'%i
+ [p_site(x) for x in s[i].GetSites()]
+ print '%02d: KEYS'%i
+ [p_key(x) for x in s[i].GetKeys()]
+ print '%02d: PERSONS'%i
+ [p_person(x) for x in s[i].GetPersons()]
+ print '%02d: NODES'%i
+ [p_node(x) for x in s[i].GetNodes()]
+ print '%02d: SLICES'%i
+ [p_slice(x) for x in s[i].GetSlices()]
+ print '%02d: Slice Attribute Types'%i
+ [p_sat(x) for x in s[i].GetSliceAttributeTypes()]
+ print '%02d: Slice Attributes'%i
+ [p_sa(x) for x in s[i].GetSliceAttributes()]
+ timer_show()
+ snodes=min(3,number_nodes)
+ print '%02d: SLIVERS for first %d nodes'%(i,snodes)
+ print 'WARNING - GetSlivers needs fix'
+# for id in myrange(snodes):
+# p_sliver('%02d:'%i,s[i].GetSlivers(id))
+
+ print '%02d:============================== END DUMP'%i
+
+
+## for usage under the api
+def pt ():
+ for x in GetSites():
+ p_site(x)
+
+def pk ():
+ for x in GetKeys():
+ print (x['key_id'],x['peer_id'],x['key'])
+
+def pp ():
+ for x in GetPersons():
+ p_person(x)
+
+def pn ():
+ for x in GetNodes():
+ p_node(x)
+
+def ps ():
+ for x in GetSlices():
+ p_slice(x)
+
+def psat():
+ for x in GetSliceAttributeTypes():
+ p_sat(x)
+
+def psa():
+ for x in GetSliceAttributes():
+ p_sa(x)
+
+def pv ():
+ for s in GetSlivers():
+ p_sliver('',s)
+
+def all():
+ print 'SITES'
+ pt()
+ print 'KEYS'
+ pk()
+ print 'PERSONS'
+ pp()
+ print 'NODES'
+ pn()
+ print 'SLICES'
+ ps()
+ print 'SLICE ATTR TYPES'
+ psat()
+ print 'SLICE ATTRS'
+ psa()
+ print 'SLIVERS'
+ pv()
+
+