OPSI.System.Posix module

opsi python library - Posix

Functions and classes for the use with a POSIX operating system.

author:Jan Schneider <j.schneider@uib.de>
author:Erol Ueluekmen <e.ueluekmen@uib.de>
author:Niko Wenselowski <n.wenselowski@uib.de>
license:GNU Affero General Public License version 3
exception OPSI.System.Posix.CommandNotFoundException

Bases: exceptions.RuntimeError

class OPSI.System.Posix.Distribution(distribution_information=None)

Bases: object

version
class OPSI.System.Posix.Harddisk(device)
createFilesystem(partition, fs=None)
createPartition(start, end, fs, type=u'primary', boot=False, lba=False, number=None)
deletePartition(partition)
deletePartitionTable()
fill(partition=0, infile=u'', progressSubject=None)
getBusType()
getControllerInfo()
getPartition(number)
getPartitions()
getSignature()
mountPartition(partition, mountpoint, **options)
randomFill(partition=0, progressSubject=None)
readMasterBootRecord()
readPartitionBootRecord(partition=1)
readPartitionTable()
readRotational()

Checks if a disk is rotational.

The result of the check is saved in the attribute rotational.

New in version 4.0.4.2.

resizeFilesystem(partition, size=0, fs=None)
restoreImage(partition, imageFile, progressSubject=None)
saveImage(partition, imageFile, progressSubject=None)
setBlockAlignment(align=False)
setDiskLabelType(label)
setDosCompatibility(comp=True)
setNTFSPartitionStartSector(partition, sector=0)
setPartitionBootable(partition, bootable)
setPartitionId(partition, id)
shred(partition=0, iterations=25, progressSubject=None)
umountPartition(partition)
useBIOSGeometry()
writeMasterBootRecord(system=u'auto')
writePartitionBootRecord(partition=1, fsType=u'auto')
writePartitionTable()
zeroFill(partition=0, progressSubject=None)
class OPSI.System.Posix.NetworkPerformanceCounter(interface)

Bases: threading.Thread

getBytesInPerSecond()
getBytesOutPerSecond()
run()
stop()
class OPSI.System.Posix.SysInfo

Bases: object

broadcast
distribution
distributionId
domainname
fqdn
hardwareAddress
hostname
ipAddress
netmask
opsiVersion
subnet
sysVersion
class OPSI.System.Posix.SystemSpecificHook

Bases: object

