Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added host protection status #1641

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deploy-board/deploy_board/templates/environs/env_hosts.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ <h4 class="panel-title pull-left">Hosts</h4>

{% include "environs/env_tabs.tmpl" with envTabKind="deploy" %}

{% if show_protected_hosts is None %}
<p><a href="/env/{{ env.envName }}/{{stage}}/hosts/?show_protected_hosts"> <button class="btn btn-primary" >Show protected hosts</button> </a></p>
{% endif %}
<!-- Used for generating the Show Host Names button -->
<div class="modal fade" id="showHosts" tabindex="-1" role="dialog" aria-labelledby="showHostsLabel">
<div class="modal-dialog" role="document">
Expand Down
9 changes: 9 additions & 0 deletions deploy-board/deploy_board/templates/host_side_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ <h4 class="panel-title pull-left">Hosts</h4>
</div>

{% if pinterest %}
<div class="row">
<p>
{% if not instance_protected %}
Host is not protected.
{% else %}
Host is protected.
{% endif %}
</p>
</div>
{% if show_terminate %}
<div class="row">
<button id="terminateBtn" class="deployToolTip btn btn-default btn-block" data-target="#terminateHost"
Expand Down
18 changes: 18 additions & 0 deletions deploy-board/deploy_board/templates/hosts/hosts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<th>StartDate(-08:00)</th>
<th>LastUpdate</th>
<th>ErrorCode</th>
{% if show_protection_status %}
<th>Protected</th>
{% endif %}
</tr>
{% for agent in agents %}
<tr>
Expand All @@ -57,6 +60,9 @@
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
{% if show_protection_status %}
<td>N/A</td>
{% endif %}
{% elif agent.lastErrorCode|isProvisioningHost %}
<td><input type="checkbox" value="{{ agent.hostId | default_if_none:'' }}"></td>
<td><a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agent.hostName }}">{{ agent.hostName }}</a></td>
Expand All @@ -67,6 +73,9 @@
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
{% if show_protection_status %}
<td>N/A</td>
{% endif %}
{% else %}
<td><input type="checkbox" value="{{ agent.hostId }}"></td>
<td><a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agent.hostName }}">{{ agent.hostName }}</a></td>
Expand All @@ -77,6 +86,15 @@
<td>{{ agent.startDate|convertTimestamp }}</td>
<td>{{ agent.lastUpdateDate|convertTimestamp }}</td>
<td>{{ agent.lastErrorCode }}</td>
{% if show_protection_status %}
<td>
{% if agent.hostId in protected_hosts %}
Protected
{% else %}
Not protected
{% endif %}
</td>
{% endif %}
{% endif %}
</tr>
{% endfor %}
Expand Down
10 changes: 10 additions & 0 deletions deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,17 +1426,27 @@ def get_hosts(request, name, stage):
title = "All hosts"

agents_wrapper = {}
show_protected_hosts = request.GET.get("show_protected_hosts")
host_ids = []
for agent in agents:
if agent['deployId'] not in agents_wrapper:
agents_wrapper[agent['deployId']] = []
agents_wrapper[agent['deployId']].append(agent)
host_ids.append(agent['hostId'])

protected_hosts = []
if show_protected_hosts:
protected_hosts = hosts_helper.get_hosts_is_protected(request, host_ids)

return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"stage": stage,
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
"protected_hosts": protected_hosts,
"show_protected_hosts": show_protected_hosts
})


Expand Down
20 changes: 16 additions & 4 deletions deploy-board/deploy_board/webapp/helpers/hosts_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,42 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-
"""Collection of all hosts related calls
"""
"""Collection of all hosts related calls"""

from deploy_board.webapp.helpers.deployclient import DeployClient
from deploy_board.webapp.helpers.cmdbapiclient import CmdbApiClient
from deploy_board.webapp.helpers.rodimus_client import RodimusClient

deployclient = DeployClient()
cmdbapi_client = CmdbApiClient()
rodimus_client = RodimusClient()


def get_hosts_by_name(request, host_name):
return deployclient.get("/hosts/%s" % host_name, request.teletraan_user_id.token)


def query_cmdb(query, fields, account_id):
return cmdbapi_client.query(query, fields, account_id)


def get_cmdb_host_info(host_id, account_id):
return cmdbapi_client.get_host_details(host_id, account_id)


def get_hosts_is_protected(request, host_ids):
return rodimus_client.post(
"/hosts/state?actionType=PROTECTED",
request.teletraan_user_id.token,
data=host_ids,
)
Loading