parent
7bc6729e0c
commit
cc75f39c61
@ -0,0 +1,44 @@
|
||||
import os,json,sys,subprocess
|
||||
|
||||
def find_drive(file_path):
|
||||
for number in range(65,91):
|
||||
drive_letter = chr(number)
|
||||
if os.path.exists(drive_letter+file_path):
|
||||
return drive_letter+file_path
|
||||
print("\n Searched file could not be found on any drive with path:" + file_path)
|
||||
return False
|
||||
|
||||
def load_json_file(file_path,variable):
|
||||
file = open(file_path)
|
||||
data = json.load(file)
|
||||
file.close()
|
||||
return data.get(variable)
|
||||
|
||||
|
||||
def get_administrator_status():
|
||||
command = "(Get-LocalUser | Where-Object{$_.SID -like \"S-1-5-*-500\"}).Enabled"
|
||||
run = subprocess.run(["powershell", "-Command", command], stdout=subprocess.PIPE, universal_newlines=True)
|
||||
print("Is admin account enabled already: " + run.stdout)
|
||||
return run.stdout
|
||||
|
||||
|
||||
def enable_administrator_account():
|
||||
command = "(Get-LocalUser | Where-Object{$_.SID -like \"S-1-5-*-500\"}).Name | Enable-LocalUser"
|
||||
run = subprocess.run(["powershell", "-Command", command], stdout=subprocess.PIPE, universal_newlines=True)
|
||||
print("\n Administrator account is activated by localscript")
|
||||
return run.stdout
|
||||
|
||||
#execute
|
||||
|
||||
meta_data_path = find_drive(":\OPENSTACK\LATEST\META_DATA.json")
|
||||
if meta_data_path != "False":
|
||||
meta_data = load_json_file(meta_data_path,"meta")
|
||||
else:
|
||||
sys.exit(0)
|
||||
|
||||
if meta_data["admin_username"] in ["Administrateur","Administrator"] and "False" in get_administrator_status():
|
||||
run = enable_administrator_account()
|
||||
sys.exit(1001)
|
||||
else:
|
||||
print("Cloud-init user is not Administrateur/Administrator or Admin account is already enabled, script aborted.")
|
||||
sys.exit(0)
|
@ -0,0 +1,47 @@
|
||||
import os,json,sys,wmi
|
||||
from cloudbaseinit.osutils import factory as osutils_factory
|
||||
from cloudbaseinit.utils import network
|
||||
|
||||
|
||||
|
||||
def load_json_variable(file_path,variable):
|
||||
file = open(file_path)
|
||||
data = json.load(file)
|
||||
file.close()
|
||||
return data.get(variable)
|
||||
|
||||
def find_drive(file_path):
|
||||
for number in range(65,91):
|
||||
drive_letter = chr(number)
|
||||
if os.path.exists(drive_letter+file_path):
|
||||
return drive_letter+file_path
|
||||
print("\n Searched file could not be found on any drive with path:" + file_path)
|
||||
return False
|
||||
|
||||
def get_name_by_mac(mac):
|
||||
osutils = osutils_factory.get_os_utils()
|
||||
name = osutils.get_network_adapter_name_by_mac_address(mac)
|
||||
return name
|
||||
|
||||
def activate_dhcp(name, family):
|
||||
osutils = osutils_factory.get_os_utils()
|
||||
osutils._fix_network_adapter_dhcp(name, True, family)
|
||||
|
||||
|
||||
# variables
|
||||
meta_data_path = find_drive(":\OPENSTACK\LATEST\META_DATA.json")
|
||||
# 2 for ipv4 and 6 for ipv6
|
||||
family = 2
|
||||
# execute
|
||||
if meta_data_path != "False":
|
||||
macs = load_json_variable(meta_data_path,"dhcp")
|
||||
|
||||
for mac in macs:
|
||||
name = get_name_by_mac(mac)
|
||||
activate_dhcp(name, family)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
sys.exit(0)
|
||||
|
@ -0,0 +1,7 @@
|
||||
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Serv*' | Select-Object -ExpandProperty Name | %{Add-WindowsCapability -Online -Name $_}
|
||||
Set-Service -Name sshd -StartupType 'Automatic'
|
||||
net user cloudbase-init /delete
|
||||
sc.exe config cloudbase-init obj= .\LocalSystem
|
||||
$newtext = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\cloudbase-init' -Name 'ImagePath' | Select-Object -ExpandProperty ImagePath | %{$_.replace(" cloudbase-init ", " NT-AUTHORITY\SYSTEM ")}
|
||||
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\cloudbase-init' -Name 'ImagePath' -Value $newtext
|
||||
Get-AppxPackage | Where-Object {$_.name -Like "*Language*"} | Remove-AppxPackage
|
Loading…
Reference in new issue