( Vamp | 2021. 03. 10., sze – 15:00 )

Kesz a cucc. Nem szep, de legalabb csunya :D

 

Ellenben mukodik:

 

import atexit
import pyVmomi
import ssl

from pyVmomi import vim, vmodl
from pyVim.connect import SmartConnect, Disconnect

domain = "domain"

context = ssl._create_unverified_context()
si = SmartConnect(host='hostname', port='443', user='username', pwd='pass', sslContext=context)


atexit.register(Disconnect, si)
file = open('/sys/devices/virtual/dmi/id/product_uuid')
uuid = file.read().strip().lower()
file.close()

uuidString = uuid.replace("-","")

newOrder = [6,7,4,5,2,3,0,1,10,11,8,9,14,15,12,13]
for i in range(16, len(uuidString)): newOrder.append(i)

uuid_string = str.join('', [uuidString[i] for i in newOrder])

uuid_string = uuid_string[:8] + '-' + uuid_string[8:]
uuid_string = uuid_string[:13] + '-' + uuid_string[13:]
uuid_string = uuid_string[:18] + '-' + uuid_string[18:]
guid = uuid_string[:23] + '-' + uuid_string[23:]


search_index = si.content.searchIndex
vm = search_index.FindByUuid(None, guid, True, False)

hostname = vm.summary.config.name.lower()

fqdn = hostname + domain

subprocess.call(["hostnamectl", "set-hostname", fqdn])

subprocess.call(["hostnamectl", "set-hostname", "--pretty", hostname])

 

A wiki szocikk segitett. ezek szerint a linux "szabvanyos" (ugye a wiki azt irja a big-endian a legelterjedtebb formatum. a VMware viszont a microsoft fele mixed-endian-t hasznalja (....) szoval lenyegeben csak a sorrendet kellett beloni.

 

Koszi megegyszer a segitseget, elinditottal a helyes uton :)

 

Szerk: igy van teljesen kesz. Hozzadtam a hostname beallitast is. most mar csak tesztelni kell....:)