View | Details | Raw Unified | Return to bug 219687 | Differences between
and this patch

Collapse All | Expand All

(-)net/google-compute-engine/Makefile (+50 lines)
Added Link Here
1
# $FreeBSD$
2
3
PORTNAME=	google-compute-engine
4
PORTVERSION=	2.4.1
5
CATEGORIES=	net python
6
MASTER_SITES=	CHEESESHOP
7
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
8
DISTNAME=	${GH_ACCOUNT}-${GH_PROJECT}-${GH_TAGNAME}
9
10
MAINTAINER=	helen.koike@collabora.com
11
COMMENT=	Guest Environment for Google Compute Engine
12
13
LICENSE=	APACHE20
14
LICENSE_FILE=	${WRKSRC}/LICENSE
15
16
BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}setuptools>0:devel/${PYTHON_PKGNAMEPREFIX}setuptools
17
RUN_DEPENDS=	sudo:security/sudo \
18
		ntpdate:net/ntp \
19
		${PYTHON_PKGNAMEPREFIX}boto>0:devel/py-boto \
20
		${PYTHON_PKGNAMEPREFIX}netifaces>0:net/py-netifaces \
21
		${PYTHON_PKGNAMEPREFIX}netaddr>0:net/py-netaddr
22
23
USES=		python
24
USE_PYTHON=	autoplist distutils concurrent
25
USE_GITHUB=	yes
26
GH_ACCOUNT=	GoogleCloudPlatform
27
GH_PROJECT=	compute-image-packages
28
GH_TAGNAME=	20170718
29
30
USE_RC_SUBR=	google_instance_setup \
31
		google_network_setup \
32
		google_accounts_daemon \
33
		google_clock_skew_daemon \
34
		google_startup_scripts \
35
		google_shutdown_scripts
36
37
SUB_LIST=	PYTHON_CMD="${PYTHON_CMD}"
38
39
post-patch:
40
	@${REINPLACE_CMD} -i -e 's|%%PREFIX%%|${PREFIX}|g' \
41
		${WRKSRC}/build_packages.sh \
42
		${WRKSRC}/google_compute_engine/accounts/accounts_utils.py \
43
		${WRKSRC}/google_compute_engine/boto/boto_config.py \
44
		${WRKSRC}/google_compute_engine/boto/compute_auth.py \
45
		${WRKSRC}/google_compute_engine/config_manager.py \
46
		${WRKSRC}/google_compute_engine/instance_setup/instance_config.py \
47
		${WRKSRC}/google_compute_engine/metadata_scripts/script_executor.py \
48
		${WRKSRC}/google_compute_engine/network_setup/network_setup.py