error_Harddisk_createFilesystem(harddisk, partition, fs, exception)
error_Harddisk_createPartition(harddisk, start, end, fs, type, boot, lba, exception)
error_Harddisk_deletePartition(harddisk, partition, exception)
error_Harddisk_deletePartitionTable(harddisk, exception)
error_Harddisk_fill(harddisk, partition, infile, progressSubject, exception)
error_Harddisk_mountPartition(harddisk, partition, mountpoint, exception, **options)
error_Harddisk_readMasterBootRecord(harddisk, exception)
error_Harddisk_readPartitionBootRecord(harddisk, partition, exception)
error_Harddisk_readPartitionTable(harddisk, exception)
error_Harddisk_resizeFilesystem(harddisk, partition, size, fs, exception)
error_Harddisk_restoreImage(harddisk, partition, imageFile, progressSubject, exception)
error_Harddisk_saveImage(harddisk, partition, imageFile, progressSubject, exception)
error_Harddisk_setNTFSPartitionStartSector(harddisk, partition, sector, exception)
error_Harddisk_setPartitionBootable(harddisk, partition, bootable, exception)
error_Harddisk_setPartitionId(harddisk, partition, id, exception)
error_Harddisk_shred(harddisk, partition, iterations, progressSubject, exception)
error_Harddisk_umountPartition(harddisk, partition, exception)
error_Harddisk_writeMasterBootRecord(harddisk, system, exception)
error_Harddisk_writePartitionBootRecord(harddisk, partition, fsType, exception)
error_Harddisk_writePartitionTable(harddisk, exception)
error_auditHardware(config, hostId, progressSubject, exception)
error_halt(wait, exception)
error_reboot(wait, exception)
post_Harddisk_createFilesystem(harddisk, partition, fs)
post_Harddisk_createPartition(harddisk, start, end, fs, type, boot, lba)
post_Harddisk_deletePartition(harddisk, partition)
post_Harddisk_deletePartitionTable(harddisk)
post_Harddisk_fill(harddisk, partition, infile, progressSubject)
post_Harddisk_mountPartition(harddisk, partition, mountpoint, **options)
post_Harddisk_readMasterBootRecord(harddisk, result)
post_Harddisk_readPartitionBootRecord(harddisk, partition, result)
post_Harddisk_readPartitionTable(harddisk)
post_Harddisk_resizeFilesystem(harddisk, partition, size, fs)
post_Harddisk_restoreImage(harddisk, partition, imageFile, progressSubject)
post_Harddisk_saveImage(harddisk, partition, imageFile, progressSubject)
post_Harddisk_setNTFSPartitionStartSector(harddisk, partition, sector)
post_Harddisk_setPartitionBootable(harddisk, partition, bootable)
post_Harddisk_setPartitionId(harddisk, partition, id)
post_Harddisk_shred(harddisk, partition, iterations, progressSubject)
post_Harddisk_umountPartition(harddisk, partition)
post_Harddisk_writeMasterBootRecord(harddisk, system)
post_Harddisk_writePartitionBootRecord(harddisk, partition, fsType)
post_Harddisk_writePartitionTable(harddisk)
post_auditHardware(config, hostId, result)
post_halt(wait)
post_reboot(wait)
pre_Harddisk_createFilesystem(harddisk, partition, fs)
pre_Harddisk_createPartition(harddisk, start, end, fs, type, boot, lba)
pre_Harddisk_deletePartition(harddisk, partition)
pre_Harddisk_deletePartitionTable(harddisk)
pre_Harddisk_fill(harddisk, partition, infile, progressSubject)
pre_Harddisk_mountPartition(harddisk, partition, mountpoint, **options)
pre_Harddisk_readMasterBootRecord(harddisk)
pre_Harddisk_readPartitionBootRecord(harddisk, partition)
pre_Harddisk_readPartitionTable(harddisk)
pre_Harddisk_resizeFilesystem(harddisk, partition, size, fs)
pre_Harddisk_restoreImage(harddisk, partition, imageFile, progressSubject)
pre_Harddisk_saveImage(harddisk, partition, imageFile, progressSubject)
pre_Harddisk_setNTFSPartitionStartSector(harddisk, partition, sector)
pre_Harddisk_setPartitionBootable(harddisk, partition, bootable)
pre_Harddisk_setPartitionId(harddisk, partition, id)
pre_Harddisk_shred(harddisk, partition, iterations, progressSubject)
pre_Harddisk_umountPartition(harddisk, partition)
pre_Harddisk_writeMasterBootRecord(harddisk, system)
pre_Harddisk_writePartitionBootRecord(harddisk, partition, fsType)
pre_Harddisk_writePartitionTable(harddisk)
pre_auditHardware(config, hostId, progressSubject)
pre_halt(wait)
pre_reboot(wait)
OPSI.System.Posix.addSystemHook(hook)
OPSI.System.Posix.auditHardware(config, hostId, progressSubject=None)
OPSI.System.Posix.daemonize()
OPSI.System.Posix.execute(cmd, nowait=False, getHandle=False, ignoreExitCode=[], exitOnStderr=False, captureStderr=True, encoding=None, timeout=0, shell=None, waitForEnding=None)

Executes a command.

