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 _call(self, process_count, fping_count): result = [] targets = [] if self.connected() == False: logging.error("NOTE!!! HealthCheck is not connected") return try: with self.db_engine: #for target in Target.select(): for target in Device.select().where(Device.host.is_null(False), Device.device_type != 3, Device.enable == 1): targets.append( FPingTarget(target.host, target.id, target.state)) except Exception as err: logging.error("FPingCallback get targets: %s", str(err)) return try: multi_process_pool = multiprocessing.Pool(process_count) for t in targets: result.append( multi_process_pool.apply_async(generate_fping_metrics, (t, fping_count))) except Exception as err: logging.error("FPingCallback multiprocessing pool: %s", str(err)) finally: multi_process_pool.close() multi_process_pool.join() # multi_process_pool.close() # multi_process_pool.join() try: with self.db_engine: for res in result: m = res.get() last_time = datetime.datetime.now() query = Device.update( state=m.state, avg=m.avg, loss_rate=m.loss_rate, last_time=last_time).where(Device.id == m.idx) query.execute() query = Port.update(state=m.state).where( Port.device_id == m.idx) query.execute() query = Target.update(state=m.state).where( Target.device_id == m.idx) query.execute() if m.old_state <> m.state: info = 'linkUp' if m.state == 1 else 'linkDown' FPingMessage.create(host=m.host, info=info) except Exception as err: logging.error("FPingCallback update state: %s", str(err))
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
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