Esempio n. 1
0
    def run(self, tmp=None, task_vars=None):
        super().run(tmp, task_vars)
        service = self._task.args.get('service', None)
        if service:
            msg = 'You can delete service by name only in cluster context'
            cluster_id = get_object_id_from_context(task_vars,
                                                    'cluster_id',
                                                    'cluster',
                                                    err_msg=msg)
            log.info('ansible module adcm_delete_service: service "%s"',
                     service)
            try:
                cm.api.delete_service_by_name(service, cluster_id)
            except AdcmEx as e:
                raise AnsibleError(e.code + ":" + e.msg) from e
        else:
            msg = 'You can delete service only in service context'
            service_id = get_object_id_from_context(task_vars,
                                                    'service_id',
                                                    'service',
                                                    err_msg=msg)
            log.info('ansible module adcm_delete_service: service #%s',
                     service_id)
            try:
                cm.api.delete_service_by_id(service_id)
            except AdcmEx as e:
                raise AnsibleError(e.code + ":" + e.msg) from e

        return {"failed": False, "changed": True}
Esempio n. 2
0
    def run(self, tmp=None, task_vars=None):
        super().run(tmp, task_vars)
        msg = 'You can modify hc only in cluster or service context'
        cluster_id = get_object_id_from_context(task_vars,
                                                'cluster_id',
                                                'cluster',
                                                'service',
                                                err_msg=msg)
        job_id = task_vars['job']['id']
        ops = self._task.args['operations']

        log.info('ansible module adcm_hc: cluster #%s, ops: %s', cluster_id,
                 ops)

        if not isinstance(ops, list):
            raise AnsibleError('Operations should be an array: %s' % ops)

        for op in ops:
            if not isinstance(op, dict):
                raise AnsibleError(
                    'Operation items should be a dictionary: %s' % op)
            args = frozenset(op.keys())
            if args.difference(self._VALID_SUB_ARGS):
                raise AnsibleError('Invalid operation arguments: %s' % op)

        try:
            cm.api.change_hc(job_id, cluster_id, ops)
        except AdcmEx as e:
            raise AnsibleError(e.code + ": " + e.msg) from e

        return {"failed": False, "changed": True}
Esempio n. 3
0
    def run(self, tmp=None, task_vars=None):
        super().run(tmp, task_vars)
        msg = 'You can delete host only in host context'
        host_id = get_object_id_from_context(task_vars,
                                             'host_id',
                                             'host',
                                             err_msg=msg)
        log.info('ansible module adcm_delete_host: host #%s', host_id)

        try:
            cm.api.delete_host_by_id(host_id)
        except AdcmEx as e:
            raise AnsibleError(e.code + ":" + e.msg) from e

        return {"failed": False, "changed": True}
Esempio n. 4
0
    def run(self, tmp=None, task_vars=None):
        super().run(tmp, task_vars)
        msg = 'You can add host only in cluster or service context'
        cluster_id = get_object_id_from_context(task_vars,
                                                'cluster_id',
                                                'cluster',
                                                'service',
                                                err_msg=msg)
        fqdn = self._task.args.get('fqdn', None)
        host_id = self._task.args.get('host_id', None)

        log.info('ansible module: cluster_id %s, fqdn %s, host_id: %s',
                 cluster_id, fqdn, host_id)
        try:
            cm.api.add_host_to_cluster_by_id(cluster_id, fqdn, host_id)
        except AdcmEx as e:
            raise AnsibleError(e.code + ": " + e.msg) from e

        return {"failed": False, "changed": True}
Esempio n. 5
0
    def run(self, tmp=None, task_vars=None):
        super().run(tmp, task_vars)
        msg = 'You can add host only in host provider context'
        provider_id = get_object_id_from_context(task_vars, 'provider_id', 'provider', err_msg=msg)

        if 'fqdn' not in self._task.args:
            raise AnsibleError("fqdn is mandatory args of adcm_add_host")
        fqdn = self._task.args['fqdn']
        desc = ''
        if 'description' in self._task.args:
            desc = self._task.args['description']

        log.info('ansible module adcm_add_host: provider %s, fqdn %s', provider_id, fqdn)

        try:
            host = cm.api.add_provider_host(provider_id, fqdn, desc)
        except AdcmEx as e:
            raise AnsibleError(e.code + ":" + e.msg) from e

        return {"failed": False, "changed": True, "host_id": host.id}