Skip to content
Snippets Groups Projects
Commit 589d3fe3 authored by Andreas Hamacher's avatar Andreas Hamacher Committed by Jafar Lie
Browse files

deleted unused X templates. xorg.conf will be regenerated on reboot now as...

deleted unused X templates. xorg.conf will be regenerated on reboot now as well as directly deployed
parent 7b0532d6
No related branches found
No related tags found
No related merge requests found
#!/bin/python -E
from jinja2 import Template, Environment, FileSystemLoader
import itertools
import subprocess
import datetime
import os
import sys
import time
import socket
from subprocess import call
import re
import json
def grab_card_ids():
# This method runs nvidia-smi to grab the card ids, then returns a list
if not os.path.isfile("/bin/nvidia-smi"):
print("nvidia-smi binary not found!")
exit(1)
cmd = ["/bin/nvidia-smi", "--query-gpu=pci.bus_id","--format=csv,noheader"]
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cards = []
for line in p.stdout.readlines():
line = line.rstrip().split(":")[2]
pcibus_num = int(re.sub('[.:]', '', line).rstrip("0"),16)
card = "PCI:0:{}:0".format(str(pcibus_num))
cards.append(card)
return cards
def grab_card_boardname():
if not os.path.isfile("/bin/nvidia-smi"):
print("nvidia-smi binary not found!")
exit(1)
cmd = ["/bin/nvidia-smi", "--query-gpu=name","--format=csv,noheader"]
cards = []
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
line = line.rstrip()
cards.append(line)
return cards
def write_xorg_conf(cards):
num_of_cards = len(cards) + 1
boardname = (grab_card_boardname())[0]
gpus = []
file_loader = FileSystemLoader('/opt/generate-xorg/template')
env = Environment(loader=file_loader)
template = env.get_template('xorg.conf.j2')
for i in range(1, num_of_cards):
monitors = []
screens = []
res = list(itertools.combinations(cards,i))
for j in range(i):
monitors.append("Monitor"+str(j))
screens.append("Screen"+str(j))
for card in res:
filename = "/etc/X11/xorg.conf." + str(i) + str(res.index(card))
template.stream({'boardname':boardname,'monitors':monitors,'screens':screens,'devices':card}).dump(filename)
if __name__ == "__main__":
cards = grab_card_ids()
write_xorg_conf(cards)
#!/usr/bin/env python
from jinja2 import Template
import itertools
import subprocess
import datetime
import os
import sys
import time
import socket
from subprocess import call
import re
import json
def getNvidia_smi_path():
if os.path.isfile("/bin/nvidia-smi"):
return "/bin/nvidia-smi"
elif os.path.isfile("/usr/bin/nvidia-smi"):
return "/usr/bin/nvidia-smi"
else:
print("nvidia-smi binary not found!")
exit(1)
def grab_card_ids():
# This method runs nvidia-smi to grab the card ids, then returns a list
cmd = [getNvidia_smi_path(), "--query-gpu=pci.bus_id","--format=csv,noheader"]
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cards = []
for line in p.stdout.readlines():
line = line.rstrip().split(":")[2]
pcibus_num = int(re.sub('[.:]', '', line).rstrip("0"),16)
card = "PCI:0:{}:0".format(str(pcibus_num))
cards.append(card)
return cards
def grab_card_boardname():
cmd = [getNvidia_smi_path(), "--query-gpu=name","--format=csv,noheader"]
cards = []
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
line = line.rstrip()
cards.append(line)
return cards
def write_xorg_conf(cards):
num_of_cards = len(cards) + 1
boardname = (grab_card_boardname())[0]
gpus = []
for i in range(1, num_of_cards):
monitors = []
screens = []
res = list(itertools.combinations(cards,i))
for j in range(i):
monitors.append("Monitor"+str(j))
screens.append("Screen"+str(j))
for card in res:
filename = "/etc/X11/xorg.conf." + str(i) + str(res.index(card))
#gpus[filename] = filename
gpus.append({'filename':filename,'boardname':boardname,'monitors':monitors,'screens':screens,'devices':card})
print(json.dumps(gpus))
if __name__ == "__main__":
# cards = grab_card_ids()
# write_xorg_conf(cards)
cards = grab_card_ids()
write_xorg_conf(cards)
''' with open("xorgconftest.j2") as f:
template = Template(f.read())
num_of_monitors = 2
monitors = []
screens = []
busid = ["PCI:0:6:0","PCI:0:7:0","PCI:0:8:0","PCI:0:9:0"]
for i in range(num_of_monitors):
monitors.append("Monitor" + str(i))
screens.append("Screen" + str(i))
#output = template.render(monitors=monitors,devices=busid)
#print(output)
res = itertools.combinations(busid,2)
listres = list(res)
for i in listres:
output = template.render(monitors=monitors,devices=i,screens=screens)
filename = "xorg.conf." + str(listres.index(i))
print(filename)
f = open(filename,"w")
f.write(output)
f.close() '''
......@@ -9,11 +9,11 @@ Section "ServerLayout"
#InputDevice "Keyboard0" "CoreKeyboard"
#InputDevice "Mouse0" "CorePointer"
Identifier "Layout0"
{% for screen in item.screens %}
{% if item.screens.index(screen) == 0 %}
Screen 0 "Screen{{item.screens.index(screen)}}"
{% for screen in screens %}
{% if screens.index(screen) == 0 %}
Screen 0 "Screen{{screens.index(screen)}}"
{% else %}
Screen {{item.screens.index(screen)}} "Screen{{item.screens.index(screen)}}" RightOf "Screen{{item.screens.index(screen)-1}}"
Screen {{screens.index(screen)}} "Screen{{screens.index(screen)}}" RightOf "Screen{{screens.index(screen)-1}}"
{% endif %}
{% endfor %}
#InputDevice "Keyboard0" "CoreKeyboard"
......@@ -41,7 +41,7 @@ Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
EndSection
{% for monitor in item.monitors %}
{% for monitor in monitors %}
Section "Monitor"
Identifier "{{monitor}}"
VendorName "Unknown"
......@@ -51,23 +51,23 @@ Section "Monitor"
Option "DPMS"
EndSection
{% endfor %}
{% for device in item.devices %}
{% for device in devices %}
Section "Device"
Identifier "Device{{item.devices.index(device)}}"
Identifier "Device{{devices.index(device)}}"
Driver "nvidia"
VendorName "NVIDIA Corporation"
boardname "{{item.boardname}}"
boardname "{{boardname}}"
BusID "{{device}}"
EndSection
{% endfor %}
{% for screen in item.screens %}
{% for screen in screens %}
Section "Screen"
Identifier "Screen{{item.screens.index(screen)}}"
Device "Device{{item.screens.index(screen)}}"
Monitor "Monitor{{item.screens.index(screen)}}"
Identifier "Screen{{screens.index(screen)}}"
Device "Device{{screens.index(screen)}}"
Monitor "Monitor{{screens.index(screen)}}"
DefaultDepth 24
Option "ProbeAllGpus" "false"
{% if item.boardname == 'GRID K1' %}
{% if boardname == 'GRID K1' %}
Option "UseDisplayDevice" "None"
{% endif %}
SubSection "Display"
......
---
- name: run nvidia-xconf-gen
script: scripts/nvidia-xconf-gen.py
register: nvidiacards
check_mode: no
changed_when: False
- name: create /opt/generate-xorg and template dirs
become: yes
file:
path: /opt/generate-xorg/template
state: directory
mode: '0755'
- name: copy nvidia-xconf-gen.py
become: yes
copy:
src: files/nvidia-xconf-gen.py
dest: /opt/generate-xorg/nvidia-xconf-gen.py
owner: root
mode: '0755'
register: gen
- name: set env for nvidia_card_lists
set_fact:
nvidiacardslist: "{{ nvidiacards.stdout | from_json }}"
- name: copy xorg.conf.j2 template
become: yes
copy:
src: xorg.conf.j2
dest: /opt/generate-xorg/template/xorg.conf.j2
owner: root
mode: '0644'
register: xorg_template
- name: generate nvidia-xorg-conf
- name: Creates ansible-generate-xorg file under /etc/cron.d
become: yes
become_user: root
template:
src: xorg.conf.j2
dest: "{{ item['filename'] }}"
with_items: "{{ nvidiacardslist }}"
cron:
name: cron job to generate xorg after reboot
special_time: reboot
user: root
job: "/opt/generate-xorg/nvidia-xconf-gen.py"
cron_file: ansible-generate-xorg
- name: copy xorg.conf.10 xorg.conf for m3f nodes
- name: call the script once if necessary
become: yes
become_user: root
command: cp /etc/X11/xorg.conf.10 /etc/X11/xorg.conf
when: "'m3f' in ansible_hostname"
command: '/opt/generate-xorg/nvidia-xconf-gen.py'
when: xorg_template.changed or gen.changed
blacklist nouveau
options nouveau modeset=0
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/vda1
# initrd /boot/initrd-[generic-]version.img
#boot=/dev/vda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-504.el6.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/vda1 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto elevator=noop biosdevname=0 console=ttyS0 rdblacklist=nouveau nouveau.modeset=0 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /boot/initramfs-2.6.32-504.el6.x86_64.img
#
# Copyright (c) 2013 NVIDIA Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This is a sample systemd service file, designed to show how the NVIDIA
# Persistence Daemon can be started.
#
[Unit]
Description=NVIDIA Persistence Daemon
Wants=syslog.target
[Service]
Type=forking
ExecStart=/usr/bin/nvidia-persistenced --persistence-mode --user nvidia-persistenced
ExecStopPost=/bin/rm -rf /var/run/nvidia-persistenced
[Install]
WantedBy=multi-user.target
options nvidia NVreg_DeviceFileMode=0666
#%PAM-1.0
auth sufficient pam_rootok.so
auth sufficient pam_permit.so
account required pam_permit.so
session optional pam_keyinit.so force revoke
......@@ -2,8 +2,10 @@
function check_xorg_conf_file_existance() {
#echo ">>> Checking xorg.conf File Existance >>>>>>>>>>>>>>>>>>>>>>>>>"
# Changing test -e (check for any type) to test -f (check only for regular file)
# To stop the script from returning 0 if it sees directories that match this pattern
test -e /etc/X11/xorg.conf
test -f /etc/X11/xorg.conf.*
if [ $? -ne 0 ]
then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment