# Copyright 2017 Cisco Systems, Inc.
#
# 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.


"""
This module implements all the services
"""
from imcsdk.imcexception import ImcOperationError, ImcValidationException
from imcsdk.imccoreutils import IMC_PLATFORM
from imcsdk.apis.utils import _is_valid_arg


def _get_mgmtif_mo_dn(handle):
    """
    Internal method to get the mgmt_if dn based on the type of platform
    """
    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        return("sys/rack-unit-1/mgmt/if-1")
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        return("sys/chassis-1/if-1")
    else:
        raise ImcValidationException("Invalid platform detected:%s" %
                                     handle.platform)


def _get_mgmtif_mo(handle):
    """
    Internal method to get the mgmt_if mo
    """
    dn = _get_mgmtif_mo_dn(handle)
    mo = handle.query_dn(dn)
    if mo is None:
        raise ImcOperationError("common_prop_configure",
                                "%s does not exist." % dn)
    return mo


def common_prop_configure(handle, hostname=None, ddns_enable=None,
                          ddns_domain=None):
    """
    Configures networking common properties.