49
50
.include <bsd.port.mk>
(-)net/google-compute-engine/distinfo (+3 lines)
Added Link Here
1
TIMESTAMP = 1500790296
2
SHA256 (GoogleCloudPlatform-compute-image-packages-20170718_GH0.tar.gz) = c161a4d5a86e40be981bcb3a31aeb3bf9995b96d8302ef800a0251b17f72b254
3
SIZE (GoogleCloudPlatform-compute-image-packages-20170718_GH0.tar.gz) = 119048
(-)net/google-compute-engine/files/google_accounts_daemon.in (+34 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_accounts_daemon
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup google_network_setup
8
# KEYWORD: shutdown
9
#
10
# google_accounts_daemon_enable (bool):	Set to YES by default.
11
#					Set it to NO to disable google_accounts_daemon.
12
#
13
14
. /etc/rc.subr
15
16
name="google_accounts_daemon"
17
rcvar="google_accounts_daemon_enable"
18
19
load_rc_config "${name}"
20
21
: ${google_accounts_daemon_enable:="YES"}
22
23
command_interpreter="%%PYTHON_CMD%%"
24
command=%%PREFIX%%/bin/${name}
25
pidfile=/var/run/${name}.pid
26
start_cmd="google_accounts_daemon_start"
27
28
google_accounts_daemon_start()
29
{
30
  check_startmsgs && echo "Starting ${name}."
31
  daemon -p ${pidfile} -t ${name} ${command}
32
}
33
34
run_rc_command "$1"
(-)net/google-compute-engine/files/google_clock_skew_daemon.in (+34 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_clock_skew_daemon
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup google_network_setup
8
# KEYWORD: shutdown
9
#
10
# google_clock_skew_daemon_enable (bool): Set to YES by default.
11
#					  Set it to NO to disable google_clock_skew_daemon.
12
#
13
14
. /etc/rc.subr
15
16
name="google_clock_skew_daemon"
17
rcvar="google_clock_skew_daemon_enable"
18
19
load_rc_config "${name}"
20
21
: ${google_clock_skew_daemon_enable:="YES"}
22
23
command_interpreter="%%PYTHON_CMD%%"
24
command=%%PREFIX%%/bin/${name}
25
pidfile=/var/run/${name}.pid
26
start_cmd="google_clock_skew_daemon_start"
27
28
google_clock_skew_daemon_start()
29
{
30
  check_startmsgs && echo "Starting ${name}."
31
  daemon -p ${pidfile} -t ${name} ${command}
32
}
33
34
run_rc_command "$1"
(-)net/google-compute-engine/files/google_instance_setup.in (+26 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_instance_setup
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd
8
#
9
# google_instance_setup_enable (bool):	Set to YES by default.
10
#					Set it to NO to disable google_instance_setup.
11
#
12
13
. /etc/rc.subr
14
15
name="google_instance_setup"
16
rcvar="google_instance_setup_enable"
17
18
load_rc_config "${name}"
19
20
: ${google_instance_setup_enable:="YES"}
21
22
command_interpreter="%%PYTHON_CMD%%"
23
command=%%PREFIX%%/bin/${name}
24
pidfile=/var/run/${name}.pid
25
26
run_rc_command "$1"
(-)net/google-compute-engine/files/google_ip_forwarding_daemon.in (+34 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_ip_forwarding_daemon
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup google_network_setup
8
# KEYWORD: shutdown
9
#
10
# google_ip_forwarding_daemon_enable (bool): Set to YES by default.
11
#					     Set it to NO to disable google_ip_forwarding_daemon.
12
#
13
14
. /etc/rc.subr
15
16
name="google_ip_forwarding_daemon"
17
rcvar="google_ip_forwarding_daemon_enable"
18
19
load_rc_config "${name}"
20
21
: ${google_ip_forwarding_daemon_enable:="YES"}
22
23
command_interpreter="%%PYTHON_CMD%%"
24
command=%%PREFIX%%/bin/${name}
25
pidfile=/var/run/${name}.pid
26
start_cmd="google_ip_forwarding_daemon_start"
27
28
google_ip_forwarding_daemon_start()
29
{
30
  check_startmsgs && echo "Starting ${name}."
31
  daemon -p ${pidfile} -t ${name} ${command}
32
}
33
34
run_rc_command "$1"
(-)net/google-compute-engine/files/google_network_setup.in (+26 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_network_setup
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup
8
#
9
# google_network_setup_enable (bool):	Set to YES by default.
10
#					Set it to NO to disable google_network_setup.
11
#
12
13
. /etc/rc.subr
14
15
name="google_network_setup"
16
rcvar="google_network_setup_enable"
17
18
load_rc_config "${name}"
19
20
: ${google_network_setup_enable:="YES"}
21
22
command_interpreter="%%PYTHON_CMD%%"
23
command=%%PREFIX%%/bin/${name}
24
pidfile=/var/run/${name}.pid
25
26
run_rc_command "$1"
(-)net/google-compute-engine/files/google_shutdown_scripts.in (+40 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_shutdown_scripts
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup google_network_setup
8
# KEYWORD: shutdown
9
#
10
# google_shutdown_scripts_enable (bool): 	Set to YES by default.
11
#						Set it to NO to disable google_shutdown_scripts.
12
#
13
14
. /etc/rc.subr
15
16
name="google_shutdown_scripts"
17
rcvar="google_shutdown_scripts_enable"
18
19
load_rc_config "${name}"
20
21
: ${google_shutdown_scripts_enable:="YES"}
22
23
command_interpreter="%%PYTHON_CMD%%"
24
command=%%PREFIX%%/bin/google_metadata_script_runner
25
command_args="--script-type shutdown"
26
pidfile=/var/run/${name}.pid
27
start_cmd="google_shutdown_scripts_start"
28
stop_cmd="google_shutdown_scripts_stop"
29
30
google_shutdown_scripts_start()
31
{
32
}
33
34
google_shutdown_scripts_stop()
35
{
36
  echo "Stopping ${name}."
37
  ${command} ${command_args}
38
}
39
40
run_rc_command "$1"
(-)net/google-compute-engine/files/google_startup_scripts.in (+27 lines)
Added Link Here
1
#!/bin/sh
2
3
# $FreeBSD$
4
#
5
# PROVIDE: google_startup_scripts
6
# BEFORE: LOGIN
7
# REQUIRE: NETWORKING syslogd google_instance_setup google_network_setup
8
#
9
# google_startup_scripts_enable (bool): 	Set to YES by default.
10
#						Set it to NO to disable google_startup_scripts.
11
#
12
13
. /etc/rc.subr
14
15
name="google_startup_scripts"
16
rcvar="google_startup_scripts_enable"
17
18
load_rc_config "${name}"
19
20
: ${google_startup_scripts_enable:="YES"}
21
22
command_interpreter="%%PYTHON_CMD%%"
23
command=%%PREFIX%%/bin/google_metadata_script_runner
24
command_args="--script-type startup"
25
pidfile=/var/run/${name}.pid
26
27
run_rc_command "$1"
(-)net/google-compute-engine/files/patch-google__compute__engine_accounts_accounts__daemon.py (+11 lines)
Added Link Here
1
--- google_compute_engine/accounts/accounts_daemon.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/accounts/accounts_daemon.py
3
@@ -27,7 +27,7 @@
4
 from google_compute_engine import metadata_watcher
5
 from google_compute_engine.accounts import accounts_utils
6
 
7
-LOCKFILE = '/var/lock/google_accounts.lock'
8
+LOCKFILE = '/var/spool/lock/google_accounts.lock'
9
 
10
 
11
 class AccountsDaemon(object):
(-)net/google-compute-engine/files/patch-google__compute__engine_accounts_accounts__utils.py (+60 lines)
Added Link Here
1
--- google_compute_engine/accounts/accounts_utils.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/accounts/accounts_utils.py
3
@@ -43,8 +43,8 @@
4
     """
5
     self.logger = logger
6
     self.google_sudoers_group = 'google-sudoers'
7
-    self.google_sudoers_file = '/etc/sudoers.d/google_sudoers'
8
-    self.google_users_dir = '/var/lib/google'
9
+    self.google_sudoers_file = '%%PREFIX%%/etc/sudoers.d/google_sudoers'
10
+    self.google_users_dir = '%%PREFIX%%/var/lib/google'
11
     self.google_users_file = os.path.join(self.google_users_dir, 'google_users')
12
 
13
     self._CreateSudoersGroup()
14
@@ -71,7 +71,7 @@
15
     """Create a Linux group for Google added sudo user accounts."""
16
     if not self._GetGroup(self.google_sudoers_group):
17
       try:
18
-        subprocess.check_call(['groupadd', self.google_sudoers_group])
19
+        subprocess.check_call(['pw', 'groupadd', self.google_sudoers_group])
20
       except subprocess.CalledProcessError as e:
21
         self.logger.warning('Could not create the sudoers group. %s.', str(e))
22
 
23
@@ -126,7 +126,7 @@
24
     #
25
     # To solve the issue, make the password '*' which is also recognized
26
     # as locked but does not prevent SSH login.
27
-    command = ['useradd', '-m', '-s', '/bin/bash', '-p', '*', user]
28
+    command = ['pw', 'useradd', user, '-m']
29
     try:
30
       subprocess.check_call(command)
31
     except subprocess.CalledProcessError as e:
32
@@ -148,7 +148,7 @@
33
     """
34
     groups = ','.join(groups)
35
     self.logger.debug('Updating user %s with groups %s.', user, groups)
36
-    command = ['usermod', '-G', groups, user]
37
+    command = ['pw', 'usermod', user, '-G', groups]
38
     try:
39
       subprocess.check_call(command)
40
     except subprocess.CalledProcessError as e:
41
@@ -295,8 +295,8 @@
42
     # logins. This helps avoid problems caused by operator and root sharing
43
     # a home directory in CentOS and RHEL.
44
     pw_entry = self._GetUser(user)
45
-    if pw_entry and pw_entry.pw_shell == '/sbin/nologin':
46
-      message = 'Not updating user %s. User set /sbin/nologin as login shell.'
47
+    if pw_entry and os.path.basename(pw_entry.pw_shell) == 'nologin':
48
+      message = 'Not updating user %s. User set `nologin` as login shell.'
49
       self.logger.debug(message, user)
50
       return True
51
 
52
@@ -317,7 +317,7 @@
53
     """
54
     self.logger.info('Removing user %s.', user)
55
     if self.remove:
56
-      command = ['userdel', '-r', user]
57
+      command = ['pw', 'userdel', user, '-r']
58
       try:
59
         subprocess.check_call(command)
60
       except subprocess.CalledProcessError as e:
(-)net/google-compute-engine/files/patch-google__compute__engine_boto_boto__config.py (+24 lines)
Added Link Here
1
--- google_compute_engine/boto/boto_config.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/boto/boto_config.py
3
@@ -18,8 +18,8 @@
4
 If a project ID is not provided, this request the project ID from the
5
 metadata server and install the compute authentication plugin.
6
 
7
-Note the config starts with the content in /etc/boto.cfg.template,
8
-overrides settings, and then persists it into /etc/boto.cfg. This
9
+Note the config starts with the content in %%PREFIX%%/etc/boto.cfg.template,
10
+overrides settings, and then persists it into %%PREFIX%%/etc/boto.cfg. This
11
 is done so that the system boto.cfg can be removed prior to image
12
 packaging.
13
 """
14
@@ -34,8 +34,8 @@
15
 class BotoConfig(object):
16
   """Creates a boto config file for standalone GSUtil."""
17
 
18
-  boto_config = '/etc/boto.cfg'
19
-  boto_config_template = '/etc/boto.cfg.template'
20
+  boto_config = '%%PREFIX%%/etc/boto.cfg'
21
+  boto_config_template = '%%PREFIX%%/etc/boto.cfg.template'
22
   boto_config_script = os.path.abspath(__file__)
23
   boto_config_header = (
24
       'This file is automatically created at boot time by the %s script. Do '
(-)net/google-compute-engine/files/patch-google__compute__engine_boto_compute__auth.py (+11 lines)
Added Link Here
1
--- google_compute_engine/boto/compute_auth.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/boto/compute_auth.py
3
@@ -29,7 +29,7 @@
4
 class ComputeAuth(auth_handler.AuthHandler):
5
   """Google Compute service account auth handler.
6
 
7
-  The boto library reads the system config file (/etc/boto.cfg) and looks
8
+  The boto library reads the system config file (%%PREFIX%%/etc/boto.cfg) and looks
9
   at a config value called 'plugin_directory'. It then loads the Python
10
   files and find classes derived from boto.auth_handler.AuthHandler.
11
   """
(-)net/google-compute-engine/files/patch-google__compute__engine_clock__skew_clock__skew__daemon.py (+26 lines)
Added Link Here
1
--- google_compute_engine/clock_skew/clock_skew_daemon.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/clock_skew/clock_skew_daemon.py
3
@@ -24,7 +24,7 @@
4
 from google_compute_engine import logger
5
 from google_compute_engine import metadata_watcher
6
 
7
-LOCKFILE = '/var/lock/google_clock_skew.lock'
8
+LOCKFILE = '/var/spool/lock/google_clock_skew.lock'
9
 
10
 
11
 class ClockSkewDaemon(object):
12
@@ -58,9 +58,12 @@
13
       response: string, the metadata response with the new drift token value.
14
     """
15
     self.logger.info('Clock drift token has changed: %s.', response)
16
-    command = ['/sbin/hwclock', '--hctosys']
17
+
18
+    ntpd_inactive = subprocess.call(['service', 'ntpd', 'status'])
19
     try:
20
-      subprocess.check_call(command)
21
+      if not ntpd_inactive: subprocess.check_call(['service', 'ntpd', 'stop'])
22
+      subprocess.check_call('ntpdate `awk \'$1=="server" {print $2}\' /etc/ntp.conf`', shell=True)
23
+      if not ntpd_inactive: subprocess.check_call(['service', 'ntpd', 'start'])
24
     except subprocess.CalledProcessError:
25
       self.logger.warning('Failed to sync system time with hardware clock.')
26
     else:
(-)net/google-compute-engine/files/patch-google__compute__engine_config__manager.py (+20 lines)
Added Link Here
1
--- google_compute_engine/config_manager.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/config_manager.py
3
@@ -21,7 +21,7 @@
4
 from google_compute_engine import file_utils
5
 from google_compute_engine.compat import parser
6
 
7
-CONFIG = '/etc/default/instance_configs.cfg'
8
+CONFIG = '%%PREFIX%%/etc/instance_configs.cfg'
9
 
10
 
11
 class ConfigManager(object):
12
@@ -101,7 +101,7 @@
13
     """
14
     config_file = config_file or self.config_file
15
     config_name = os.path.splitext(os.path.basename(config_file))[0]
16
-    config_lock = '/var/lock/google_%s.lock' % config_name
17
+    config_lock = '/var/spool/lock/google_%s.lock' % config_name
18
     with file_utils.LockFile(config_lock):
19
       with open(config_file, 'w') as config_fp:
20
         if self.config_header:
(-)net/google-compute-engine/files/patch-google__compute__engine_instance__setup_instance__config.py (+45 lines)
Added Link Here
1
--- google_compute_engine/instance_setup/instance_config.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/instance_setup/instance_config.py
3
@@ -16,8 +16,8 @@
4
 """A library used to set up the instance's default configurations file.
5
 
6
 Note that the configurations in
7
-/etc/default/instance_configs.cfg.template override the values set in
8
-/etc/default/instance_configs.cfg. The system instance_configs.cfg may be
9
+%%PREFIX%%/etc/instance_configs.cfg.template override the values set in
10
+%%PREFIX%%/etc/instance_configs.cfg. The system instance_configs.cfg may be
11
 overridden during package upgrade.
12
 """
13
 
14
@@ -32,7 +32,7 @@
15
 class InstanceConfig(config_manager.ConfigManager):
16
   """Creates a defaults config file for instance configuration."""
17
 
18
-  instance_config = '/etc/default/instance_configs.cfg'
19
+  instance_config = '%%PREFIX%%/etc/instance_configs.cfg'
20
   instance_config_distro = '%s.distro' % instance_config
21
   instance_config_template = '%s.template' % instance_config
22
   instance_config_script = os.path.abspath(__file__)
23
@@ -40,7 +40,7 @@
24
       'This file is automatically created at boot time by the %s script. Do '
25
       'not edit this file directly. If you need to add items to this file, '
26
       'create or edit %s instead and then run '
27
-      '/usr/bin/google_instance_setup.')
28
+      '%%PREFIX%%/bin/google_instance_setup.')
29
   instance_config_options = {
30
       'Accounts': {
31
           'deprovision_remove': 'false',
32
@@ -55,11 +55,11 @@
33
           'instance_id': '0',
34
       },
35
       'InstanceSetup': {
36
-          'optimize_local_ssd': 'true',
37
+          'optimize_local_ssd': 'false',
38
           'network_enabled': 'true',
39
           'set_boto_config': 'true',
40
           'set_host_keys': 'true',
41
-          'set_multiqueue': 'true',
42
+          'set_multiqueue': 'false',
43
       },
44
       'IpForwarding': {
45
           'ethernet_proto_id': '66',
(-)net/google-compute-engine/files/patch-google__compute__engine_instance__setup_instance__setup.py (+22 lines)
Added Link Here
1
--- google_compute_engine/instance_setup/instance_setup.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/instance_setup/instance_setup.py
3
@@ -143,14 +143,14 @@
4
     """Initialize the SSH daemon."""
5
     # Exit as early as possible.
6
     # Instance setup systemd scripts block sshd from starting.
7
-    if os.path.exists('/bin/systemctl'):
8
+    if os.path.exists('%%PREFIX%%/bin/systemctl'):
9
       return
10
-    elif (os.path.exists('/etc/init.d/ssh') or
11
-          os.path.exists('/etc/init/ssh.conf')):
12
+    elif (os.path.exists('/etc/rc.d/ssh') or
13
+          os.path.exists('/etc/rc/ssh.conf')):
14
       subprocess.call(['service', 'ssh', 'start'])
15
       subprocess.call(['service', 'ssh', 'reload'])
16
-    elif (os.path.exists('/etc/init.d/sshd') or
17
-          os.path.exists('/etc/init/sshd.conf')):
18
+    elif (os.path.exists('/etc/rc.d/sshd') or
19
+          os.path.exists('/etc/rc/sshd.conf')):
20
       subprocess.call(['service', 'sshd', 'start'])
21
       subprocess.call(['service', 'sshd', 'reload'])
22
 
(-)net/google-compute-engine/files/patch-google__compute__engine_ip__forwarding_ip__forwarding__daemon.py (+32 lines)
Added Link Here
1
--- google_compute_engine/ip_forwarding/ip_forwarding_daemon.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/ip_forwarding/ip_forwarding_daemon.py
3
@@ -38,7 +38,7 @@
4
 
5
 from google_compute_engine.ip_forwarding import ip_forwarding_utils
6
 
7
-LOCKFILE = '/var/lock/google_ip_forwarding.lock'
8
+LOCKFILE = '/var/spool/lock/google_ip_forwarding.lock'
9
 
10
 
11
 class IpForwardingDaemon(object):
12
@@ -131,18 +131,18 @@
13
     Args:
14
       result: dict, the metadata response with the new network interfaces.
15
     """
16
+    ip_addresses = []
17
     for network_interface in result:
18
       mac_address = network_interface.get('mac')
19
       interface = self.network_utils.GetNetworkInterface(mac_address)
20
-      ip_addresses = []
21
       if interface:
22
         ip_addresses.extend(network_interface.get('forwardedIps', []))
23
         if self.ip_aliases:
24
           ip_addresses.extend(network_interface.get('ipAliases', []))
25
-        self._HandleForwardedIps(ip_addresses, interface)
26
       else:
27
         message = 'Network interface not found for MAC address: %s.'
28
         self.logger.warning(message, mac_address)
29
+    self._HandleForwardedIps(ip_addresses, 'lo' + self.ip_forwarding_utils.proto_id)
30
 
31
 
32
 def main():
(-)net/google-compute-engine/files/patch-google__compute__engine_ip__forwarding_ip__forwarding__utils.py (+77 lines)
Added Link Here
1
--- google_compute_engine/ip_forwarding/ip_forwarding_utils.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/ip_forwarding/ip_forwarding_utils.py
3
@@ -17,6 +17,8 @@
4
 
5
 import re
6
 import subprocess
7
+import netifaces
8
+import netaddr
9
 
10
 IP_REGEX = re.compile(r'\A(\d{1,3}\.){3}\d{1,3}\Z')
11
 IP_ALIAS_REGEX = re.compile(r'\A(\d{1,3}\.){3}\d{1,3}/\d{1,2}\Z')
12
@@ -51,8 +53,8 @@
13
     options.update(kwargs)
14
     return options
15
 
16
-  def _RunIpRoute(self, args=None, options=None):
17
-    """Run a command with ip route and return the response.
18
+  def _RunIfconfig(self, args=None, options=None):
19
+    """Run a command with ifconfig and return the response.
20
 
21
     Args:
22
       args: list, the string ip route command args to execute.
23
@@ -63,7 +65,7 @@
24
     """
25
     args = args or []
26
     options = options or {}
27
-    command = ['ip', 'route']
28
+    command = ['ifconfig']
29
     command.extend(args)
30
     for item in options.items():
31
       command.extend(item)
32
@@ -108,10 +110,15 @@
33
     Returns:
34
       list, the IP address strings.
35
     """
36
-    args = ['ls', 'table', 'local', 'type', 'local']
37
-    options = self._CreateRouteOptions(dev=interface)
38
-    result = self._RunIpRoute(args=args, options=options)
39
-    return self.ParseForwardedIps(result.split())
40
+    try:
41
+      ips = netifaces.ifaddresses('lo' + self.proto_id)
42
+      ips = ips[netifaces.AF_INET]
43
+    except (ValueError, KeyError) as e:
44
+      return []
45
+    forwarded_ips = []
46
+    for ip in ips:
47
+      forwarded_ips.append(ip['addr'] + '/' + str(netaddr.IPAddress(ip['netmask']).netmask_bits()))
48
+    return self.ParseForwardedIps(forwarded_ips)
49
 
50
   def AddForwardedIp(self, address, interface):
51
     """Configure a new IP address on the network interface.
52
@@ -121,9 +128,12 @@
53
       interface: string, the output device to use.
54
     """
55
     address = address if IP_ALIAS_REGEX.match(address) else '%s/32' % address
56
-    args = ['add', 'to', 'local', address]
57
-    options = self._CreateRouteOptions(dev=interface)
58
-    self._RunIpRoute(args=args, options=options)
59
+    cmd = 'alias'
60
+    try:
61
+      forwarded_ips = netifaces.ifaddresses(interface)
62
+    except (ValueError, KeyError) as e:
63
+      cmd = 'create'
64
+    self._RunIfconfig(args=[interface, cmd, address])
65
 
66
   def RemoveForwardedIp(self, address, interface):
67
     """Delete an IP address on the network interface.
68
@@ -132,7 +142,5 @@
69
       address: string, the IP address to configure.
70
       interface: string, the output device to use.
71
     """
72
-    address = address if IP_ALIAS_REGEX.match(address) else '%s/32' % address
73
-    args = ['delete', 'to', 'local', address]
74
-    options = self._CreateRouteOptions(dev=interface)
75
-    self._RunIpRoute(args=args, options=options)
76
+    address = address if IP_REGEX.match(address) else address[:-3]
77
+    self._RunIfconfig(args=[interface, '-alias', address])
(-)net/google-compute-engine/files/patch-google__compute__engine_metadata__scripts_script__executor.py (+11 lines)
Added Link Here
1
--- google_compute_engine/metadata_scripts/script_executor.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/metadata_scripts/script_executor.py
3
@@ -50,7 +50,7 @@
4
       metadata_script: string, the file location of an executable script.
5
     """
6
     process = subprocess.Popen(
7
-        metadata_script, shell=True, executable='/bin/bash',
8
+        metadata_script, shell=True, executable='%%PREFIX%%/bin/bash',
9
         stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
10
     while True:
11
       for line in iter(process.stdout.readline, b''):
(-)net/google-compute-engine/files/patch-google__compute__engine_network__setup_network__setup.py (+45 lines)
Added Link Here
1
--- google_compute_engine/network_setup/network_setup.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/network_setup/network_setup.py
3
@@ -74,7 +74,7 @@
4
     Args:
5
       interfaces: list of string, the output device names enable.
6
     """
7
-    interface_path = '/etc/sysconfig/network-scripts'
8
+    interface_path = '%%PREFIX%%/etc/sysconfig/network-scripts'
9
     for interface in interfaces:
10
       interface_config = os.path.join(interface_path, 'ifcfg-%s' % interface)
11
       if os.path.exists(interface_config):
12
@@ -106,12 +106,18 @@
13
     self.logger.info('Enabling the Ethernet interfaces %s.', interfaces)
14
     dhclient_command = ['dhclient']
15
     if os.path.exists(self.dhclient_script):
16
-      dhclient_command += ['-sf', self.dhclient_script]
17
-    try:
18
-      subprocess.check_call(dhclient_command + ['-x'] + interfaces)
19
-      subprocess.check_call(dhclient_command + interfaces)
20
-    except subprocess.CalledProcessError:
21
-      self.logger.warning('Could not enable interfaces %s.', interfaces)
22
+      dhclient_conf = '/etc/dhclient.conf'
23
+      if os.path.exists(dhclient_conf):
24
+        subprocess.call('sed -i "" "/^script/d" ' + dhclient_conf, shell=True)
25
+      subprocess.call('echo \'script "%s";\' >> %s' % (self.dhclient_script, dhclient_conf), shell=True)
26
+    for interface in interfaces:
27
+      try:
28
+        subprocess.check_call(['ifconfig', interface, 'down', 'delete'])
29
+        # wait previous dhclient to exit
30
+        subprocess.check_call(['sleep', '3'])
31
+        subprocess.check_call(dhclient_command + [interface])
32
+      except subprocess.CalledProcessError:
33
+        self.logger.warning('Could not enable interface %s.', interface)
34
 
35
   def _EnableNetworkInterfaces(self, interfaces):
36
     """Enable the list of network interfaces.
37
@@ -130,7 +136,7 @@
38
       except subprocess.CalledProcessError:
39
         self.logger.warning('Could not enable Ethernet interfaces.')
40
     else:
41
-      if os.path.exists('/etc/sysconfig/network-scripts'):
42
+      if os.path.exists('%%PREFIX%%/etc/sysconfig/network-scripts'):
43
         self._DisableNetworkManager(interfaces)
44
       self._ConfigureNetwork(interfaces)
45
 
(-)net/google-compute-engine/files/patch-google__compute__engine_network__utils.py (+27 lines)
Added Link Here
1
--- google_compute_engine/network_utils.py.orig	2017-06-10 00:18:58 UTC
2
+++ google_compute_engine/network_utils.py
3
@@ -17,6 +17,7 @@
4
 
5
 import logging
6
 import os
7
+import netifaces
8
 
9
 
10
 class NetworkUtils(object):
11
@@ -38,11 +39,12 @@
12
       dict, string MAC addresses mapped to the string network interface name.
13
     """
14
     interfaces = {}
15
-    for interface in os.listdir('/sys/class/net'):
16
+    for interface in netifaces.interfaces():
17
       try:
18
-        mac_address = open(
19
-            '/sys/class/net/%s/address' % interface).read().strip()
20
-      except (IOError, OSError) as e:
21
+        mac_address = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr']
22
+        if  mac_address == interface:
23
+            raise Exception('No MAC Address')
24
+      except Exception, e:
25
         message = 'Unable to determine MAC address for %s. %s.'
26
         self.logger.warning(message, interface, str(e))
27
       else:
(-)net/google-compute-engine/files/patch-setup.py (+13 lines)
Added Link Here
1
--- setup.py.orig	2017-06-10 00:18:58 UTC
2
+++ setup.py
3
@@ -30,9 +30,8 @@
4
     long_description='Google Compute Engine guest environment.',
5
     name='google-compute-engine',
6
     packages=setuptools.find_packages(),
7
-    scripts=glob.glob('scripts/*'),
8
     url='https://github.com/GoogleCloudPlatform/compute-image-packages',
9
-    version='2.4.0',
10
+    version='2.4.1',
11
     # Entry points create scripts in /usr/bin that call a function.
12
     entry_points={
13
         'console_scripts': [
(-)net/google-compute-engine/pkg-descr (+14 lines)
Added Link Here
1
Google Compute Engine offers scripts and daemons which runs in the
2
background and provides the following services:
3
4
- Accounts daemon to setup and manage user accounts, and to enable SSH key based
5
  authentication.
6
- Clock skew daemon to keep the system clock in sync after VM start and stop
7
  events.
8
- Instance setup scripts to execute VM configuration scripts during boot.
9
- IP forwarding daemon that integrates network load balancing with forwarding
10
  rule changes into the guest.
11
- Metadata scripts to run user provided scripts at VM startup and shutdown.
12
- Network setup service to enable multiple network interfaces on boot.
13
14
WWW: https://github.com/GoogleCloudPlatform/compute-image-packages
(-)net/google-compute-engine/pkg-message (+26 lines)
Added Link Here
1
2
==============================================================================
3
4
google-compute-engine has been installed, and the following services are
5
available:
6
7
google_accounts_daemon		Responsible for provisioning and
8
				deprovisioning user accounts
9
google_clock_skew_daemon	Responsible for syncing the software clock with
10
				the hypervisor clock
11
google_instance_setup		Configure the guest at boot
12
google_ip_forwarding_daemon	Responsible to setup or remove IP routes in the
13
				guest
14
google_network_setup		Responsible to enables all associated network
15
				interfaces
16
google_shutdown_scripts		Implement support for running host provided
17
				shutdown scripts
18
google_startup_scripts		Implement support for running host provided
19
                                startup scripts
20
21
The above services are enabled by default, set <servicename>_enable=NO in
22
/etc/rc.conf to disable execution of the script at boot.
23
24
Reboot your system after installation of this package to activate the services
25
26
==============================================================================

Return to bug 219687