Exemplo n.º 1
0
def set_restart_delay(seconds):
    '''
    Set the number of seconds after which the computer will start up after a
    power failure.

    .. warning::
    Though salt reports success, this command fails with the following error:
    ``Error, IOServiceOpen returned 0x10000003``
    The setting is not updated. This is an apple bug.

    :param int seconds: The number of seconds. Must be a multiple of 30

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_restart_delay 180
    '''
    if seconds % 30 != 0:
        msg = '\nInvalid value passed for seconds.\n' \
              'Must be a multiple of 30.\n' \
              'Passed: {0}'.format(seconds)
        raise CommandExecutionError(msg)
    cmd = 'systemsetup -setwaitforstartupafterpowerfailure {0}'.format(seconds)
    return execute_return_success(cmd)
Exemplo n.º 2
0
def set_boot_arch(arch='default'):
    '''
    Set the kernel to boot in 32 or 64 bit mode on next boot.

    .. note::
        Though salt reports success, this command fails with the following
        error:
        ``changes to kernel architecture failed to save!``
        The setting is not updated. This is either an apple bug, not available
        on the test system, or a result of system files now being locked down in
        OS X.

    :param str arch: A string representing the desired architecture. If no
    value is passed, default is assumed. Valid values include:
    - i386
    - x86_64
    - default

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_boot_arch i386
    '''
    if arch not in ['i386', 'x86_64', 'default']:
        msg = '\nInvalid value passed for arch.\n' \
              'Must be i386, x86_64, or default.\n' \
              'Passed: {0}'.format(arch)
        raise CommandExecutionError(msg)
    cmd = 'systemsetup -setkernelbootarchitecture {0}'.format(arch)
    return execute_return_success(cmd)
Exemplo n.º 3
0
 def test_execute_return_success_command_succeeded(self):
     """
     test execute_return_success function
     command succeeded
     """
     mock_cmd = MagicMock(return_value={"retcode": 0, "stdout": "spongebob"})
     with patch.object(mac_utils, "_run_all", mock_cmd):
         ret = mac_utils.execute_return_success("dir c:\\")
         self.assertEqual(ret, True)
Exemplo n.º 4
0
 def test_execute_return_success_not_supported(self):
     '''
     test execute_return_success function
     command not supported
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0,
                                        'stdout': 'not supported'})
     with patch.object(mac_utils, '_run_all', mock_cmd):
         ret = mac_utils.execute_return_success('dir c:\\')
         self.assertEqual(ret, 'Not supported on this machine')
Exemplo n.º 5
0
 def test_execute_return_success_command_succeeded(self):
     '''
     test execute_return_success function
     command succeeded
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0,
                                        'stdout': 'spongebob'})
     with patch.object(mac_utils, '_run_all', mock_cmd):
         ret = mac_utils.execute_return_success('dir c:\\')
         self.assertEqual(ret, True)
