def gen_agent_by_deploy(progress, deployId, reportKind, deployStage=""): agent_wrapper = {} agent_wrapper[deployId] = [] # get total alive hosts if deployStage == TOTAL_ALIVE_HOST_REPORT: for agent in progress['agents']: if agent['deployId'] == deployId: agent_wrapper[deployId].append(agent) # get unknown (unreachable) hosts elif reportKind == UNKNOWN_HOST_REPORT: for agent in progress['missingHosts']: # create a fake agent to pass into the agent wrapper missingAgent = { 'hostName': agent, 'lastErrorCode': UNKNOWN_HOSTS_CODE } agent_wrapper[deployId].append(missingAgent) # get provisioning hosts elif reportKind == PROVISION_HOST_REPORT: for host in progress['provisioningHosts']: # create a fake agent to pass into the agent wrapper newHost = { 'hostName': host.get('hostName'), 'hostId': host.get('hostId'), 'lastErrorCode': PROVISION_HOST_CODE } agent_wrapper[deployId].append(newHost) # get all hosts (alive + unknown) elif reportKind == TOTAL_HOST_REPORT: for agent in progress['agents']: agent_wrapper[deployId].append(agent) for agent in progress['missingHosts']: missingAgent = { 'hostName': agent, 'lastErrorCode': UNKNOWN_HOSTS_CODE } agent_wrapper[deployId].append(missingAgent) # get all failed status elif reportKind == FAILED_HOST_REPORT: for agent in progress['agents']: if is_agent_failed(agent): agent_wrapper[deployId].append(agent) else: for agent in progress['agents']: if agent['deployId'] == deployId: if agent['deployStage'] == deployStage: agent_wrapper[deployId].append(agent) return agent_wrapper
def gen_agent_by_deploy(progress, deployId, reportKind, deployStage=""): agent_wrapper = {} agent_wrapper[deployId] = [] # get total alive hosts if deployStage == TOTAL_ALIVE_HOST_REPORT: for agent in progress['agents']: if agent['deployId'] == deployId: agent_wrapper[deployId].append(agent) # get unknown (unreachable) hosts elif reportKind == UNKNOWN_HOST_REPORT: for agent in progress['missingHosts']: # create a fake agent to pass into the agent wrapper missingAgent = {'hostName': agent, 'lastErrorCode': UNKNOWN_HOSTS_CODE} agent_wrapper[deployId].append(missingAgent) # get provisioning hosts elif reportKind == PROVISION_HOST_REPORT: for host in progress['provisioningHosts']: # create a fake agent to pass into the agent wrapper newHost = {'hostName': host.get('hostName'), 'hostId': host.get('hostId'), 'lastErrorCode': PROVISION_HOST_CODE} agent_wrapper[deployId].append(newHost) # get all hosts (alive + unknown) elif reportKind == TOTAL_HOST_REPORT: for agent in progress['agents']: agent_wrapper[deployId].append(agent) for agent in progress['missingHosts']: missingAgent = {'hostName': agent, 'lastErrorCode': UNKNOWN_HOSTS_CODE} agent_wrapper[deployId].append(missingAgent) # get all failed status elif reportKind == FAILED_HOST_REPORT: for agent in progress['agents']: if is_agent_failed(agent): agent_wrapper[deployId].append(agent) else: for agent in progress['agents']: if agent['deployId'] == deployId: if agent['deployStage'] == deployStage: agent_wrapper[deployId].append(agent) return agent_wrapper
def get(self, request, name, stage, hostname): host = environ_hosts_helper.get_host_by_env_and_hostname(request, name, stage, hostname) show_terminate = False if host and host.get('state') and host.get('state') != 'PENDING_TERMINATE' and host.get('state') != 'TERMINATING' and host.get('state') != 'TERMINATED': show_terminate = True # TODO deprecated it asg = '' if host and host.get('groupName'): group_info = groups_helper.get_group_info(request, host.get('groupName')) if group_info and group_info["asgStatus"] == "ENABLED": asg = host.get('groupName') # gather the env name and stage info agents = agents_helper.get_agents_by_host(request, hostname) agent_wrappers = [] show_force_terminate = False for agent in agents: if agent.get('deployStage') == 'STOPPING' or agent.get('deployStage') == 'STOPPED': if is_agent_failed(agent): show_force_terminate = True agent_wrapper = {} agent_wrapper["agent"] = agent envId = agent['envId'] agent_env = environs_helper.get(request, envId) agent_wrapper["env"] = agent_env agent_wrapper["error"] = "" if agent.get('lastErrno', 0) != 0: agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'], agent_env['stageName'], hostname) agent_wrappers.append(agent_wrapper) return render(request, 'hosts/host_details.html', { 'env_name': name, 'stage_name': stage, 'hostname': hostname, 'host': host, 'agent_wrappers': agent_wrappers, 'show_terminate': show_terminate, 'show_force_terminate': show_force_terminate, 'asg_group': asg, 'pinterest': IS_PINTEREST, })
def get_agent_wrapper(request, hostname): # gather the env name and stage info agents = agents_helper.get_agents_by_host(request, hostname) agent_wrappers = [] show_force_terminate = False for agent in agents: if agent.get('deployStage') == 'STOPPING' or agent.get('deployStage') == 'STOPPED': if is_agent_failed(agent): show_force_terminate = True agent_wrapper = {} agent_wrapper["agent"] = agent envId = agent['envId'] agent_env = environs_helper.get(request, envId) agent_wrapper["env"] = agent_env agent_wrapper["error"] = "" if agent.get('lastErrno', 0) != 0: agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'], agent_env['stageName'], hostname) agent_wrappers.append(agent_wrapper) return agent_wrappers, show_force_terminate