{% extends 'virtualization/virtualmachine/base.html' %}
{% load buttons %}
{% load static %}
{% load helpers %}
{% load plugins %}

{% block content %}
<div class="row my-3">
	<div class="col col-md-6">
        <div class="card">
            <h5 class="card-header">
                Virtual Machine
            </h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row">Name</th>
                        <td>{{ object }}</td>
                    </tr>
                    <tr>
                        <th scope="row">Status</th>
                        <td>
                            <span class="badge bg-{{ object.get_status_class }}">{{ object.get_status_display }}</span>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Role</th>
                        <td>
                            {% if object.role %}
                                <a href="{{ object.role.get_absolute_url }}">{{ object.role }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Platform</th>
                        <td>
                            {% if object.platform %}
                                <a href="{{ object.platform.get_absolute_url }}">{{ object.platform }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Tenant</th>
                        <td>
                            {% if object.tenant %}
                                {% if object.tenant.group %}
                                    <a href="{{ object.tenant.group.get_absolute_url }}">{{ object.tenant.group }}</a> /
                                {% endif %}
                                <a href="{{ object.tenant.get_absolute_url }}">{{ object.tenant }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Primary IPv4</th>
                        <td>
                            {% if object.primary_ip4 %}
                                <a href="{% url 'ipam:ipaddress' pk=object.primary_ip4.pk %}">{{ object.primary_ip4.address.ip }}</a>
                                {% if object.primary_ip4.nat_inside %}
                                    <span>(NAT for {{ object.primary_ip4.nat_inside.address.ip }})</span>
                                {% elif object.primary_ip4.nat_outside %}
                                    <span>(NAT: {{ object.primary_ip4.nat_outside.address.ip }})</span>
                                {% endif %}
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Primary IPv6</th>
                        <td>
                            {% if object.primary_ip6 %}
                                <a href="{% url 'ipam:ipaddress' pk=object.primary_ip6.pk %}">{{ object.primary_ip6.address.ip }}</a>
                                {% if object.primary_ip6.nat_inside %}
                                    <span>(NAT for {{ object.primary_ip6.nat_inside.address.ip }})</span>
                                {% elif object.primary_ip6.nat_outside %}
                                    <span>(NAT: {{ object.primary_ip6.nat_outside.address.ip }})</span>
                                {% endif %}
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        {% include 'inc/custom_fields_panel.html' %}
        {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='virtualization:virtualmachine_list' %}
        {% include 'inc/comments_panel.html' %}
        {% plugin_left_page object %}
    </div>
	<div class="col col-md-6">
        <div class="card">
            <h5 class="card-header">
                Cluster
            </h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row">Cluster</th>
                        <td>
                            {% if object.cluster.group %}
                                <a href="{{ object.cluster.group.get_absolute_url }}">{{ object.cluster.group }}</a> /
                            {% endif %}
                            <a href="{{ object.cluster.get_absolute_url }}">{{ object.cluster }}</a>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Cluster Type</th>
                        <td>{{ object.cluster.type }}</td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="card">
            <h5 class="card-header">
                Resources
            </h5>
            <div class="card-body">
                <table class="table table-hover attr-table">
                    <tr>
                        <th scope="row"><i class="mdi mdi-gauge"></i> Virtual CPUs</th>
                        <td>{{ object.vcpus|placeholder }}</td>
                    </tr>
                    <tr>
                        <th scope="row"><i class="mdi mdi-chip"></i> Memory</th>
                        <td>
                            {% if object.memory %}
                                {{ object.memory|humanize_megabytes }}
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row"><i class="mdi mdi-harddisk"></i> Disk Space</th>
                        <td>
                            {% if object.disk %}
                                {{ object.disk }} GB
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="card">
            <h5 class="card-header">
                Services
            </h5>
            <div class="card-body">
            {% if services %}
                <table class="table table-hover">
                    {% for service in services %}
                        {% include 'ipam/inc/service.html' %}
                    {% endfor %}
                </table>
            {% else %}
                <span class="text-muted">None</span>
            {% endif %}
            </div>
            {% if perms.ipam.add_service %}
                <div class="card-footer text-end noprint">
                    <a href="{% url 'virtualization:virtualmachine_service_assign' virtualmachine=object.pk %}" class="btn btn-sm btn-primary">
                        <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Assign Service
                    </a>
                </div>
            {% endif %}
        </div>
        {% plugin_right_page object %}
    </div>
</div>
<div class="row">
    <div class="col col-md-12">
        {% plugin_full_width_page object %}
    </div>
</div>
{% endblock %}
