Skip to content

Development #1

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7034e28
gitignore
mismailzz Nov 16, 2021
0aa6fdd
Ignore python cache paths
mismailzz Nov 16, 2021
1c97edc
Update paths
mismailzz Nov 16, 2021
daa778d
Untrack files in .gitignore
mismailzz Nov 16, 2021
2fa7db6
Bootstrap button class added
mismailzz Nov 16, 2021
027eea4
temp update
mismailzz Nov 16, 2021
699b42a
temporary removed
mismailzz Nov 17, 2021
8b989f2
Again frontail added to dev
mismailzz Nov 17, 2021
1ac5de7
delete
mismailzz Nov 17, 2021
68a9b31
frontail submodule added
mismailzz Nov 17, 2021
12e74b7
varaibleSetup
mismailzz Nov 17, 2021
fa35e46
output variable to file
mismailzz Nov 17, 2021
16c5af8
output variable file
mismailzz Nov 17, 2021
f2bb857
getvminfo save results
mismailzz Nov 17, 2021
1317fc2
get vminfo playbook enabled
mismailzz Nov 17, 2021
32ed6e5
ansible.cfg and inventory.ini added
mismailzz Nov 17, 2021
61d5c09
Ansible command updated
mismailzz Nov 17, 2021
2d9042e
ansible_vmresult path updated in vminfo.yml
mismailzz Nov 17, 2021
fe9490a
connect/execute vm information
mismailzz Nov 17, 2021
1789cee
makemigration db for vminfo
mismailzz Nov 17, 2021
bb61ea0
update db
mismailzz Nov 17, 2021
ad56b42
rectified form name
mismailzz Nov 17, 2021
7948757
css file update for password
mismailzz Nov 17, 2021
a7e6e2b
define form labels
mismailzz Nov 17, 2021
068b167
dark button
mismailzz Nov 17, 2021
110f764
execute button name added
mismailzz Nov 18, 2021
88e140b
vm select variablefile creation
mismailzz Nov 18, 2021
15e81b1
vmpatch data gather
mismailzz Nov 18, 2021
a72a5b3
debug
mismailzz Nov 18, 2021
91b9c4b
debug
mismailzz Nov 18, 2021
fbe2561
debug
mismailzz Nov 18, 2021
ea5b54f
patch commands setup
mismailzz Nov 18, 2021
69a94ef
log file for cmd
mismailzz Nov 18, 2021
f3acab4
endline
mismailzz Nov 18, 2021
cd28f6e
Merge branch 'vmfrontend' into development
mismailzz Nov 18, 2021
59ae308
delete php file
mismailzz Nov 18, 2021
fcd9d52
Merge branch 'vmfrontend' into development - php file deleted
mismailzz Nov 18, 2021
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Don't track python cache files
patching/__pycache__/*
patching/migrations/__pycache__/*
scripts/patching/__pycache__/*
vsmooth/__pycache__/*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "frontail/frontail"]
path = frontail/frontail
url = https://github.com/mismailzz/frontail.git
Binary file modified db.sqlite3
Binary file not shown.
Binary file removed patching/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/forms.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file removed patching/__pycache__/views.cpython-36.pyc
Binary file not shown.
Binary file removed patching/__pycache__/views.cpython-39.pyc
Binary file not shown.
23 changes: 20 additions & 3 deletions patching/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.core import validators
from patching.models import HypervisorInfo
from patching.models import HypervisorInfo, VirtualMachineInfo


class HypervisorInfo_Form(forms.ModelForm):
Expand All @@ -11,6 +11,23 @@ class Meta:
widgets = {
'esxi_hostname': forms.TextInput(attrs={'class': 'mycssclass'}),
'esxi_username': forms.TextInput(attrs={'class': 'mycssclass'}),
'esxi_password': forms.TextInput(attrs={'class': 'mycssclass'}),
'esxi_password': forms.PasswordInput(),
'esxi_password': forms.PasswordInput(attrs={'class': 'mycssclass'}),
}
labels = {
'esxi_hostname': ('ESXi Hostname'),
'esxi_username': ('ESXi Username'),
'esxi_password': ('ESXi Password'),
}

class VirtualMachineInfo_Form(forms.ModelForm):
class Meta:
model = VirtualMachineInfo
fields = ('vm_username', 'vm_password',)
widgets = {
'vm_username': forms.TextInput(attrs={'class': 'mycssclass'}),
'vm_password': forms.PasswordInput(attrs={'class': 'mycssclass'}),
}
labels = {
'vm_username': ('VM Username'),
'vm_password': ('VM Password'),
}
26 changes: 26 additions & 0 deletions patching/migrations/0004_auto_20211117_1758.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.5 on 2021-11-17 17:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('patching', '0003_auto_20211114_0659'),
]

operations = [
migrations.CreateModel(
name='VirtualMachineInfo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('vm_username', models.CharField(max_length=100)),
('vm_password', models.CharField(max_length=100)),
],
),
migrations.AlterField(
model_name='hypervisorinfo',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed patching/migrations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed patching/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions patching/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class HypervisorInfo(models.Model):
esxi_hostname = models.CharField(max_length=100)
esxi_username = models.CharField(max_length=100)
esxi_password = models.CharField(max_length=100)

class VirtualMachineInfo(models.Model):
vm_username = models.CharField(max_length=100)
vm_password = models.CharField(max_length=100)
47 changes: 36 additions & 11 deletions patching/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.shortcuts import render
from . import forms
from patching.forms import HypervisorInfo_Form
from patching.forms import HypervisorInfo_Form, VirtualMachineInfo_Form
import scripts.patching.vmfilter as ansible_vminfo
import scripts.patching.controller as ansible_controller
import json
import os

Expand All @@ -12,9 +13,16 @@ def index(request):
return render(request, 'patching/index.html')



def connect_select_patch(request):
hypervisorForm = HypervisorInfo_Form()
virtualMachineForm = VirtualMachineInfo_Form()

vhostname = ""
vusername = ""
vpassword = ""
vm_username = ""
vm_password = ""
ansible_playbookPath = "playbook/patching/"

virtual_machine_dict = {}

Expand All @@ -24,15 +32,14 @@ def connect_select_patch(request):

if hypervisorForm.is_valid():
print("Validation")
print("IP: ", hypervisorForm.cleaned_data['esxi_hostname'])
print("User: ", hypervisorForm.cleaned_data['esxi_username'])
print("Password: ", hypervisorForm.cleaned_data['esxi_password'])
vhostname = hypervisorForm.cleaned_data['esxi_hostname']
vusername = hypervisorForm.cleaned_data['esxi_username']
vpassword = hypervisorForm.cleaned_data['esxi_password']
vmware_hypervisor = ansible_controller.VMwareHypervisorVariables(vhostname, vusername, vpassword, ansible_playbookPath)
vmware_hypervisor.vmInfo()
vm_resultjson()
vm_readJson()
#form.save(commit=True)
#return index(request)
#my_dict_vms = {'virtual_machines': vm_readJson()}
#return render(request, 'patching/patch_panel.html', context=my_dict_vms)
virtual_machine_dict = vm_readJson()
else:
print('ERROR FORM INVALID')
Expand All @@ -42,9 +49,27 @@ def connect_select_patch(request):
if request.POST.get('vm_names'):
selected_vms = request.POST.get('vm_names');
print("Virtual Machines Selected:", selected_vms)

#return render(request,'patching/patch_panel.html',{'form1':hypervisorForm, 'form2': selectVMForm, 'virtual_machines': virtual_machine_dict})
return render(request,'patching/patch_panel.html',{'form1':hypervisorForm, 'virtual_machines': virtual_machine_dict})
vmware_hypervisor = ansible_controller.VMwareHypervisorVariables()
vmware_hypervisor.vmSelectedInfo(selected_vms, ansible_playbookPath)

elif 'executevmbutton' in request.POST:
virtualMachineForm = VirtualMachineInfo_Form(request.POST)
vmware_hypervisor = ansible_controller.VMwareHypervisorVariables()

if virtualMachineForm.is_valid():
#GET THE CREDENTIONALS INFORMATION OF THE VIRTUAL MACHINES
vm_username = virtualMachineForm.cleaned_data['vm_username']
vm_password = virtualMachineForm.cleaned_data['vm_password']
vmware_hypervisor.vmCredentialsInfo(vm_username, vm_password, ansible_playbookPath)
#GET THE PATCH COMMANDS INFORMATION FROM THE TEXTAREA AND SAVE TO FILE
if request.POST.get('vmpatch'):
vm_patchCommands = request.POST.get('vmpatch')
print(vm_patchCommands)
vmware_hypervisor.vm_patchCommands(vm_patchCommands, ansible_playbookPath)
vmware_hypervisor.vmPatch()


return render(request,'patching/patch_panel.html',{'form1':hypervisorForm, 'virtual_machines': virtual_machine_dict, 'form2':virtualMachineForm,})


def vm_resultjson():
Expand Down
File renamed without changes.
Empty file added playbook/patching/inventory.ini
Empty file.
20 changes: 3 additions & 17 deletions playbook/patching/vmInfo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
hosts: local
gather_facts: no
vars_files:
- variablefile
- hypvariablefile
tasks:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
Expand All @@ -18,20 +18,6 @@
- name: Delete Existing file
file:
state: absent
path: varDir/temp
path: ../../temp/patching/ansible_vmresult
delegate_to: localhost
- local_action: copy content={{ vminfo }} dest=varDir/temp

- name: Display results
debug:
var: vminfo

- name: Run a script using an executable in a system path
ansible.builtin.script: ./scripts/filter.py
args:
executable: python3
delegate_to: localhost
register: vmDict
- name: Resultant Dictionary
debug:
var: vmDict.stdout_lines
- local_action: copy content={{ vminfo }} dest=../../temp/patching/ansible_vmresult
39 changes: 39 additions & 0 deletions playbook/patching/vmpatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- hosts: localhost
gather_facts: no

vars_files:
- hypvariablefile
- vm_patchvariablefile
- vmvariablefile
- patchCommand.yml

tasks:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
vm_type: vm
validate_certs: no
delegate_to: localhost
register: vminfo

- name: Execute the targeted commands - CLEAN/LIST REPO/UPDATE
community.vmware.vmware_vm_shell:
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
validate_certs: no
vm_id: "{{ item[0].guest_name }}"
vm_username: "{{ guestvm_username }}"
vm_password: "{{ guestvm_password }}"
wait_for_process: True
vm_shell: "/bin/echo"
vm_shell_args: "$( {{ item[1] }} )"
when: (item[0].power_state == "poweredOn") and (item[0].guest_name in vm_toPatched)
with_nested:
- "{{ vminfo.virtual_machines }}"
- "{{ run_commands }}"
delegate_to: localhost
register: result
Binary file removed scripts/patching/__pycache__/vmfilter.cpython-36.pyc
Binary file not shown.
Binary file removed scripts/patching/__pycache__/vmfilter.cpython-39.pyc
Binary file not shown.
Loading