Parameters:
  • nowait (bool) – If this is True the command will be executed and no waiting for it to finish will be done.
  • getHandle (bool) – If this is True the handle the reference to the command output will be returned.
  • ignoreExitCode (bool or list or tuple or set) – Ignore exit codes of the program. This can be True to ignore all exit codes or a list of specific exit codes that should be ignored.
  • exitOnStderr (bool) – If this is True output on stderr will be interpreted as an failed execution and will throw an Exception.
  • captureStderr (bool) – If this is True the output of stderr will be redirected to stdout.
  • encoding (str) – The encoding to be used to decode the output.
  • timeout (int) – The time in seconds after that the execution will be aborted.
  • shell – Currently ignored. This is introduced to have the same keyword arguments as on Windows.
  • waitForEnding (bool) – If this is set it will overwrite the setting for nowait. This is introduced to have the same keyword arguments as on Windows.
Returns:

If the command finishes and we wait for it to finish the output will be returned.

Returntype:

list

OPSI.System.Posix.getActiveConsoleSessionId()

Get the currently used console session id.

Warning

This is currently only faked to have the function available for the opsi-linux-client-agent!

OPSI.System.Posix.getActiveSessionId()

Returns the currently active session ID.

New in version 4.0.5.

Returntype:int
OPSI.System.Posix.getActiveSessionIds(winApiBugCommand=None, data=None)

Getting the IDs of the currently active sessions.

New in version 4.0.5.

Parameters:data ([str, ]) – Prefetched data to read information from.
Returntype:[int, ]
OPSI.System.Posix.getBlockDeviceBusType(device)
Returns:‘IDE’, ‘SCSI’, ‘SATA’, ‘RAID’ or None (not found)
Returntype:str or None
OPSI.System.Posix.getBlockDeviceContollerInfo(device, lshwoutput=None)
OPSI.System.Posix.getDHCPDRestartCommand(default=None)

Returns a command that can be used to restart the used DHCPD.

The command will include the full path to tools used, i.e. service.

If no command can be automatically determined and default is given this will be returned. If default is not given an RuntimeError will be risen.

OPSI.System.Posix.getDHCPResult(device, leasesFile=None)

Get the settings of the current DHCP lease.

It first tries to read the value from leases files and then tries to read the values from pump.

Changed in version 4.0.5.1: Added parameter leasesFile.

Parameters:leasesFile (str) – The file to read the leases from. If this is not given known places for this file will be tried.
Returns:Settings of the lease. All keys are lowercase. Possible keys are: ip, netmask, bootserver, nextserver, gateway, bootfile, hostname, domain.
Returntype:dict
OPSI.System.Posix.getDHCPServiceName()

Tries to read the name of the used dhcpd. Returns None if no known service was detected.

OPSI.System.Posix.getDefaultNetworkInterfaceName()
OPSI.System.Posix.getDiskSpaceUsage(path)
OPSI.System.Posix.getEthernetDevices()

Get the ethernet devices on the system.

Returns:For each device the name of the device.
Returntype:[str]
OPSI.System.Posix.getFQDN()
OPSI.System.Posix.getHarddisks(data=None)

Get the available harddisks from the machine.

Parameters:data ([str, ]) – Data to parse through.
Returns:The found harddisks.
Returntype:[Harddisk, ]
OPSI.System.Posix.getHostname()
OPSI.System.Posix.getKernelParams()

Reads the kernel cmdline and returns a dict containing all key=value pairs. keys are converted to lower case

OPSI.System.Posix.getNetworkDeviceConfig(device)
OPSI.System.Posix.getNetworkInterfaces()

Get information about the network interfaces on the system.

Returntype:[{}]
OPSI.System.Posix.getSambaServiceName(default=None, staticFallback=True)

Get the name for the samba service.

Parameters:
  • default (str) – If not value was detected use this as default.
  • staticFallback (bool) – If this is True it will use a static lookup to determine what value needs to be returned in case no service name was detected by the automatic approach.
OPSI.System.Posix.getServiceNames(_serviceStatusOutput=None)

Get the names of services on the system.

This script tries to pull the information from systemctl if present. If systemctl is not present it will fall back to use service.

