Clean up of repo
[nepi.git] / src / nepi / testbeds / planetlab / util.py
index 133f3af..e320c4c 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 from constants import TESTBED_ID, TESTBED_VERSION
@@ -8,6 +7,7 @@ from nepi.util.constants import TIME_NOW
 from nepi.util.graphtools import mst
 from nepi.util import ipaddr2
 from nepi.util import environ
+from nepi.util import server
 from nepi.util.parallel import ParallelRun
 import sys
 import os
@@ -27,9 +27,9 @@ import logging
 import metadata
 import weakref
 
-def getAPI(user, pass_):
+def getAPI(user, pass_, **kw):
     import plcapi
-    return plcapi.PLCAPI(username=user, password=pass_)
+    return plcapi.PLCAPI(username=user, password=pass_, **kw)
 
 def filterBlacklist(candidates):
     blpath = environ.homepath('plblacklist')
@@ -49,6 +49,22 @@ def filterBlacklist(candidates):
     finally:
         bl.close()
 
+def appendBlacklist(node_ids):
+    if not isinstance(node_ids, list):
+        node_ids = [ node_ids ]
+    
+    blpath = environ.homepath('plblacklist')
+    bl = open(blpath, "a")
+    
+    try:
+        for node_id in node_ids:
+            bl.write("%s\n" % (node_id,))
+    finally:
+        bl.close()
+
+def getVnet(api, slicename):
+    return api.GetSliceVsysNetTag(slicename)
+
 def getNodes(api, num, **constraints):
     # Now do the backtracking search for a suitable solution
     # First with existing slice nodes
@@ -93,7 +109,7 @@ def getSpanningTree(nodes, root = None, maxbranching = 2, hostgetter = operator.
     # Obtain all IPs in numeric format
     # (which means faster distance computations)
     for node in nodes:
-        node._ip = socket.gethostbyname(hostgetter(node))
+        node._ip = server.gethostbyname(hostgetter(node))
         node._ip_n = struct.unpack('!L', socket.inet_aton(node._ip))[0]
     
     # Compute plan