1

I am working on a Java class that accesses VMWare VMs on a VCenter using the Java API.

The Java API allows us to connect to the VCenter, access the guest VM (CentOS7) and list files in directories with no problems except for the /tmp directory.

for usage reference: Doc : GuestFileManager

// filePathToCheck = "/tmp/some-file-to-find.txt
ManagedObjectReference fileManager = ...; // GuestFileManager
ManagedObjectReference vmGuest = ...;  // VirtualMachine
String fileToCheckName = FilenameUtils.getName(filePathToCheck); // -> some-file-to-find.txt
String guestDirectory = filePathToCheck.replace(fileToCheckName,""); // -> /tmp/
guestFiles = vimPort.listFilesInGuest(fileManager, vmGuest, auth, guestDirectory, null, null, null);

I am using GuestFileManager.listFilesInGuest() and find that with any directory other than /tmp I can list the files in the directory exactly as they appear in an ssh session.

With a listFilesInGuest() looking at the path "/tmp" directory I get a listing of:

.
..
vmware-root (directory)

even though my ssh session shows:

.
..
finishedinstall
.font-unix
.ICE-unix
systemd-private-f2b5415058d14dbfa4306235d53fed88-vmtoolsd.service-QN0Muw
.Test-unix
.X11-unix
.XIM-unix

I did a find on vmware-root and it showed up at

/tmp/systemd-private-f2b5415058d14dbfa4306235d53fed88-vmtoolsd.service-QN0Muw/tmp/vmware-root

navigation into that folder revealed the files found in listFilesInGuest():

.
..
vmware-root

This would be fine we operated in a vacuum, but the program will need to read, modify or execute files in the temp directory from other program installers and interfaces which use "the" /tmp directory and not VMWare's buried location.

I have not been able to find any documentation on some way to re-configure VMWare Tools nor a way to get to the /tmp directory using the API and I am hoping someone in SO will encountered and found a victorious path for this VMWare feature.

EDIT : With further testing I have found that this "special" tmp directory only happens in posix, the VMWareTools API on Windows navigates as I would expect in all OS.

rwheadon
  • 241
  • 1
  • 12
  • 1
    Try disabling the private tmp directory. There should be some setting file for vmtoolsd service. For example: http://upwork.link/apache2/centos7-how-do-disable-privatetmp-for-apache-with-systemd/ – Icarus3 Apr 26 '17 at 15:00
  • @Icarus3 : You are correct, there is a place in /usr/lib/systemd/system/vmtoolsd.service where the setting PrivateTmp=true is set during the tools installation. I went into a test VM and changed the setting to PrivateTmp=false and after the reboot the private "tmp" directory was gone and references to "/tmp" worked as desired. This setting does not appear to be optional during the VMWare tools installation and setup so either the VM template will need to be set up with this change or it will need to be done with provisioning scripts. Make your comment into an answer and I'll accept it. – rwheadon Apr 27 '17 at 16:11
  • I found the heads-up also from bbs.archlinux.org : "what are the directories systemd-private-xxxxxx ?" with the comment "They are created by services with PrivateTmp=true (usually ntpd). They should be cleaned automatically after haven't been used for the amount of time specified in /usr/lib/tmpfiles.d/tmp.conf (30 days by default)" – rwheadon Apr 27 '17 at 16:20

1 Answers1

2

Try disabling the private tmp directory. There should be some setting file for vmtoolsd service. For example: apache

As it turned out ( see the comments ), such setting can be found in: /usr/lib/systemd/system/vmtoolsd.service

Icarus3
  • 2,310
  • 14
  • 22