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

Collapse All | Expand All

(-)sysutils/py-google-compute-engine/Makefile (+43 lines)
Added Link Here
1
# $FreeBSD$
2
3
PORTNAME=	google-compute-engine
4
PORTVERSION=	2.4.1
5
CATEGORIES=	sysutils python
6
MASTER_SITES=	CHEESESHOP
7
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
8
9
MAINTAINER=	helen.koike@collabora.com
10
COMMENT=	Guest Environment for Google Compute Engine
11
12
LICENSE=	APACHE20
13
LICENSE_FILE=	${WRKSRC}/LICENSE
14
15
RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}boto>0:devel/py-boto \
16
		${PYTHON_PKGNAMEPREFIX}netaddr>0:net/py-netaddr \
17
		${PYTHON_PKGNAMEPREFIX}netifaces>0:net/py-netifaces \
18
		sudo:security/sudo
19
20
USES=		python
21
USE_PYTHON=	autoplist concurrent distutils
22
23
USE_RC_SUBR=	google_instance_setup \
24
		google_network_setup \
25
		google_accounts_daemon \
26
		google_clock_skew_daemon \
27
		google_startup_scripts \
28
		google_shutdown_scripts
29
30
SUB_LIST=	PYTHON_CMD="${PYTHON_CMD}"
31
REINPLACE_ARGS=	-i ''
32
33
post-patch:
34
	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|g' \
35
		${WRKSRC}/google_compute_engine/accounts/accounts_utils.py \
36
		${WRKSRC}/google_compute_engine/boto/boto_config.py \
37
		${WRKSRC}/google_compute_engine/boto/compute_auth.py \
38
		${WRKSRC}/google_compute_engine/config_manager.py \
39
		${WRKSRC}/google_compute_engine/instance_setup/instance_config.py \
40
		${WRKSRC}/google_compute_engine/metadata_scripts/script_executor.py \
41
		${WRKSRC}/google_compute_engine/network_setup/network_setup.py
42
43
.include <bsd.port.mk>
(-)sysutils/py-google-compute-engine/distinfo (+3 lines)
Added Link Here
1
TIMESTAMP = 1501403910
2
SHA256 (google-compute-engine-2.4.1.tar.gz) = d1709420ade5e7b8318b73c8ae245382cfe362e0f9b5236d3a28c0459a6d8d49
3
SIZE (google-compute-engine-2.4.1.tar.gz) = 28626
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-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"
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_accounts_accounts__daemon.py (+14 lines)
Added Link Here
1
This patch won't be necessary anymore in further versions.
2
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
3
4
--- google_compute_engine/accounts/accounts_daemon.py.orig	2017-07-18 16:43:14 UTC
5
+++ google_compute_engine/accounts/accounts_daemon.py
6
@@ -27,7 +27,7 @@ from google_compute_engine import logger
7
 from google_compute_engine import metadata_watcher
8
 from google_compute_engine.accounts import accounts_utils
9
 
10
-LOCKFILE = '/var/lock/google_accounts.lock'
11
+LOCKFILE = '/var/spool/lock/google_accounts.lock'
12
 
13
 
14
 class AccountsDaemon(object):
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_accounts_accounts__utils.py (+52 lines)
Added Link Here
1
This patch won't be necessary anymore in further versions.
2
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
3
4
--- google_compute_engine/accounts/accounts_utils.py.orig	2017-07-23 07:12:16 UTC
5
+++ google_compute_engine/accounts/accounts_utils.py
6
@@ -43,8 +43,8 @@ class AccountsUtils(object):
7
     """
8
     self.logger = logger
9
     self.google_sudoers_group = 'google-sudoers'
10
-    self.google_sudoers_file = '/etc/sudoers.d/google_sudoers'
11
-    self.google_users_dir = '/var/lib/google'
12
+    self.google_sudoers_file = '%%PREFIX%%/etc/sudoers.d/google_sudoers'
13
+    self.google_users_dir = '%%PREFIX%%/var/lib/google'
14
     self.google_users_file = os.path.join(self.google_users_dir, 'google_users')
15
 
16
     self._CreateSudoersGroup()
17
@@ -71,7 +71,7 @@ class AccountsUtils(object):
18
     """Create a Linux group for Google added sudo user accounts."""
19
     if not self._GetGroup(self.google_sudoers_group):
20
       try:
21
-        subprocess.check_call(['groupadd', self.google_sudoers_group])
22
+        subprocess.check_call(['pw', 'groupadd', self.google_sudoers_group])
23
       except subprocess.CalledProcessError as e:
24
         self.logger.warning('Could not create the sudoers group. %s.', str(e))
25
 
26
@@ -126,7 +126,7 @@ class AccountsUtils(object):
27
     #
28
     # To solve the issue, make the password '*' which is also recognized
29
     # as locked but does not prevent SSH login.
30
-    command = ['useradd', '-m', '-s', '/bin/bash', '-p', '*', user]
31
+    command = ['pw', 'useradd', user, '-m']
32
     try:
33
       subprocess.check_call(command)
34
     except subprocess.CalledProcessError as e:
35
@@ -148,7 +148,7 @@ class AccountsUtils(object):
36
     """
