diff options
| author | Sankar Tanguturi <stanguturi@stanguturi-rhel> | 2016-03-09 16:02:34 -0800 | 
|---|---|---|
| committer | Sankar Tanguturi <stanguturi@stanguturi-rhel> | 2016-03-09 16:02:34 -0800 | 
| commit | a6e0922a4d34ede6df000dd8fc4bb3531218d69f (patch) | |
| tree | 0422066e5342e365d7ab8102857fa301c659b50c /cloudinit/sources/helpers | |
| parent | ef7368ef61c47fbb0bc03e6e7a5bc4571d492baf (diff) | |
| download | vyos-cloud-init-a6e0922a4d34ede6df000dd8fc4bb3531218d69f.tar.gz vyos-cloud-init-a6e0922a4d34ede6df000dd8fc4bb3531218d69f.zip | |
 - Fixed few issues with return values form util.subp()
 - Added a new utility method to send a RPC for enabling NICS
 - Modified DataSourceOVF.py to enable nics.
 - Executed ./tools/run-pep8 and no issues were reported.
Diffstat (limited to 'cloudinit/sources/helpers')
| -rw-r--r-- | cloudinit/sources/helpers/vmware/imc/guestcust_util.py | 60 | 
1 files changed, 55 insertions, 5 deletions
| 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)
 | 
