# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2010 Citrix Systems, Inc.
# Copyright 2010-2012 OpenStack Foundation
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import base64
import binascii
import os
import time
import uuid

from oslo.config import cfg

from nova.api.metadata import password
from nova.compute import api as compute_api
from nova import context
from nova import crypto
from nova import exception
from nova.openstack.common.gettextutils import _
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
from nova.openstack.common import strutils
from nova import utils


USE_AGENT_KEY = "xenapi_use_agent"
USE_AGENT_SM_KEY = compute_api.SM_IMAGE_PROP_PREFIX + USE_AGENT_KEY

LOG = logging.getLogger(__name__)

xenapi_agent_opts = [
    cfg.IntOpt('agent_timeout',
               default=30,
               help='number of seconds to wait for agent reply'),
    cfg.IntOpt('agent_version_timeout',
               default=300,
               help='number of seconds to wait for agent '
                    'to be fully operational'),
    cfg.IntOpt('agent_resetnetwork_timeout',
               default=60,
               help='number of seconds to wait for agent reply '
                    'to resetnetwork request'),
    cfg.StrOpt('xenapi_agent_path',
               default='usr/sbin/xe-update-networking',
               help='Specifies the path in which the xenapi guest agent '
                    'should be located. If the agent is present, network '
                    'configuration is not injected into the image. '
                    'Used if compute_driver=xenapi.XenAPIDriver and '
                    ' flat_injected=True'),
    cfg.BoolOpt('xenapi_disable_agent',
               default=False,
               help='Disables the use of the XenAPI agent in any image '
                    'regardless of what image properties are present. '),
    cfg.BoolOpt('xenapi_use_agent_default',
               default=False,
               help='Determines if the xenapi agent should be used when '
                    'the image used does not contain a hint to declare if '
                    'the agent is present or not. '
                    'The hint is a glance property "' + USE_AGENT_KEY + '" '
                    'that has the value "true" or "false". '
                    'Note that waiting for the agent when it is not present '
                    'will significantly increase server boot times.'),