37
     groups = ','.join(groups)
38
     self.logger.debug('Updating user %s with groups %s.', user, groups)
39
-    command = ['usermod', '-G', groups, user]
40
+    command = ['pw', 'usermod', user, '-G', groups]
41
     try:
42
       subprocess.check_call(command)
43
     except subprocess.CalledProcessError as e:
44
@@ -317,7 +317,7 @@ class AccountsUtils(object):
45
     """
46
     self.logger.info('Removing user %s.', user)
47
     if self.remove:
48
-      command = ['userdel', '-r', user]
49
+      command = ['pw', 'userdel', user, '-r']
50
       try:
51
         subprocess.check_call(command)
52
       except subprocess.CalledProcessError as e:
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_boto_boto__config.py (+27 lines)
Added Link Here
1
This patch won't be necessary anymore in further versions.
2
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
3
4
--- google_compute_engine/boto/boto_config.py.orig	2017-07-23 07:12:16 UTC
5
+++ google_compute_engine/boto/boto_config.py
6
@@ -18,8 +18,8 @@
7
 If a project ID is not provided, this request the project ID from the
8
 metadata server and install the compute authentication plugin.
9
 
10
-Note the config starts with the content in /etc/boto.cfg.template,
11
-overrides settings, and then persists it into /etc/boto.cfg. This
12
+Note the config starts with the content in %%PREFIX%%/etc/boto.cfg.template,
13
+overrides settings, and then persists it into %%PREFIX%%/etc/boto.cfg. This
14
 is done so that the system boto.cfg can be removed prior to image
15
 packaging.
16
 """
17
@@ -34,8 +34,8 @@ from google_compute_engine import metada
18
 class BotoConfig(object):
19
   """Creates a boto config file for standalone GSUtil."""
20
 
21
-  boto_config = '/etc/boto.cfg'
22
-  boto_config_template = '/etc/boto.cfg.template'
23
+  boto_config = '%%PREFIX%%/etc/boto.cfg'
24
+  boto_config_template = '%%PREFIX%%/etc/boto.cfg.template'
25
   boto_config_script = os.path.abspath(__file__)