Parameters:_serviceStatusOutput ([str, ]) – The output of service –status-all.Used for testing.
Returntype:set

New in version 4.0.5.11.

Note

Does not work on Suse Linux Enterprise Server (SLES) 11SP3.

OPSI.System.Posix.getSystemProxySetting()
OPSI.System.Posix.halt(wait=10)
OPSI.System.Posix.hardwareExtendedInventory(config, opsiValues={}, progressSubject=None)
OPSI.System.Posix.hardwareInventory(config, progressSubject=None)
OPSI.System.Posix.ifconfig(device, address, netmask=None)
OPSI.System.Posix.isCentOS()

Returns True if this is running on CentOS. Returns False if otherwise.

OPSI.System.Posix.isDebian()

Returns True if this is running on Debian. Returns False if otherwise.

OPSI.System.Posix.isOpenSUSE()

Returns True if this is running on openSUSE. Returns False if otherwise. For OpenSUSE Leap please use isOpenSUSELeap()

OPSI.System.Posix.isOpenSUSELeap()

Returns True if this is running on OpenSUSE Leap. Returns False if otherwise.

OPSI.System.Posix.isRHEL()

Returns True if this is running on Red Hat Enterprise Linux. Returns False if otherwise.

OPSI.System.Posix.isSLES()

Returns True if this is running on Suse Linux Enterprise Server. Returns False if otherwise.

OPSI.System.Posix.isUCS()

Returns True if this is running on Univention Corporate Server. Returns False if otherwise.

OPSI.System.Posix.isUbuntu()

Returns True if this is running on Ubuntu. Returns False if otherwise.

OPSI.System.Posix.isXenialSfdiskVersion()

check for sfdisk version to adapt commands to changed output

Returns True for versions equal 2.27.1 - the one used in Ubuntu Xenial.

OPSI.System.Posix.locateDHCPDConfig(default=None)
OPSI.System.Posix.locateDHCPDInit(default=None)

Returns the init command for the DHCPD.

It will try to get the init script from /etc/init.d. If no init commands are found and default is given it will return the default. If no default is given it will throw an RuntimeError.

Parameters:default – If no init script is found fall back to this instead of throwing an error.
Returntype:str
OPSI.System.Posix.mount(dev, mountpoint, **options)
OPSI.System.Posix.reboot(wait=10)
OPSI.System.Posix.removeSystemHook(hook)
OPSI.System.Posix.runCommandInSession(command, sessionId=None, desktop=None, duplicateFrom=None, waitForProcessEnding=True, timeoutSeconds=0)

Run an command.

The arguments sessionId, desktop and duplicateFrom currently do not have any effect and are only provided to have a method signature matching the one from the corresponding Windows module.

New in version 4.0.5.2.

Parameters:
  • waitForProcessEnding (bool) – If this is False the command will be started and we will not wait for it to finish.
  • timeoutSeconds – If this is set we will wait this many seconds until the execution of the process is terminated.
Returntype:

(subprocess.Popen, None, int, None) if waitForProcessEnding is False, otherwise (None, None, None, None)

OPSI.System.Posix.setLocalSystemTime(timestring)

Method sets the local systemtime param timestring = “2014-07-15 13:20:24.085661” Die Typ SYSTEMTIME-Struktur ist wie folgt:

WYear Integer-The current year. WMonth Integer-The current month. January is 1. WDayOfWeek Integer-The current day of the week. Sunday is 0. WDay Integer-The current day of the month. WHour Integer-The current hour. wMinute Integer-The current minute. wSecond Integer-The current second. wMilliseconds Integer-The current millisecond.

win32api.SetSystemTime

int = SetSystemTime(year, month , dayOfWeek , day , hour , minute , second , millseconds )

http://docs.activestate.com/activepython/2.5/pywin32/win32api__SetSystemTime_meth.html

OPSI.System.Posix.shutdown(wait=10)
OPSI.System.Posix.umount(devOrMountpoint)
OPSI.System.Posix.which(cmd)