Exemplo n.º 6
0
 def test_execute_return_success_command_succeeded(self):
     '''
     test execute_return_success function
     command succeeded
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0,
                                        'stdout': 'spongebob'})
     with patch.object(mac_utils, '_run_all', mock_cmd):
         ret = mac_utils.execute_return_success('dir c:\\')
         self.assertEqual(ret, True)
Exemplo n.º 7
0
def set_computer_name(name):
    '''
    Set the computer name

    :param str name: The new computer name

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_computer_name "Mike's Mac"
    '''
    cmd = 'systemsetup -setcomputername "{0}"'.format(name)
    return execute_return_success(cmd)
Exemplo n.º 8
0
def set_remote_login(enable):
    '''
    Set the remote login (SSH) to either on or off.

    :param bool enable: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_remote_login True
    '''
    state = validate_enabled(enable)
    cmd = 'systemsetup -f -setremotelogin {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 9
0
def set_sleep_on_power_button(enabled):
    '''
    Set whether or not the power button can sleep the computer.

    :param bool enabled: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_sleep_on_power_button True
    '''
    state = validate_enabled(enabled)
    cmd = 'systemsetup -setallowpowerbuttontosleepcomputer {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 10
0
def set_remote_events(enable):
    '''
    Set whether the server responds to events sent by other computers (such as
    AppleScripts)

    :param bool enable: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_remote_events On
    '''
    state = validate_enabled(enable)
    cmd = 'systemsetup -setremoteappleevents {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 11
0
def set_harddisk_sleep(minutes):
    '''
    Set the amount of idle time until the harddisk sleeps. Pass "Never" of "Off"
    to never sleep.

    :param minutes: Can be an integer between 1 and 180 or "Never" or "Off"
    :ptype: int, str

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_harddisk_sleep 120
        salt '*' power.set_harddisk_sleep off
    '''
    value = _validate_sleep(minutes)
    cmd = 'systemsetup -setharddisksleep {0}'.format(value)
    return execute_return_success(cmd)
Exemplo n.º 12
0
def set_wake_on_network(enabled):
    '''
    Set whether or not the computer will wake from sleep when network activity
    is detected.

    :param bool enabled: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_wake_on_network True
    '''
    state = validate_enabled(enabled)
    cmd = 'systemsetup -setwakeonnetworkaccess {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 13
0
def set_subnet_name(name):
    '''
    Set the local subnet name

    :param str name: The new local subnet name

    .. note::
       Spaces are changed to dashes. Other special characters are removed.

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        The following will be set as 'Mikes-Mac'
        salt '*' system.set_subnet_name "Mike's Mac"
    '''
    cmd = 'systemsetup -setlocalsubnetname "{0}"'.format(name)
    return execute_return_success(cmd)
Exemplo n.º 14
0
def set_restart_power_failure(enabled):
    '''
    Set whether or not the computer will automatically restart after a power
    failure.

    :param bool enabled: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_restart_power_failure True
    '''
    state = validate_enabled(enabled)
    cmd = 'systemsetup -setrestartpowerfailure {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 15
0
def set_sleep(minutes):
    '''
    Sets the amount of idle time until the machine sleeps. Sets the same value
    for Computer, Display, and Hard Disk. Pass "Never" or "Off" for computers
    that should never sleep.

    :param minutes: Can be an integer between 1 and 180 or "Never" or "Off"
    :ptype: int, str

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_sleep 120
        salt '*' power.set_sleep never
    '''
    value = _validate_sleep(minutes)
    cmd = 'systemsetup -setsleep {0}'.format(value)
    return execute_return_success(cmd)
Exemplo n.º 16
0
def set_disable_keyboard_on_lock(enable):
    '''
    Get whether or not the keyboard should be disabled when the X Serve
    enclosure lock is engaged.

    :param bool enable: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_disable_keyboard_on_lock False
    '''

    state = validate_enabled(enable)
    cmd = 'systemsetup -setdisablekeyboardwhenenclosurelockisengaged ' \
          'k{0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 17
0
def set_restart_freeze(enabled):
    '''
    Specifies whether the server restarts automatically after a system freeze.
    This setting doesn't seem to be editable. The command completes successfully
    but the setting isn't actually updated. This is probably an OS X bug. The
    functions remains in case they ever fix the bug.

    :param bool enabled: True to enable, False to disable. "On" and "Off" are
    also acceptable values. Additionally you can pass 1 and 0 to represent True
    and False respectively

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' power.set_restart_freeze True
    '''
    state = validate_enabled(enabled)
    cmd = 'systemsetup -setrestartfreeze {0}'.format(state)
    return execute_return_success(cmd)
Exemplo n.º 18
0
def set_startup_disk(path):
    '''
    Set the current startup disk to the indicated path. Use
    ``system.list_startup_disks`` to find valid startup disks on the system.

    :param str path: The valid startup disk path

    :return: True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_startup_disk True
    '''
    if path not in list_startup_disks():
        msg = '\nInvalid value passed for path.\n' \
              'Must be a valid startup disk as found in ' \
              'system.list_startup_disks.\n' \
              'Passed: {0}'.format(path)
        raise CommandExecutionError(msg)
    cmd = 'systemsetup -setstartupdisk {0}'.format(path)
    return execute_return_success(cmd)