make get_existing_objs tolerant of nonexistent sliver or network
diff --git a/xos/tosca/resources/port.py b/xos/tosca/resources/port.py
index a4dc974..435ba0f 100644
--- a/xos/tosca/resources/port.py
+++ b/xos/tosca/resources/port.py
@@ -15,21 +15,23 @@
def get_existing_objs(self):
# Port objects have no name, their unique key is (sliver, network)
- args = self.get_xos_args()
- sliver = args['sliver']
- network = args['network']
+ args = self.get_xos_args(throw_exception=False)
+ sliver = args.get('sliver',None)
+ network = args.get('network',None)
+ if (not sliver) or (not network):
+ return []
return self.xos_model.objects.filter(**{'sliver': sliver, 'network': network})
- def get_xos_args(self):
+ def get_xos_args(self, throw_exception=True):
args = {}
sliver_name = self.get_requirement("tosca.relationships.network.BindsTo")
if sliver_name:
- args["sliver"] = self.get_xos_object(Sliver, name=sliver_name)
+ args["sliver"] = self.get_xos_object(Sliver, throw_exception, name=sliver_name)
net_name = self.get_requirement("tosca.relationships.network.LinksTo")
if net_name:
- args["network"] = self.get_xos_object(Network, name=net_name)
+ args["network"] = self.get_xos_object(Network, throw_exception, name=net_name)
return args