예제 #1
0
 def provision(self, dnsaas):
     if dnsaas is not None:
         self.dns_configurator = ImsDnsClient(dnsaas)
         self.is_dnsaas = True
     while not self.topology.state == "DEPLOYED":
         logger.info("topology not yet in status deployed, currently %s" % self.topology.state)
         time.sleep(5)
     self.configure_topology()
예제 #2
0
class CheckerThread(threading.Thread):
    def __init__(self, topology):
        super(CheckerThread, self).__init__()
        self.heatclient = HeatClient()
        self.topology = topology
        self.db = DatabaseManager()
        self.is_stopped = False
        self.is_dnsaas = False
        self.dnsaas = None
        self.novac = NovaClient()
        self.dns_configurator = None
        self.neutronc = NeutronClient(
            utilSys.get_endpoint("network", region_name=SysUtil().get_sys_conf()["os_region_name"]), utilSys.get_token()
        )
        self.dns_configurator = None

    def run(self):
        while not self.is_stopped:
            self.update_topology_state()
            if self.topology.state == "DELETED":
                TopologyOrchestrator.delete(self.topology)
                self.is_stopped = True
            for si in self.topology.service_instances:
                if not self.is_stopped:
                    for unit in si.units:
                        if len(unit.ports) == 0:
                            self.set_ips(unit)
            time.sleep(30)

    def provision(self, dnsaas):
        if dnsaas is not None:
            self.dns_configurator = ImsDnsClient(dnsaas)
            self.is_dnsaas = True
        while not self.topology.state == "DEPLOYED":
            logger.info("topology not yet in status deployed, currently %s" % self.topology.state)
            time.sleep(5)
        self.configure_topology()

    def configure_topology(self):
        for si in self.topology.service_instances:
            si.adapter_instance = FactoryServiceAdapter.get_agent(si.service_type, si.adapter)
            for unit in si.units:
                try:
                    config = {}
                    config["hostname"] = unit.hostname
                    config["ips"] = unit.ips
                    config["zabbix_ip"] = os.environ["ZABBIX_IP"]
                    config["floating_ips"] = unit.floating_ips
                    config["hostname"] = unit.hostname
                except:
                    logging.error("there was an issue getting the config for the vnf")

                try:
                    logging.info("sending requests to the adapter %s with config" % config)
                    si.adapter_instance.preinit(config)
                    si.adapter_instance.install(config)
                except Exception, e:
                    logging.error("error while configuring vnf %s" % e)

                # add relations
                for ext_service in si.relation:
                    logger.info(
                        "solving dependencies between si %s and external service %s" % (si.name, ext_service.name)
                    )
                    if ext_service.name == "dns" and self.is_dnsaas is True:
                        ext_unit = Unit(hostname=None, state="INITIALISING")
                        ext_si = ServiceInstance(
                            name="dns", service_type="dns", state="INITIALISING", image="test", flavor="test", size={}
                        )
                        ext_unit.ips["mgmt"] = os.environ["DNSAAS_IP"]
                        self.dns_configurator.configure_dns_entry(si.service_type)(unit.ips["mgmt"], unit.hostname)
                        si.adapter_instance.add_dependency(config, ext_unit, ext_si)
                    else:
                        service_list = self.db.get_by_name(ServiceInstance, ext_service.name)
                        if len(service_list) == 1:
                            ext_si = service_list[0]
                            for ext_unit in ext_si.units:
                                logging.info(
                                    "sending request add_dependency to the adapter %s with config %s and ext_unit %s"
                                    % (si.service_type, config, ext_unit)
                                )
                                si.adapter_instance.add_dependency(config, ext_unit, ext_si)
                try:
                    si.adapter_instance.pre_start(config)
                    si.adapter_instance.start(config)
                except Exception, e:
                    logging.error("error while configuring vnf %s" % e)