Skip to content

Commit

Permalink
Make channel discovery compatible with Ubuntu 16.04
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Apr 7, 2016
1 parent e372432 commit 7b0a76d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions common/negotiator_common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Scriptable KVM/QEMU guest agent in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: November 1, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""
Expand Down Expand Up @@ -33,7 +33,7 @@
from negotiator_common.config import BUILTIN_COMMANDS_DIRECTORY, USER_COMMANDS_DIRECTORY

# Semi-standard module versioning.
__version__ = '0.8.2'
__version__ = '0.8.3'

# Initialize a logger for this module.
logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions guest/negotiator_guest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Scriptable KVM/QEMU guest agent in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: November 1, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""
Expand Down Expand Up @@ -30,7 +30,7 @@
from negotiator_common.utils import compact, GracefulShutdown

# Semi-standard module versioning.
__version__ = '0.8.2'
__version__ = '0.8.3'

# Initialize a logger for this module.
logger = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions guest/negotiator_guest/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Scriptable KVM/QEMU guest agent in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 24, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""
Expand Down Expand Up @@ -75,8 +75,8 @@

def main():
"""Command line interface for the ``negotiator-guest`` program."""
# Initialize logging to the terminal.
coloredlogs.install(level=logging.INFO)
# Initialize logging to the terminal and system log.
coloredlogs.install(syslog=True)
# Parse the command line arguments.
list_commands = False
execute_command = None
Expand Down
4 changes: 2 additions & 2 deletions guest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Setup script for the `negotiator-guest' package.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: November 1, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""Setup script for the ``negotiator-guest`` package."""
Expand Down Expand Up @@ -49,7 +49,7 @@
'negotiator-guest = negotiator_guest.cli:main'
]),
install_requires=[
'coloredlogs >= 0.6',
'coloredlogs >= 5.0',
'negotiator-common >= 0.8',
],
classifiers=[
Expand Down
42 changes: 29 additions & 13 deletions host/negotiator_host/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Scriptable KVM/QEMU guest agent in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: December 30, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""
Expand All @@ -17,6 +17,7 @@
import logging
import multiprocessing
import os
import re
import socket
import stat
import time
Expand All @@ -30,7 +31,7 @@
from executor import execute

# Semi-standard module versioning.
__version__ = '0.8.2'
__version__ = '0.8.3'

# Initialize a logger for this module.
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -196,18 +197,33 @@ def find_available_channels(directory, name):
channels = {}
suffix = '.%s' % name
running_guests = set(find_running_guests())
for entry in os.listdir(directory):
# Validate the filename suffix.
if entry.endswith(suffix):
pathname = os.path.join(directory, entry)
# Make sure we're dealing with a UNIX socket.
if stat.S_ISSOCK(os.stat(pathname).st_mode):
guest_name = entry[:-len(suffix)]
# Make sure the guest is available and running.
if guest_name in running_guests:
for root, dirs, files in os.walk(directory):
for filename in files:
# Validate the filename.
if filename.endswith(suffix):
# In Ubuntu 12.04 and 14.04 I have observed and now assume
# the following directory/file naming scheme for channels:
#
# /var/lib/libvirt/qemu/channel/target/GUEST_NAME.negotiator-guest-to-host.0
guest_name = filename[:-len(suffix)]
logger.debug("Found channel of guest %r (using old naming convention).", guest_name)
elif filename == name:
# In Ubuntu 16.04 I have observed and now assume the
# following directory/file naming scheme for channels:
#
# /var/lib/libvirt/qemu/channel/target/domain-GUEST_NAME/negotiator-guest-to-host.0
guest_name = re.sub('^domain-', '', os.path.basename(root))
logger.debug("Found channel of guest %r (using new naming convention).", guest_name)
else:
continue
# Make sure the guest is available and running.
pathname = os.path.join(root, filename)
if guest_name in running_guests:
# Make sure we're dealing with a UNIX socket.
if stat.S_ISSOCK(os.stat(pathname).st_mode):
channels[guest_name] = pathname
else:
logger.debug("Ignoring UNIX socket %s (guest %r isn't running) ..", pathname, guest_name)
else:
logger.debug("Ignoring UNIX socket %s (guest %r isn't running) ..", pathname, guest_name)
return channels


Expand Down
9 changes: 5 additions & 4 deletions host/negotiator_host/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Scriptable KVM/QEMU guest agent in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 24, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""
Expand Down Expand Up @@ -72,8 +72,8 @@

def main():
"""Command line interface for the ``negotiator-host`` program."""
# Initialize logging to the terminal.
coloredlogs.install(level=logging.INFO)
# Initialize logging to the terminal and system log.
coloredlogs.install(syslog=True)
# Parse the command line arguments.
actions = []
context = Context()
Expand Down Expand Up @@ -135,7 +135,8 @@ def __init__(self):
def print_guest_names(self):
"""Print the names of the guests that Negotiator can connect with."""
channels = find_available_channels(CHANNELS_DIRECTORY, HOST_TO_GUEST_CHANNEL_NAME)
print('\n'.join(sorted(channels.keys())))
if channels:
print('\n'.join(sorted(channels.keys())))

def print_commands(self, guest_name):
"""Print the commands supported by the guest."""
Expand Down
4 changes: 2 additions & 2 deletions host/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Setup script for the `negotiator-host' package.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: November 1, 2014
# Last Change: April 8, 2016
# URL: https://negotiator.readthedocs.org

"""Setup script for the ``negotiator-host`` package."""
Expand Down Expand Up @@ -49,7 +49,7 @@
'negotiator-host = negotiator_host.cli:main'
]),
install_requires=[
'coloredlogs >= 0.6',
'coloredlogs >= 5.0',
'negotiator-common >= 0.8',
],
classifiers=[
Expand Down

0 comments on commit 7b0a76d

Please sign in to comment.