X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fobjects%2Fsliceplus.py;h=6bbbfa2235bf2e4c377e61e9b8cc52789dc94cf0;hb=ab385c86e10475c711c350f1ddf1cca0c2accd65;hp=94174b4915d00d44370b7e7e0440173942e4bdc2;hpb=03c932fef9efc6728c8e81df6e0627625e3e0421;p=plstackapi.git diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py index 94174b4..6bbbfa2 100644 --- a/planetstack/core/xoslib/objects/sliceplus.py +++ b/planetstack/core/xoslib/objects/sliceplus.py @@ -1,6 +1,7 @@ from core.models import Slice, SlicePrivilege, SliceRole, Sliver, Site, Node, User from plus import PlusObjectMixin from operator import itemgetter, attrgetter +from rest_framework.exceptions import APIException class SlicePlus(Slice, PlusObjectMixin): class Meta: @@ -19,6 +20,7 @@ class SlicePlus(Slice, PlusObjectMixin): def getSliceInfo(self, user=None): if not self._sliceInfo: used_sites = {} + ready_sites = {} used_deployments = {} sliverCount = 0 sshCommands = [] @@ -29,9 +31,11 @@ class SlicePlus(Slice, PlusObjectMixin): used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1 sliverCount = sliverCount + 1 - if (sliver.instance_id and sliver.instance_name): - sshCommand = 'ssh -o "ProxyCommand ssh -q %s@%s" ubuntu@%s' % (sliver.instance_id, sliver.node.name, sliver.instance_name) - sshCommands.append(sshCommand); + sshCommand = sliver.get_ssh_command() + if sshCommand: + sshCommands.append(sshCommand) + + ready_sites[site.name] = ready_sites.get(site.name, 0) + 1 users = {} for priv in SlicePrivilege.objects.filter(slice=self): @@ -51,6 +55,7 @@ class SlicePlus(Slice, PlusObjectMixin): networkPorts = network.ports self._sliceInfo= {"sitesUsed": used_sites, + "sitesReady": ready_sites, "deploymentsUsed": used_deployments, "sliverCount": sliverCount, "siteCount": len(used_sites.keys()), @@ -66,6 +71,14 @@ class SlicePlus(Slice, PlusObjectMixin): return self._sliceInfo + @property + def site_ready(self): + return self.getSliceInfo()["sitesReady"] + + @site_ready.setter + def site_ready(self, value): + pass + @property def site_allocation(self): return self._site_allocation @@ -183,7 +196,7 @@ class SlicePlus(Slice, PlusObjectMixin): nodes = self.get_node_allocation([site]) if (not nodes): - raise ValueError("no nodes in site %s" % site_name) + raise APIException(detail="no nodes in site %s" % site_name) while (len(slivers) < desired_allocation): # pick the least allocated node @@ -261,7 +274,7 @@ class SlicePlus(Slice, PlusObjectMixin): # uh oh, we didn't find a network - raise ValueError("No network was found that ports could be set on") + raise APIException(detail="No network was found that ports could be set on")