def __init__(self, *args, **kwargs):
        KubernetesAnsibleModule.__init__(self,
                                         *args,
                                         argument_spec=STATUS_ARG_SPEC,
                                         supports_check_mode=True,
                                         **kwargs)
        if not HAS_KUBERNETES_COLLECTION:
            self.fail_json(
                msg="The community.kubernetes collection must be installed",
                exception=K8S_COLLECTION_ERROR,
                error=to_native(k8s_collection_import_exception),
            )
        self.kind = self.params.get("kind")
        self.api_version = self.params.get("api_version")
        self.name = self.params.get("name")
        self.namespace = self.params.get("namespace")
        self.force = self.params.get("force")

        self.status = self.params.get("status") or {}
        self.conditions = self.params.get("conditions") or []

        if self.conditions and self.status and self.status.get("conditions"):
            raise ValueError(
                "You cannot specify conditions in both the `status` and `conditions` parameters"
            )

        if self.conditions:
            self.status["conditions"] = self.conditions
Beispiel #2
0
 def __init__(self, *args, **kwargs):
     KubernetesAnsibleModule.__init__(self,
                                      *args,
                                      supports_check_mode=True,
                                      **kwargs)
     if self._name == 'k8s_facts':
         self.deprecate(
             "The 'k8s_facts' module has been renamed to 'k8s_info'",
             version='2.13')
Beispiel #3
0
    def __init__(self, k8s_kind=None, *args, **kwargs):
        self.client = None
        self.warnings = []

        mutually_exclusive = [
            ('resource_definition', 'src'),
        ]

        KubernetesAnsibleModule.__init__(self,
                                         *args,
                                         mutually_exclusive=mutually_exclusive,
                                         supports_check_mode=True,
                                         **kwargs)
        self.kind = k8s_kind or self.params.get('kind')
        self.api_version = self.params.get('api_version')
        self.name = self.params.get('name')
        self.namespace = self.params.get('namespace')
        resource_definition = self.params.get('resource_definition')

        if resource_definition:
            if isinstance(resource_definition, string_types):
                try:
                    self.resource_definitions = yaml.safe_load_all(
                        resource_definition)
                except (IOError, yaml.YAMLError) as exc:
                    self.fail(msg="Error loading resource_definition: {0}".
                              format(exc))
            elif isinstance(resource_definition, list):
                self.resource_definitions = resource_definition
            else:
                self.resource_definitions = [resource_definition]
        src = self.params.get('src')
        if src:
            self.resource_definitions = self.load_resource_definitions(src)

        if not resource_definition and not src:
            implicit_definition = dict(kind=self.kind,
                                       apiVersion=self.api_version,
                                       metadata=dict(name=self.name))
            if self.namespace:
                implicit_definition['metadata']['namespace'] = self.namespace
            self.resource_definitions = [implicit_definition]
Beispiel #4
0
    def __init__(self, k8s_kind=None, *args, **kwargs):
        self.client = None
        self.warnings = []

        mutually_exclusive = [
            ('resource_definition', 'src'),
            ('merge_type', 'apply'),
        ]

        KubernetesAnsibleModule.__init__(self,
                                         *args,
                                         mutually_exclusive=mutually_exclusive,
                                         supports_check_mode=True,
                                         **kwargs)
        self.kind = k8s_kind or self.params.get('kind')
        self.api_version = self.params.get('api_version')
        self.name = self.params.get('name')
        self.namespace = self.params.get('namespace')
        resource_definition = self.params.get('resource_definition')
        validate = self.params.get('validate')
        if validate:
            if LooseVersion(self.openshift_version) < LooseVersion("0.8.0"):
                self.fail_json(
                    msg="openshift >= 0.8.0 is required for validate")
        self.append_hash = self.params.get('append_hash')
        if self.append_hash:
            if not HAS_K8S_CONFIG_HASH:
                self.fail_json(msg=missing_required_lib(
                    "openshift >= 0.7.2", reason="for append_hash"),
                               exception=K8S_CONFIG_HASH_IMP_ERR)
        if self.params['merge_type']:
            if LooseVersion(self.openshift_version) < LooseVersion("0.6.2"):
                self.fail_json(msg=missing_required_lib(
                    "openshift >= 0.6.2", reason="for merge_type"))
        self.apply = self.params.get('apply', False)
        if self.apply:
            if not HAS_K8S_APPLY:
                self.fail_json(msg=missing_required_lib("openshift >= 0.9.2",
                                                        reason="for apply"))

        if resource_definition:
            if isinstance(resource_definition, string_types):
                try:
                    self.resource_definitions = yaml.safe_load_all(
                        resource_definition)
                except (IOError, yaml.YAMLError) as exc:
                    self.fail(msg="Error loading resource_definition: {0}".
                              format(exc))
            elif isinstance(resource_definition, list):
                self.resource_definitions = resource_definition
            else:
                self.resource_definitions = [resource_definition]
        src = self.params.get('src')
        if src:
            self.resource_definitions = self.load_resource_definitions(src)
        try:
            self.resource_definitions = [
                item for item in self.resource_definitions if item
            ]
        except AttributeError:
            pass

        if not resource_definition and not src:
            implicit_definition = dict(kind=self.kind,
                                       apiVersion=self.api_version,
                                       metadata=dict(name=self.name))
            if self.namespace:
                implicit_definition['metadata']['namespace'] = self.namespace
            self.resource_definitions = [implicit_definition]
 def __init__(self, *args, **kwargs):
     KubernetesAnsibleModule.__init__(self,
                                      *args,
                                      supports_check_mode=True,
                                      **kwargs)