@depends(HAS_PYVMOMI)
def service_restart(host, username, password, service_name, protocol=None, port=None, host_names=None):
 service_instance = salt.utils.vmware.get_service_instance(host=host, username=username, password=password, protocol=protocol, port=port)
 host_names = _check_hosts(service_instance, host, host_names)
 valid_services = ['DCUI', 'TSM', 'SSH', 'ssh', 'lbtd', 'lsassd', 'lwiod', 'netlogond', 'ntpd', 'sfcbd-watchdog', 'snmpd', 'vprobed', 'vpxa', 'xorg']
 ret = {}
 if ((service_name == 'SSH') or (service_name == 'ssh')):
  temp_service_name = 'TSM-SSH'
 else:
  temp_service_name = service_name
 for host_name in host_names:
  if (service_name not in valid_services):
   ret.update({host_name: {'Error': '{0} is not a valid service name.'.format(service_name)}})
   return ret
  host_ref = _get_host_ref(service_instance, host, host_name=host_name)
  service_manager = _get_service_manager(host_ref)
  log.debug("Restarting the '{0}' service on {1}.".format(service_name, host_name))
  try:
   service_manager.RestartService(id=temp_service_name)
  except vim.fault.HostConfigFault as err:
   msg = "'vsphere.service_restart' failed for host {0}: {1}".format(host_name, err)
   log.debug(msg)
   ret.update({host_name: {'Error': msg}})
   continue
  except vim.fault.RestrictedVersion as err:
   log.debug(err)
   ret.update({host_name: {'Error': err}})
   continue
  ret.update({host_name: {'Service Restarted': True}})
 return ret

@ depends ( HAS_PYVMOMI ) def service_restart ( host , username , password , service_name , protocol = None , port = None , host_names = None ) : service_instance = salt . utils . vmware . get_service_instance ( host = host , username = username , password = password , protocol = protocol , port = port ) host_names = _check_hosts ( service_instance , host , host_names ) valid_services = [ 'DCUI' , 'TSM' , 'SSH' , 'ssh' , 'lbtd' , 'lsassd' , 'lwiod' , 'netlogond' , 'ntpd' , 'sfcbd-watchdog' , 'snmpd' , 'vprobed' , 'vpxa' , 'xorg' ] ret = { } if ( ( service_name == 'SSH' ) or ( service_name == 'ssh' ) ) : temp_service_name = 'TSM-SSH' else : temp_service_name = service_name for host_name in host_names : if ( service_name not in valid_services ) : ret . update ( { host_name : { 'Error' : '{0} is not a valid service name.' . format ( service_name ) } } ) return ret host_ref = _get_host_ref ( service_instance , host , host_name = host_name ) service_manager = _get_service_manager ( host_ref ) log . debug ( "Restarting the '{0}' service on {1}." . format ( service_name , host_name ) ) try : service_manager . RestartService ( id = temp_service_name ) except vim . fault . HostConfigFault as err : msg = "'vsphere.service_restart' failed for host {0}: {1}" . format ( host_name , err ) log . debug ( msg ) ret . update ( { host_name : { 'Error' : msg } } ) continue except vim . fault . RestrictedVersion as err : log . debug ( err ) ret . update ( { host_name : { 'Error' : err } } ) continue ret . update ( { host_name : { 'Service Restarted' : True } } ) return ret
restart a "service" on the rest server .