26
   boto_config_header = (
27
       'This file is automatically created at boot time by the %s script. Do '
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_boto_compute__auth.py (+13 lines)
Added Link Here
1
This is only a cosmetic patch as it fixes docs and not execution
2
3
--- google_compute_engine/boto/compute_auth.py.orig	2017-07-23 07:12:16 UTC
4
+++ google_compute_engine/boto/compute_auth.py
5
@@ -29,7 +29,7 @@ GS_SCOPES = set([
6
 class ComputeAuth(auth_handler.AuthHandler):
7
   """Google Compute service account auth handler.
8
 
9
-  The boto library reads the system config file (/etc/boto.cfg) and looks
10
+  The boto library reads the system config file (%%PREFIX%%/etc/boto.cfg) and looks
11
   at a config value called 'plugin_directory'. It then loads the Python
12
   files and find classes derived from boto.auth_handler.AuthHandler.
13
   """
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_clock__skew_clock__skew__daemon.py (+28 lines)
Added Link Here
1
BSD doesn't have hwclock, use ntpdate instead
2
3
--- google_compute_engine/clock_skew/clock_skew_daemon.py.orig	2017-07-18 16:43:14 UTC
4
+++ google_compute_engine/clock_skew/clock_skew_daemon.py
5
@@ -24,7 +24,7 @@ from google_compute_engine import file_u
6
 from google_compute_engine import logger
7
 from google_compute_engine import metadata_watcher
8
 
9
-LOCKFILE = '/var/lock/google_clock_skew.lock'
10
+LOCKFILE = '/var/spool/lock/google_clock_skew.lock'
11
 
12
 
13
 class ClockSkewDaemon(object):
14
@@ -58,9 +58,12 @@ class ClockSkewDaemon(object):
15
       response: string, the metadata response with the new drift token value.
16
     """
17
     self.logger.info('Clock drift token has changed: %s.', response)
18
-    command = ['/sbin/hwclock', '--hctosys']
19
+
20
+    ntpd_inactive = subprocess.call(['service', 'ntpd', 'status'])
21
     try:
22
-      subprocess.check_call(command)
23
+      if not ntpd_inactive: subprocess.check_call(['service', 'ntpd', 'stop'])
24
+      subprocess.check_call('ntpdate `awk \'$1=="server" {print $2}\' /etc/ntp.conf`', shell=True)
25
+      if not ntpd_inactive: subprocess.check_call(['service', 'ntpd', 'start'])
26
     except subprocess.CalledProcessError:
27
       self.logger.warning('Failed to sync system time with hardware clock.')
28
     else:
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_config__manager.py (+23 lines)
Added Link Here
1
This patch won't be necessary anymore in further versions.
2
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
3
4
--- google_compute_engine/config_manager.py.orig	2017-07-23 07:12:16 UTC
5
+++ google_compute_engine/config_manager.py
6
@@ -21,7 +21,7 @@ import textwrap
7
 from google_compute_engine import file_utils
8
 from google_compute_engine.compat import parser
9
 
10
-CONFIG = '/etc/default/instance_configs.cfg'
11
+CONFIG = '%%PREFIX%%/etc/instance_configs.cfg'
12
 
13
 
14
 class ConfigManager(object):
15
@@ -101,7 +101,7 @@ class ConfigManager(object):
16
     """
17
     config_file = config_file or self.config_file
18
     config_name = os.path.splitext(os.path.basename(config_file))[0]
19
-    config_lock = '/var/lock/google_%s.lock' % config_name
20
+    config_lock = '/var/spool/lock/google_%s.lock' % config_name
21
     with file_utils.LockFile(config_lock):
22
       with open(config_file, 'w') as config_fp:
23
         if self.config_header:
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_instance__setup_instance__config.py (+49 lines)
Added Link Here
1
This patch fixes the paths and disable optimization scripts used only on Linux.
2
The variables won't be needed to be fixed in further versions
3
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
4
5
--- google_compute_engine/instance_setup/instance_config.py.orig	2017-07-23 07:12:16 UTC
6
+++ google_compute_engine/instance_setup/instance_config.py
7
@@ -16,8 +16,8 @@
8
 """A library used to set up the instance's default configurations file.
9
 
10
 Note that the configurations in
11
-/etc/default/instance_configs.cfg.template override the values set in
12
-/etc/default/instance_configs.cfg. The system instance_configs.cfg may be
13
+%%PREFIX%%/etc/instance_configs.cfg.template override the values set in
14
+%%PREFIX%%/etc/instance_configs.cfg. The system instance_configs.cfg may be
15
 overridden during package upgrade.
16
 """
17
 
18
@@ -32,7 +32,7 @@ from google_compute_engine.compat import
19
 class InstanceConfig(config_manager.ConfigManager):
20
   """Creates a defaults config file for instance configuration."""
21
 
22
-  instance_config = '/etc/default/instance_configs.cfg'
23
+  instance_config = '%%PREFIX%%/etc/instance_configs.cfg'
24
   instance_config_distro = '%s.distro' % instance_config
25
   instance_config_template = '%s.template' % instance_config
26
   instance_config_script = os.path.abspath(__file__)
27
@@ -40,7 +40,7 @@ class InstanceConfig(config_manager.Conf
28
       'This file is automatically created at boot time by the %s script. Do '
29
       'not edit this file directly. If you need to add items to this file, '
30
       'create or edit %s instead and then run '
31
-      '/usr/bin/google_instance_setup.')
32
+      '%%PREFIX%%/bin/google_instance_setup.')
33
   instance_config_options = {
34
       'Accounts': {
35
           'deprovision_remove': 'false',
36
@@ -55,11 +55,11 @@ class InstanceConfig(config_manager.Conf
37
           'instance_id': '0',
38
       },
39
       'InstanceSetup': {
40
-          'optimize_local_ssd': 'true',
41
+          'optimize_local_ssd': 'false',
42
           'network_enabled': 'true',
43
           'set_boto_config': 'true',
44
           'set_host_keys': 'true',
45
-          'set_multiqueue': 'true',
46
+          'set_multiqueue': 'false',
47
       },
48
       'IpForwarding': {
49
           'ethernet_proto_id': '66',
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_instance__setup_instance__setup.py (+26 lines)
Added Link Here
1
This patch fixes paths to rc scripts
2
The PREFIX fix won't be necessary anymore in further versions
3
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
4
5
--- google_compute_engine/instance_setup/instance_setup.py.orig	2017-07-18 16:43:14 UTC
6
+++ google_compute_engine/instance_setup/instance_setup.py
7
@@ -143,14 +143,14 @@ class InstanceSetup(object):
8
     """Initialize the SSH daemon."""
9
     # Exit as early as possible.
10
     # Instance setup systemd scripts block sshd from starting.
11
-    if os.path.exists('/bin/systemctl'):
12
+    if os.path.exists('%%PREFIX%%/bin/systemctl'):
13
       return
14
-    elif (os.path.exists('/etc/init.d/ssh') or
15
-          os.path.exists('/etc/init/ssh.conf')):
16
+    elif (os.path.exists('/etc/rc.d/ssh') or
17
+          os.path.exists('/etc/rc/ssh.conf')):
18
       subprocess.call(['service', 'ssh', 'start'])
19
       subprocess.call(['service', 'ssh', 'reload'])
20
-    elif (os.path.exists('/etc/init.d/sshd') or
21
-          os.path.exists('/etc/init/sshd.conf')):
22
+    elif (os.path.exists('/etc/rc.d/sshd') or
23
+          os.path.exists('/etc/rc/sshd.conf')):
24
       subprocess.call(['service', 'sshd', 'start'])
25
       subprocess.call(['service', 'sshd', 'reload'])
26
 
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_ip__forwarding_ip__forwarding__daemon.py (+35 lines)
Added Link Here
1
This patch depends on the follow PR from the upsteram project
2
https://github.com/GoogleCloudPlatform/compute-image-packages/pull/442
3
4
--- google_compute_engine/ip_forwarding/ip_forwarding_daemon.py.orig	2017-07-18 16:43:14 UTC
5
+++ google_compute_engine/ip_forwarding/ip_forwarding_daemon.py
6
@@ -38,7 +38,7 @@ from google_compute_engine import networ
7
 
8
 from google_compute_engine.ip_forwarding import ip_forwarding_utils
9
 
10
-LOCKFILE = '/var/lock/google_ip_forwarding.lock'
11
+LOCKFILE = '/var/spool/lock/google_ip_forwarding.lock'
12
 
13
 
14
 class IpForwardingDaemon(object):
15
@@ -131,18 +131,18 @@ class IpForwardingDaemon(object):
16
     Args:
17
       result: dict, the metadata response with the new network interfaces.
18
     """
19
+    ip_addresses = []
20
     for network_interface in result:
21
       mac_address = network_interface.get('mac')
22
       interface = self.network_utils.GetNetworkInterface(mac_address)
23
-      ip_addresses = []
24
       if interface:
25
         ip_addresses.extend(network_interface.get('forwardedIps', []))
26
         if self.ip_aliases:
27
           ip_addresses.extend(network_interface.get('ipAliases', []))
28
-        self._HandleForwardedIps(ip_addresses, interface)
29
       else:
30
         message = 'Network interface not found for MAC address: %s.'
31
         self.logger.warning(message, mac_address)
32
+    self._HandleForwardedIps(ip_addresses, 'lo' + self.ip_forwarding_utils.proto_id)
33
 
34
 
35
 def main():
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_ip__forwarding_ip__forwarding__utils.py (+80 lines)
Added Link Here
1
This patch depends on the follow PR from the upsteram project
2
https://github.com/GoogleCloudPlatform/compute-image-packages/pull/442
3
4
--- google_compute_engine/ip_forwarding/ip_forwarding_utils.py.orig	2017-07-18 16:43:14 UTC
5
+++ google_compute_engine/ip_forwarding/ip_forwarding_utils.py
6
@@ -17,6 +17,8 @@
7
 
8
 import re
9
 import subprocess
10
+import netifaces
11
+import netaddr
12
 
13
 IP_REGEX = re.compile(r'\A(\d{1,3}\.){3}\d{1,3}\Z')
14
 IP_ALIAS_REGEX = re.compile(r'\A(\d{1,3}\.){3}\d{1,3}/\d{1,2}\Z')
15
@@ -51,8 +53,8 @@ class IpForwardingUtils(object):
16
     options.update(kwargs)
17
     return options
18
 
19
-  def _RunIpRoute(self, args=None, options=None):
20
-    """Run a command with ip route and return the response.
21
+  def _RunIfconfig(self, args=None, options=None):
22
+    """Run a command with ifconfig and return the response.
23
 
24
     Args:
25
       args: list, the string ip route command args to execute.
26
@@ -63,7 +65,7 @@ class IpForwardingUtils(object):
27
     """
28
     args = args or []
29
     options = options or {}
30
-    command = ['ip', 'route']
31
+    command = ['ifconfig']
32
     command.extend(args)
33
     for item in options.items():
34
       command.extend(item)
35
@@ -108,10 +110,15 @@ class IpForwardingUtils(object):
36
     Returns:
37
       list, the IP address strings.
38
     """
39
-    args = ['ls', 'table', 'local', 'type', 'local']
40
-    options = self._CreateRouteOptions(dev=interface)
41
-    result = self._RunIpRoute(args=args, options=options)
42
-    return self.ParseForwardedIps(result.split())
43
+    try:
44
+      ips = netifaces.ifaddresses('lo' + self.proto_id)
45
+      ips = ips[netifaces.AF_INET]
46
+    except (ValueError, KeyError) as e:
47
+      return []
48
+    forwarded_ips = []
49
+    for ip in ips:
50
+      forwarded_ips.append(ip['addr'] + '/' + str(netaddr.IPAddress(ip['netmask']).netmask_bits()))
51
+    return self.ParseForwardedIps(forwarded_ips)
52
 
53
   def AddForwardedIp(self, address, interface):
54
     """Configure a new IP address on the network interface.
55
@@ -121,9 +128,12 @@ class IpForwardingUtils(object):
56
       interface: string, the output device to use.
57
     """
58
     address = address if IP_ALIAS_REGEX.match(address) else '%s/32' % address
59
-    args = ['add', 'to', 'local', address]
60
-    options = self._CreateRouteOptions(dev=interface)
61
-    self._RunIpRoute(args=args, options=options)
62
+    cmd = 'alias'
63
+    try:
64
+      forwarded_ips = netifaces.ifaddresses(interface)
65
+    except (ValueError, KeyError) as e:
66
+      cmd = 'create'
67
+    self._RunIfconfig(args=[interface, cmd, address])
68
 
69
   def RemoveForwardedIp(self, address, interface):
70
     """Delete an IP address on the network interface.
71
@@ -132,7 +142,5 @@ class IpForwardingUtils(object):
72
       address: string, the IP address to configure.
73
       interface: string, the output device to use.
74
     """
75
-    address = address if IP_ALIAS_REGEX.match(address) else '%s/32' % address
76
-    args = ['delete', 'to', 'local', address]
77
-    options = self._CreateRouteOptions(dev=interface)
78
-    self._RunIpRoute(args=args, options=options)
79
+    address = address if IP_REGEX.match(address) else address[:-3]
80
+    self._RunIfconfig(args=[interface, '-alias', address])
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_metadata__scripts_script__executor.py (+14 lines)
Added Link Here
1
This patch won't be necessary anymore in further versions.
2
See https://github.com/GoogleCloudPlatform/compute-image-packages/pull/440
3
4
--- google_compute_engine/metadata_scripts/script_executor.py.orig	2017-07-23 07:12:16 UTC
5
+++ google_compute_engine/metadata_scripts/script_executor.py
6
@@ -50,7 +50,7 @@ class ScriptExecutor(object):
7
       metadata_script: string, the file location of an executable script.
8
     """
9
     process = subprocess.Popen(
10
-        metadata_script, shell=True, executable='/bin/bash',
11
+        metadata_script, shell=True, executable='%%PREFIX%%/bin/bash',
12
         stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
13
     while True:
14
       for line in iter(process.stdout.readline, b''):
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_network__setup_network__setup.py (+47 lines)
Added Link Here
1
dhclient works a bit different in BSD compared to Linux, this patch adapts its usage.
2
3
--- google_compute_engine/network_setup/network_setup.py.orig	2017-07-23 07:12:16 UTC
4
+++ google_compute_engine/network_setup/network_setup.py
5
@@ -74,7 +74,7 @@ class NetworkSetup(object):
6
     Args:
7
       interfaces: list of string, the output device names enable.
8
     """
9
-    interface_path = '/etc/sysconfig/network-scripts'
10
+    interface_path = '%%PREFIX%%/etc/sysconfig/network-scripts'
11
     for interface in interfaces:
12
       interface_config = os.path.join(interface_path, 'ifcfg-%s' % interface)
13
       if os.path.exists(interface_config):
14
@@ -106,12 +106,18 @@ class NetworkSetup(object):
15
     self.logger.info('Enabling the Ethernet interfaces %s.', interfaces)
16
     dhclient_command = ['dhclient']
17
     if os.path.exists(self.dhclient_script):
18
-      dhclient_command += ['-sf', self.dhclient_script]
19
-    try:
20
-      subprocess.check_call(dhclient_command + ['-x'] + interfaces)
21
-      subprocess.check_call(dhclient_command + interfaces)
22
-    except subprocess.CalledProcessError:
23
-      self.logger.warning('Could not enable interfaces %s.', interfaces)
24
+      dhclient_conf = '/etc/dhclient.conf'
25
+      if os.path.exists(dhclient_conf):
26
+        subprocess.call('sed -i "" "/^script/d" ' + dhclient_conf, shell=True)
27
+      subprocess.call('echo \'script "%s";\' >> %s' % (self.dhclient_script, dhclient_conf), shell=True)
28
+    for interface in interfaces:
29
+      try:
30
+        subprocess.check_call(['ifconfig', interface, 'down', 'delete'])
31
+        # wait previous dhclient to exit
32
+        subprocess.check_call(['sleep', '3'])
33
+        subprocess.check_call(dhclient_command + [interface])
34
+      except subprocess.CalledProcessError:
35
+        self.logger.warning('Could not enable interface %s.', interface)
36
 
37
   def _EnableNetworkInterfaces(self, interfaces):
38
     """Enable the list of network interfaces.
39
@@ -130,7 +136,7 @@ class NetworkSetup(object):
40
       except subprocess.CalledProcessError:
41
         self.logger.warning('Could not enable Ethernet interfaces.')
42
     else:
43
-      if os.path.exists('/etc/sysconfig/network-scripts'):
44
+      if os.path.exists('%%PREFIX%%/etc/sysconfig/network-scripts'):
45
         self._DisableNetworkManager(interfaces)
46
       self._ConfigureNetwork(interfaces)
47
 
(-)sysutils/py-google-compute-engine/files/patch-google__compute__engine_network__utils.py (+30 lines)
Added Link Here
1
This patch depends on the follow PR from the upsteram project
2
https://github.com/GoogleCloudPlatform/compute-image-packages/pull/442
3
4
--- google_compute_engine/network_utils.py.orig	2017-07-18 16:43:14 UTC
5
+++ google_compute_engine/network_utils.py
6
@@ -17,6 +17,7 @@
7
 
8
 import logging
9
 import os
10
+import netifaces
11
 
12
 
13
 class NetworkUtils(object):
14
@@ -38,11 +39,12 @@ class NetworkUtils(object):
15
       dict, string MAC addresses mapped to the string network interface name.
16
     """
17
     interfaces = {}
18
-    for interface in os.listdir('/sys/class/net'):
19
+    for interface in netifaces.interfaces():
20
       try:
21
-        mac_address = open(
22
-            '/sys/class/net/%s/address' % interface).read().strip()
23
-      except (IOError, OSError) as e:
24
+        mac_address = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr']
25
+        if  mac_address == interface:
26
+            raise Exception('No MAC Address')
27
+      except Exception as e:
28
         message = 'Unable to determine MAC address for %s. %s.'
29
         self.logger.warning(message, interface, str(e))
30
       else:
(-)sysutils/py-google-compute-engine/files/patch-setup.py (+10 lines)
Added Link Here
1
--- setup.py.orig	2017-07-18 16:43:14 UTC
2
+++ setup.py
3
@@ -30,7 +30,6 @@ setuptools.setup(
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.1',
10
     # Entry points create scripts in /usr/bin that call a function.
(-)sysutils/py-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
(-)sysutils/py-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