def get_ports(self, o): i = 0 ports = [] if (o.slice.network in ["host", "bridged"]): pass # no ports in host or bridged mode else: for port in o.ports.all(): if (not port.ip): # 'unmanaged' ports may have an ip, but no mac # XXX: are there any ports that have a mac but no ip? raise DeferredException( "Port on network %s is not yet ready" % port.network.name) pd = {} pd["mac"] = port.mac or "" pd["ip"] = port.ip or "" pd["xos_network_id"] = port.network.id if port.network.name == "wan_network": if port.ip: (a, b, c, d) = port.ip.split('.') pd["mac"] = "02:42:%02x:%02x:%02x:%02x" % ( int(a), int(b), int(c), int(d)) if o.isolation == "container": # container on bare metal instance_port = self.get_instance_port(port) if not instance_port: raise DeferredException( "No instance on slice for port on network %s" % port.network.name) pd["snoop_instance_mac"] = instance_port.mac pd["snoop_instance_id"] = instance_port.instance.instance_id pd["src_device"] = "" pd["bridge"] = "br-int" else: # container in VM pd["snoop_instance_mac"] = "" pd["snoop_instance_id"] = "" pd["parent_mac"] = self.get_parent_port_mac(o, port) pd["bridge"] = "" for (k, v) in port.get_parameters().items(): pd[k] = v ports.append(pd) # for any ports that don't have a device, assign one used_ports = [x["device"] for x in ports if ("device" in x)] avail_ports = [ "eth%d" % i for i in range(0, 64) if ("eth%d" % i not in used_ports) ] for port in ports: if not port.get("device", None): port["device"] = avail_ports.pop(0) return ports
def sync_record(self, record): if (not record.tenant.id): raise DeferredException("Privilege waiting on VPN Tenant ID") certificate = self.get_certificate_name(record) tenant = OpenVPNTenant.get_tenant_objects().filter( pk=record.tenant.id)[0] if (not tenant): raise DeferredException("Privilege waiting on VPN Tenant") # Only add a certificate if ones does not yet exist pki_dir = OpenVPNService.get_pki_dir(tenant) if (not os.path.isfile(pki_dir + "/issued/" + certificate + ".crt")): OpenVPNService.execute_easyrsa_command( pki_dir, "build-client-full " + certificate + " nopass") tenant.save() record.save()
def sync_record(self, sc): logger.info("Sync'ing ServiceController %s" % sc) if sc.xos and (not sc.xos.enable_build): raise DeferredException("XOS build is currently disabled") unready = self.check_controller_unready(sc) if unready: raise Exception("Controller %s has unready resources: %s" % (str(sc), ",".join([str(x) for x in unready]))) dockerfile = self.create_synchronizer_dockerfile(sc) if dockerfile: dockerfiles = [dockerfile] else: dockerfiles = [] tenant_fields = { "dockerfiles": dockerfiles, "build_dir": self.build_dir, "ansible_tag": sc.__class__.__name__ + "_" + str(sc.id) } path = "servicecontroller" res = run_template(self.playbook, tenant_fields, path=path, object=sc)
def sync_record(self, sc): logger.info("Sync'ing XOSComponent %s" % sc) if sc.xos and (not sc.xos.enable_build): raise DeferredException("XOS build is currently disabled") unready = self.check_controller_unready(sc) if unready: raise Exception("Controller %s has unready resources: %s" % (str(sc), ",".join([str(x) for x in unready])))
def get_parent_port_mac(self, instance, port): if not instance.parent: raise Exception("instance has no parent") for parent_port in instance.parent.ports.all(): if parent_port.network == port.network: if not parent_port.mac: raise DeferredException("parent port on network %s does not have mac yet" % parent_port.network.name) return parent_port.mac raise Exception("failed to find corresponding parent port for network %s" % port.network.name)
def sync_record(self, xos): logger.info("Sync'ing XOS %s" % xos) if not xos.docker_project_name: raise Exception("xos.docker_project_name is not set") if not xos.db_container_name: raise Exception("xos.db_container_name is not set") if (not xos.enable_build): raise DeferredException("XOS build is currently disabled") # We've seen the XOS object get synced before the ServiceController object # is synced. This results in the XOS UI container getting built with files # from that controller missing. So let's try to defer. # # It could be argued that we should continue to defer if the ServiceController # is in error state, but it is important that a single broken service does # not takedown the entirety of XOS. for scr in xos.loadable_modules.all(): if (scr.backend_status is not None) and (scr.backend_status.startswith("0")): raise DeferredException( "Detected unsynced loadable module. Deferring.") self.create_docker_compose() dockerfiles = [self.create_ui_dockerfile()] tenant_fields = { "dockerfiles": dockerfiles, "build_dir": self.build_dir, "docker_project_name": xos.docker_project_name, "ansible_tag": xos.__class__.__name__ + "_" + str(xos.id) } path = "XOS" res = run_template(self.playbook, tenant_fields, path=path)
def sync_record(self, xos): logger.info("Sync'ing XOS %s" % xos) if (not xos.enable_build): raise DeferredException("XOS build is currently disabled") self.create_docker_compose() dockerfiles = [self.create_ui_dockerfile()] tenant_fields = { "dockerfiles": dockerfiles, "build_dir": self.build_dir, "docker_project_name": xos.docker_project_name, "ansible_tag": xos.__class__.__name__ + "_" + str(xos.id) } path = "XOS" res = run_template(self.playbook, tenant_fields, path=path)