Beispiel #1
0
class ConcreteManager(manager.Manager):
    """Send cmd to TMC to create server.Collect all resources state"""

    RPC_API_VERSION = '1.0'

    target = messaging.Target(version=RPC_API_VERSION)

    def __init__(self, service_name=None, *args, **kwargs):
        super(ConcreteManager, self).__init__(*args, **kwargs)
        self.inspector = inspect_tmc.InspectManager("abc")
        self.data_handle = ConvertDBData()
        self.aging_data = AgingData()
        self.driver = importutils.import_object(CONF.concrete_driver)
        self.ResCollectThPool = ThreadPool(CONF.concrete_collect_res_thread_num)
        self.StateCollectThPool = ThreadPool(
            CONF.concrete_collect_state_thread_num)

    def resources_collect(self, context):
        rc_start_time = datetime(1, 1, 1)
        while True:
            rc_period = datetime.utcnow() - rc_start_time
            rc_start_time = datetime.utcnow().replace(microsecond=0)

            host_urls = self.inspector.get_host_urls(context)
            for host_url in host_urls:
                self.ResCollectThPool.queueTask(self.driver.service_root,
                                                (host_url, '/rest/v1/'))
            self.ResCollectThPool.waitFinish(interval=1)

            self.aging_data.aging_resource(rc_start_time)
            self.aging_data.aging_tmc(rc_period)

            time.sleep(CONF.concrete_update_resource_interval)

    def need_update_server_state(self, last_action, task_state, server_state):
        if server_state == SERVER_DELETED or \
                        task_state == TASK_SCHEDULING:
            return False
        else:
            return True

    @periodic_task.periodic_task(spacing=CONF.concrete_inspect_tmc_interval,
                                 run_immediately=True)
    def inspect_tmc(self, context):
        self.inspector.inspect_tmc()


    def servers_state_collect(self, context):
        while True:
            servers = self.db.servers_get_all(context)
            # high_prior_servers=[]
            # low_prior_servers=[]
            # for server in servers:
            #     if not server.deleted:
            #         continue
            #
            #     server=dict(server)
            #     if self.need_update_server_state(server['deleted_at'],
            #                      server['task_state'], server['node_state']):
            #         if server['task_state'] == TASK_STABLE:
            #             low_prior_servers.append(server)
            #         else:
            #             # TASK_SPAWNING,TASK_STOPPING,TASK_DELETING...
            #             # new request command, get these server state first
            #             high_prior_servers.append(server)
            #
            # query_servers = high_prior_servers+low_prior_servers
            for server in servers:
                self.StateCollectThPool.queueTask(
                    self.driver.server_state_collect, (context, server))

            self.StateCollectThPool.waitFinish(interval=1)

            time.sleep(CONF.concrete_update_state_interval)

    def init_host(self):
        ctxt = context.get_admin_context()
        thread.start_new_thread(self.resources_collect, (ctxt,))
        thread.start_new_thread(self.servers_state_collect, (ctxt,))
        # second arg need be a tuple.  (ctxt,) is tuple, (ctxt) is not tuple

    def create_server(self, context, server_properties, weighed_resource):
        self.driver.create_server(context, server_properties, weighed_resource)

    def delete_server(self, context, system_id):
        return self.driver.delete_server(context, system_id)

    def reset_blade(self, context, lid, type):
        return self.driver.reset_blade(context, lid, {'ResetType': type})

    def config_blade(self, context, lid, config):
        return self.driver.config_blade(context, lid, config)

    def config_port(self, context, lid, config):
        return self.driver.config_port(context, lid, config)

    def reset_machine(self, context, system_id, body):
        return self.driver.reset_machine(context, system_id, body)