@property
def sfaapi(self):
+ """
+ Property to instanciate the SFA API based in sfi client.
+ For each SFA method called this instance is used.
+ """
if not self._sfaapi:
sfa_user = self.get("sfauser")
sfa_sm = "http://sfa3.planet-lab.eu:12346/"
self.fail_node_not_alive(hostname)
else:
if self._check_if_in_slice([host_hrn]):
+ self.debug("The node %s is already in the slice" % hostname)
self._slicenode = True
self._node_to_provision = host_hrn
super(PlanetlabSfaNode, self).do_discover()
# self.fail_not_enough_nodes()
#
def _blacklisted(self, host_hrn):
+ """
+ Check in the SFA API that the node is not in the blacklist.
+ """
if self.sfaapi.blacklisted(host_hrn):
- self.fail_node_not_available(hostname)
+ self.fail_node_not_available(host_hrn)
return False
def _reserved(self, host_hrn):
+ """
+ Check in the SFA API that the node is not in the reserved
+ list.
+ """
if self.sfaapi.reserved(host_hrn):
- self.fail_node_not_available(hostname)
+ self.fail_node_not_available(host_hrn)
return False
def do_provision(self):
"""
- Add node to user's slice after verifing that the node is functioning
- correctly.
+ Add node to user's slice and verifing that the node is functioning
+ correctly. Check ssh, file system.
"""
if self._skip_provision():
super(PlanetlabSfaNode, self).do_provision()
# the timeout was reach without establishing ssh connection
# the node is blacklisted, deleted from the slice, and a new
# node to provision is discovered
- self.warn(" Could not SSH login ")
+ self.warning(" Could not SSH login ")
self._blacklist_node(node)
self.do_discover()
continue
((out2, err2), proc2) = self.execute(cmd)
if out1.find("/proc type proc") < 0 or \
"Read-only file system".lower() in err2.lower():
- self.warn(" Corrupted file system ")
+ self.warning(" Corrupted file system ")
self._blacklist_node(node)
self.do_discover()
continue
# return self.plapi.get_nodes(filters, fields=['node_id'])
#
def _add_node_to_slice(self, host_hrn):
+ """
+ Add node to slice, using SFA API.
+ """
self.info(" Adding node to slice ")
slicename = self.get("username").replace('_', '.')
slicename = 'ple.' + slicename
self.sfaapi.add_resource_to_slice(slicename, host_hrn)
-# def _delete_node_from_slice(self, node):
-# self.warn(" Deleting node from slice ")
-# slicename = self.get("username")
-# self.plapi.delete_slice_node(slicename, [node])
-#
+ def _delete_from_slice(self):
+ """
+ Delete every node from slice, using SFA API.
+ Sfi client doesn't work for particular node urns.
+ """
+ self.warning(" Deleting node from slice ")
+ slicename = self.get("username").replace('_', '.')
+ slicename = 'ple.' + slicename
+ self.sfaapi.remove_all_from_slice(slicename)
+
def _get_hostname(self):
+ """
+ Get the attribute hostname.
+ """
hostname = self.get("hostname")
if hostname:
return hostname
def _set_hostname_attr(self, node):
"""
Query SFAAPI for the hostname of a certain host hrn and sets the
- attribute hostname, it will over write the previous value
+ attribute hostname, it will over write the previous value.
"""
hosts_hrn = self.sfaapi.get_resources_hrn()
for hostname, hrn in hosts_hrn.iteritems():
def _check_if_in_slice(self, hosts_hrn):
"""
Check using SFA API if any host hrn from hosts_hrn is in the user's
- slice
+ slice.
"""
slicename = self.get("username").replace('_', '.')
slicename = 'ple.' + slicename
slice_nodes = self.sfaapi.get_slice_resources(slicename)['resource']
- slice_nodes_hrn = self.sfaapi.get_resources_hrn(slice_nodes)
- nodes_inslice = list(set(hosts_hrn) & set(slice_nodes_hrn.values()))
+ if slice_nodes:
+ slice_nodes_hrn = self.sfaapi.get_resources_hrn(slice_nodes).values()
+ else: slice_nodes_hrn = []
+ nodes_inslice = list(set(hosts_hrn) & set(slice_nodes_hrn))
return nodes_inslice
def _do_ping(self, hostname):
"""
- Perform ping command on node's IP matching hostname
+ Perform ping command on node's IP matching hostname.
"""
ping_ok = False
ip = self._get_ip(hostname)
def _blacklist_node(self, host_hrn):
"""
- Add node mal functioning node to blacklist
+ Add mal functioning node to blacklist (in SFA API).
"""
self.warning(" Blacklisting malfunctioning node ")
self.sfaapi.blacklist_resource(host_hrn)