summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceOVF.py11
-rw-r--r--cloudinit/sources/helpers/vmware/imc/guestcust_util.py60
2 files changed, 64 insertions, 7 deletions
diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
index 0fbdf0b8..bc13b71a 100644
--- a/cloudinit/sources/DataSourceOVF.py
+++ b/cloudinit/sources/DataSourceOVF.py
@@ -40,8 +40,11 @@ from cloudinit.sources.helpers.vmware.imc.guestcust_state import \
GuestCustStateEnum
from cloudinit.sources.helpers.vmware.imc.guestcust_error import \
GuestCustErrorEnum
-from cloudinit.sources.helpers.vmware.imc.guestcust_util import \
- set_customization_status
+from cloudinit.sources.helpers.vmware.imc.guestcust_util import (
+ set_customization_status,
+ get_nics_to_enable,
+ enable_nics
+)
LOG = logging.getLogger(__name__)
@@ -100,10 +103,13 @@ class DataSourceOVF(sources.DataSource):
LOG.debug("Customization for VMware platform is disabled.")
if vmwareImcConfigFilePath:
+ nics = ""
try:
cf = ConfigFile(vmwareImcConfigFilePath)
conf = Config(cf)
(md, ud, cfg) = read_vmware_imc(conf)
+ dirpath = os.path.dirname(vmwareImcConfigFilePath)
+ nics = get_nics_to_enable(dirpath)
except Exception as e:
LOG.debug("Error parsing the customization Config File")
LOG.exception(e)
@@ -128,6 +134,7 @@ class DataSourceOVF(sources.DataSource):
return False
vmwarePlatformFound = True
+ enable_nics(nics)
set_customization_status(
GuestCustStateEnum.GUESTCUST_STATE_DONE,
GuestCustErrorEnum.GUESTCUST_ERROR_SUCCESS)
diff --git a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
index 2466a47e..b8c58f1e 100644
--- a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
+++ b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
@@ -19,14 +19,20 @@
import logging
import os
+import time
from cloudinit import util
+from .guestcust_state import GuestCustStateEnum
+from .guestcust_error import GuestCustErrorEnum
+from .guestcust_event import GuestCustEventEnum
logger = logging.getLogger(__name__)
CLOUDINIT_LOG_FILE = "/var/log/cloud-init.log"
+QUERY_NICS_SUPPORTED = "queryNicsSupported"
+NICS_STATUS_CONNECTED = "connected"
# This will send a RPC command to the underlying
@@ -35,17 +41,20 @@ def send_rpc(rpc):
if not rpc:
return None
- rc = 1
- output = "Error sending the RPC command"
+ out = ""
+ err = "Error sending the RPC command"
try:
logger.debug("Sending RPC command: %s", rpc)
- (rc, output) = util.subp(["vmware-rpctool", rpc], rcs=[0])
+ (out, err) = util.subp(["vmware-rpctool", rpc], rcs=[0])
+ # Remove the trailing newline in the output.
+ if out:
+ out = out.rstrip()
except Exception as e:
logger.debug("Failed to send RPC command")
logger.exception(e)
- return (rc, output)
+ return (out, err)
# This will send the customization status to the
@@ -59,7 +68,8 @@ def set_customization_status(custstate, custerror, errormessage=None):
message = CLOUDINIT_LOG_FILE
rpc = "deployPkg.update.state %d %d %s" % (custstate, custerror, message)
- (rc, output) = send_rpc(rpc)
+ (out, err) = send_rpc(rpc)
+ return (out, err)
# This will read the file nics.txt in the specified directory
@@ -77,3 +87,43 @@ def get_nics_to_enable(dirpath):
nics = fp.read(NICS_SIZE)
return nics
+
+
+# This will send a RPC command to the underlying VMware Virtualization platform
+# and enable nics.
+def enable_nics(nics):
+ if not nics:
+ logger.warning("No Nics found")
+ return
+
+ enableNicsWaitRetries = 5
+ enableNicsWaitCount = 5
+ enableNicsWaitSeconds = 1
+
+ for attempt in range(0, enableNicsWaitRetries):
+ logger.debug("Trying to connect interfaces, attempt %d", attempt)
+ (out, err) = set_customization_status(
+ GuestCustStateEnum.GUESTCUST_STATE_RUNNING,
+ GuestCustEventEnum.GUESTCUST_EVENT_ENABLE_NICS,
+ nics)
+ if not out:
+ time.sleep(enableNicsWaitCount * enableNicsWaitSeconds)
+ continue
+
+ if out != QUERY_NICS_SUPPORTED:
+ logger.warning("NICS connection status query is not supported")
+ return
+
+ for count in range(0, enableNicsWaitCount):
+ (out, err) = set_customization_status(
+ GuestCustStateEnum.GUESTCUST_STATE_RUNNING,
+ GuestCustEventEnum.GUESTCUST_EVENT_QUERY_NICS,
+ nics)
+ if out and out == NICS_STATUS_CONNECTED:
+ logger.info("NICS are connected on %d second", count)
+ return
+
+ time.sleep(enableNicsWaitSeconds)
+
+ logger.warning("Can't connect network interfaces after %d attempts",
+ enableNicsWaitRetries)