def determine_openstack_user(self): # The user can specify an openstack_user using the flags, or they can leave it blank # and we'll attempt to discover the user. If failing to discover we'll default to # the same user as the nova-gridcentric process. user = FLAGS.openstack_user if user == '': # Attempt to determine the openstack user. try: # use ps to determine the user running the nova-compute process cmd = "ps aux | grep nova-compute | grep python | grep -v grep | awk '{print $1}'" _, cmd_user, _ = utilities.check_command(cmd) user = cmd_user.strip() except: user = '' if user == '': # We were unable to determine the user. We'll just default to our current user. user = os.getuid() return user
def touch_as(path, uid): utilities.check_command(['sudo', '-u', '#%d' % uid, 'touch', path])
def mkdir_as(path, uid): utilities.check_command(['sudo', '-u', '#%d' % uid, 'mkdir', '-p', path])
def run_as(cmd, uid): sudo_cmd = ['sudo', '-u', '#%d' % uid] sudo_cmd += cmd utilities.check_command(sudo_cmd)