def find_or_make_port(self, instance, network, **kwargs): port = Port.objects.filter(instance=instance, network=network) if port: port = port[0] else: port = Port(instance=instance, network=network, **kwargs) port.save() return port
def find_or_make_port(self, instance, network, **kwargs): port = Port.objects.filter(instance=instance, network=network) if port: port = port[0] print "port already exist", port[0] else: port = Port(instance=instance, network=network, **kwargs) print "NETWORK", network, "MAKE_PORT", port port.save() return port
def create(self): xos_args = self.get_xos_args() if not xos_args.get("instance", None): raise Exception("Must specify slver when creating port") if not xos_args.get("network", None): raise Exception("Must specify network when creating port") port = Port(**xos_args) port.caller = self.user port.save() self.postprocess(port) self.info("Created Port '%s' connect instance '%s' to network %s" % (str(port), str(port.instance), str(port.network)))
def handle_container_on_metal(instance): from core.models import Instance, Flavor, Port, Image print "MODEL POLICY: instance", instance, "handle container_on_metal" if instance.deleted: return if (instance.isolation in ["container"]) and (instance.slice.network not in ["host", "bridged"]): # Our current docker-on-metal network strategy requires that there be some # VM on the server that connects to the networks, so that # the containers can piggyback off of that configuration. if not Instance.objects.filter(slice=instance.slice, node=instance.node, isolation="vm").exists(): flavors = Flavor.objects.filter(name="m1.small") if not flavors: raise XOSConfigurationError("No m1.small flavor") images = Image.objects.filter(kind="vm") companion_instance = Instance( slice=instance.slice, node=instance.node, image=images[0], creator=instance.creator, deployment=instance.node.site_deployment.deployment, flavor=flavors[0]) companion_instance.save() print "MODEL POLICY: instance", instance, "created companion", companion_instance # Add the ports for the container for network in instance.slice.networks.all(): # hmmm... The NAT ports never become ready, because sync_ports never # instantiates them. Need to think about this. print "MODEL POLICY: instance", instance, "handling network", network if (network.name.endswith("-nat")): continue if not Port.objects.filter(network=network, instance=instance).exists(): port = Port(network=network, instance=instance) port.save() print "MODEL POLICY: instance", instance, "created port", port