예제 #1
0
 def apply(self):
     '''Call create/delete/modify/rename operations'''
     netapp_utils.ems_log_event("na_ontap_qtree", self.server)
     current = self.get_qtree()
     rename, cd_action, modify = None, None, None
     if self.parameters.get('from_name'):
         rename = self.na_helper.is_rename_action(
             self.get_qtree(self.parameters['from_name']), current)
     else:
         cd_action = self.na_helper.get_cd_action(current, self.parameters)
     if cd_action is None and self.parameters['state'] == 'present':
         modify = self.na_helper.get_modified_attributes(
             current, self.parameters)
     if self.na_helper.changed:
         if self.module.check_mode:
             pass
         else:
             if rename:
                 self.rename_qtree()
             if cd_action == 'create':
                 self.create_qtree()
             elif cd_action == 'delete':
                 self.delete_qtree()
             elif modify:
                 self.modify_qtree()
     self.module.exit_json(changed=self.na_helper.changed)
 def apply(self):
     results = netapp_utils.get_cserver(self.server)
     cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
     netapp_utils.ems_log_event("na_ontap_fcp", cserver)
     exists = self.get_fcp()
     changed = False
     if self.parameters['state'] == 'present':
         if exists:
             if self.parameters['status'] == 'up':
                 if not self.current_status():
                     self.start_fcp()
                     changed = True
             else:
                 if self.current_status():
                     self.stop_fcp()
                     changed = True
         else:
             self.create_fcp()
             if self.parameters['status'] == 'up':
                 self.start_fcp()
             elif self.parameters['status'] == 'down':
                 self.stop_fcp()
             changed = True
     else:
         if exists:
             if self.current_status():
                 self.stop_fcp()
             self.destroy_fcp()
             changed = True
     self.module.exit_json(changed=changed)
예제 #3
0
    def apply(self):
        """
        Apply action to cifs-share-access-control
        """
        changed = False
        cifs_acl_exists = False
        netapp_utils.ems_log_event("na_ontap_cifs_acl", self.server)
        cifs_acl_details = self.get_cifs_acl()
        if cifs_acl_details:
            cifs_acl_exists = True
            if self.state == 'absent':  # delete
                changed = True
            elif self.state == 'present':
                if cifs_acl_details['permission'] != self.permission:  # rename
                    changed = True
        else:
            if self.state == 'present':  # create
                changed = True
        if changed:
            if self.module.check_mode:
                pass
            else:
                if self.state == 'present':  # execute create
                    if not cifs_acl_exists:
                        self.create_cifs_acl()
                    else:  # execute modify
                        self.modify_cifs_acl_permission()
                elif self.state == 'absent':  # execute delete
                    self.delete_cifs_acl()

        self.module.exit_json(changed=changed)
 def apply(self):
     """
     Apply action to quotas
     """
     netapp_utils.ems_log_event("na_ontap_quotas", self.server)
     modify_quota_status = None
     modify_quota = None
     current = self.get_quotas()
     if 'set_quota_status' in self.parameters:
         quota_status = self.get_quota_status()
         if quota_status is not None:
             quota_status_action = self.na_helper.get_modified_attributes(
                 {'set_quota_status': True if quota_status == 'on' else False}, self.parameters)
             if quota_status_action:
                 modify_quota_status = 'quota-on' if quota_status_action['set_quota_status'] else 'quota-off'
     cd_action = self.na_helper.get_cd_action(current, self.parameters)
     if cd_action is None:
         modify_quota = self.na_helper.get_modified_attributes(current, self.parameters)
     if self.na_helper.changed:
         if self.module.check_mode:
             pass
         else:
             if cd_action == 'create':
                 self.quota_entry_set()
             elif cd_action == 'delete':
                 self.quota_entry_delete()
             elif modify_quota is not None:
                 for key in list(modify_quota):
                     modify_quota[key.replace("_", "-")] = modify_quota.pop(key)
                 self.quota_entry_modify(modify_quota)
             if modify_quota_status is not None:
                 self.on_or_off_quota(modify_quota_status)
     self.module.exit_json(changed=self.na_helper.changed)
예제 #5
0
    def apply(self):
        """Apply action to ntp-server"""

        changed = False
        ntp_modify = False
        results = netapp_utils.get_cserver(self.server)
        cserver = netapp_utils.setup_na_ontap_zapi(
            module=self.module, vserver=results)
        netapp_utils.ems_log_event("na_ontap_ntp", cserver)
        ntp_server_details = self.get_ntp_server()
        if ntp_server_details is not None:
            if self.state == 'absent':  # delete
                changed = True
            elif self.state == 'present' and self.version:
                # modify version
                if self.version != ntp_server_details['version']:
                    ntp_modify = True
                    changed = True
        else:
            if self.state == 'present':  # create
                changed = True

        if changed:
            if self.module.check_mode:
                pass
            else:
                if self.state == 'present':
                    if ntp_server_details is None:
                        self.create_ntp_server()
                    elif ntp_modify:
                        self.modify_version()
                elif self.state == 'absent':
                    self.delete_ntp_server()

        self.module.exit_json(changed=changed)
예제 #6
0
 def apply(self):
     """
     Check to see which play we should run
     """
     current = self.get_snapshot()
     netapp_utils.ems_log_event("na_ontap_snapshot", self.server)
     rename, cd_action = None, None
     modify = {}
     if self.parameters.get('from_name'):
         current_old_name = self.get_snapshot(self.parameters['from_name'])
         rename = self.na_helper.is_rename_action(current_old_name, current)
         modify = self.na_helper.get_modified_attributes(
             current_old_name, self.parameters)
     else:
         cd_action = self.na_helper.get_cd_action(current, self.parameters)
         if cd_action is None:
             modify = self.na_helper.get_modified_attributes(
                 current, self.parameters)
     if self.na_helper.changed:
         if self.module.check_mode:
             pass
         else:
             if rename:
                 self.rename_snapshot()
             if cd_action == 'create':
                 self.create_snapshot()
             elif cd_action == 'delete':
                 self.delete_snapshot()
             elif modify:
                 self.modify_snapshot()
     self.module.exit_json(changed=self.na_helper.changed)
예제 #7
0
    def apply(self):
        """
        Apply action to NVMe service
        """
        netapp_utils.ems_log_event("na_ontap_nvme", self.server)
        current = self.get_nvme()
        cd_action = self.na_helper.get_cd_action(current, self.parameters)
        if self.parameters.get('status_admin') is not None:
            self.parameters[
                'status_admin'] = self.na_helper.get_value_for_bool(
                    False, self.parameters['status_admin'])
            if cd_action is None and self.parameters['state'] == 'present':
                modify = self.na_helper.get_modified_attributes(
                    current, self.parameters)
        if self.na_helper.changed:
            if self.module.check_mode:
                pass
            else:
                if cd_action == 'create':
                    self.create_nvme()
                elif cd_action == 'delete':
                    # NVMe status_admin needs to be down before deleting it
                    self.modify_nvme('false')
                    self.delete_nvme()
                elif modify:
                    self.modify_nvme()

        self.module.exit_json(changed=self.na_helper.changed)
예제 #8
0
 def apply(self):
     """
     check the option in the playbook to see what needs to be done
     :return:
     """
     changed = False
     result = None
     results = netapp_utils.get_cserver(self.server)
     cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
     netapp_utils.ems_log_event("na_ontap_net_vlan", cserver)
     existing_vlan = self.does_vlan_exist()
     if existing_vlan:
         if self.state == 'absent':  # delete
             changed = True
     else:
         if self.state == 'present':  # create
             changed = True
     if changed:
         if self.module.check_mode:
             pass
         else:
             if self.state == 'present':
                 self.create_vlan()
             elif self.state == 'absent':
                 self.delete_vlan()
     self.module.exit_json(changed=changed, meta=result)
    def apply(self):
        '''Apply action to disks'''
        changed = False
        results = netapp_utils.get_cserver(self.server)
        cserver = netapp_utils.setup_na_ontap_zapi(module=self.module,
                                                   vserver=results)
        netapp_utils.ems_log_event("na_ontap_disks", cserver)

        # check if anything needs to be changed (add/delete/update)
        unowned_disks = self.get_unassigned_disk_count()
        owned_disks = self.get_owned_disk_count()
        if 'disk_count' in self.parameters:
            if self.parameters['disk_count'] < owned_disks:
                self.module.fail_json(
                    msg="Fewer disks than are currently owned was requested. "
                    "This module does not do any disk removing. "
                    "All disk removing will need to be done manually.")
            if self.parameters['disk_count'] > owned_disks + unowned_disks:
                self.module.fail_json(
                    msg="Not enough unowned disks remain to fulfill request")
        if unowned_disks >= 1:
            if 'disk_count' in self.parameters:
                if self.parameters['disk_count'] > owned_disks:
                    needed_disks = self.parameters['disk_count'] - owned_disks
                    self.disk_assign(needed_disks)
                    changed = True
            else:
                self.disk_assign(0)
                changed = True
        self.module.exit_json(changed=changed)
예제 #10
0
 def apply(self):
     """
     Apply action to export-policy
     """
     changed = False
     export_policy_exists = False
     netapp_utils.ems_log_event("na_ontap_export_policy", self.server)
     rename_flag = False
     export_policy_details = self.get_export_policy()
     if export_policy_details:
         export_policy_exists = True
         if self.state == 'absent':  # delete
             changed = True
     else:
         if self.state == 'present':  # create or rename
             if self.from_name is not None:
                 if self.get_export_policy(self.from_name):
                     changed = True
                     rename_flag = True
                 else:
                     self.module.fail_json(msg='Error renaming export-policy %s: does not exists' % self.from_name)
             else:  # create
                 changed = True
     if changed:
         if self.module.check_mode:
             pass
         else:
             if self.state == 'present':  # execute create or rename_export_policy
                 if rename_flag:
                     self.rename_export_policy()
                 else:
                     self.create_export_policy()
             elif self.state == 'absent':  # execute delete
                 self.delete_export_policy()
     self.module.exit_json(changed=changed)
예제 #11
0
 def apply(self):
     changed = False
     netapp_utils.ems_log_event("na_ontap_svm_options", self.server)
     is_set = self.is_option_set()
     if not is_set:
         self.set_options()
         changed = True
     self.module.exit_json(changed=changed)
 def asup_log_for_cserver(self, event_name):
     """
     Fetch admin vserver for the given cluster
     Create and Autosupport log event with the given module name
     :param event_name: Name of the event log
     :return: None
     """
     netapp_utils.ems_log_event(event_name, self.server)
 def autosupport_log(self):
     """
     AutoSupport log for na_ontap_net_port
     :return: None
     """
     results = netapp_utils.get_cserver(self.server)
     cserver = netapp_utils.setup_na_ontap_zapi(module=self.module,
                                                vserver=results)
     netapp_utils.ems_log_event("na_ontap_net_port", cserver)
예제 #14
0
 def autosupport_log(self):
     """
     Autosupport log for software_update
     :return:
     """
     results = netapp_utils.get_cserver(self.server)
     cserver = netapp_utils.setup_na_ontap_zapi(module=self.module,
                                                vserver=results)
     netapp_utils.ems_log_event("na_ontap_software_update", cserver)
 def asup_log_for_cserver(self, event_name):
     """
     Fetch admin vserver for the given cluster
     Create and Autosupport log event with the given module name
     :param event_name: Name of the event log
     :return: None
     """
     results = netapp_utils.get_cserver(self.server)
     cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
     netapp_utils.ems_log_event(event_name, cserver)
 def asup_log(self):
     if self.use_rest:
         # TODO: logging for Rest
         return
     else:
         # Either we are using ZAPI, or REST failed when it should not
         try:
             netapp_utils.ems_log_event("na_ontap_vscan", self.server)
         except Exception:
             # TODO: we may fail to connect to REST or ZAPI, the line below shows REST issues only
             # self.module.fail_json(msg=repr(self.restApi.errors), log=repr(self.restApi.debug_logs))
             pass
예제 #17
0
 def apply(self):
     """
     Apply action to FlexCache
     """
     netapp_utils.ems_log_event("na_ontap_flexcache", self.server)
     current = self.flexcache_get()
     cd_action = self.na_helper.get_cd_action(current, self.parameters)
     if cd_action == 'create':
         self.check_parameters()
         self.flexcache_create()
     elif cd_action == 'delete':
         self.flexcache_delete()
     self.module.exit_json(changed=self.na_helper.changed)
 def apply(self):
     """
     Run Module based on play book
     """
     netapp_utils.ems_log_event("na_ontap_volume_clone", self.server)
     current = self.get_volume_clone()
     cd_action = self.na_helper.get_cd_action(current, self.parameters)
     if self.na_helper.changed:
         if self.module.check_mode:
             pass
         else:
             if cd_action == 'create':
                 self.create_volume_clone()
     self.module.exit_json(changed=self.na_helper.changed)
    def apply(self):

        netapp_utils.ems_log_event("na_ontap_lun_copy", self.server)
        if self.get_lun():  # lun already exists at destination
            changed = False
        else:
            changed = True
            if self.module.check_mode:
                pass
            else:
                # need to copy lun
                if self.parameters['state'] == 'present':
                    self.copy_lun()

        self.module.exit_json(changed=changed)
    def apply(self):
        """
        Apply action to cluster HA
        """
        results = netapp_utils.get_cserver(self.server)
        cserver = netapp_utils.setup_na_ontap_zapi(module=self.module,
                                                   vserver=results)
        netapp_utils.ems_log_event("na_ontap_cluster_ha", cserver)
        current = self.get_cluster_ha_enabled()
        cd_action = self.na_helper.get_cd_action(current, self.parameters)
        if cd_action == 'create':
            self.modify_cluster_ha("true")
        elif cd_action == 'delete':
            self.modify_cluster_ha("false")

        self.module.exit_json(changed=self.na_helper.changed)
예제 #21
0
    def apply(self):
        create_delete_decision = {}
        modify_decision = {}

        netapp_utils.ems_log_event("na_ontap_user", self.server)
        for application in self.parameters['applications']:
            current = self.get_user(application)
            if current is not None:
                current['lock_user'] = self.na_helper.get_value_for_bool(True, current['lock_user'])

            cd_action = self.na_helper.get_cd_action(current, self.parameters)

            if cd_action is not None:
                create_delete_decision[application] = cd_action
            else:
                modify_decision[application] = self.na_helper.get_modified_attributes(current, self.parameters)

        if not create_delete_decision and self.parameters.get('state') == 'present':
            if self.parameters.get('set_password') is not None:
                self.na_helper.changed = True

        if self.na_helper.changed:

            if self.module.check_mode:
                pass
            else:
                for application in create_delete_decision:
                    if create_delete_decision[application] == 'create':
                        self.create_user(application)
                    elif create_delete_decision[application] == 'delete':
                        self.delete_user(application)
                lock_user = False
                for application in modify_decision:
                    if 'role_name' in modify_decision[application]:
                        self.modify_user(application)
                    if 'lock_user' in modify_decision[application]:
                        lock_user = True

                if lock_user:
                    if self.parameters.get('lock_user'):
                        self.lock_given_user()
                    else:
                        self.unlock_given_user()
                if not create_delete_decision and self.parameters.get('set_password') is not None:
                    # if change password return false nothing has changed so we need to set changed to False
                    self.na_helper.changed = self.change_password()
        self.module.exit_json(changed=self.na_helper.changed)
예제 #22
0
 def apply(self):
     # asup logging
     if not self.use_rest:
         netapp_utils.ems_log_event("na_ontap_dns", self.server)
     dns_attrs = self.get_dns()
     changed = False
     if self.parameters['state'] == 'present':
         if dns_attrs is not None:
             changed = self.modify_dns(dns_attrs)
         else:
             self.create_dns()
             changed = True
     else:
         if dns_attrs is not None:
             self.destroy_dns(dns_attrs)
             changed = True
     self.module.exit_json(changed=changed)
예제 #23
0
    def apply(self):
        """
        Apply action to NVME Namespace
        """
        netapp_utils.ems_log_event("na_ontap_nvme_namespace", self.server)
        current = self.get_namespace()
        cd_action = self.na_helper.get_cd_action(current, self.parameters)
        if self.na_helper.changed:
            if self.module.check_mode:
                pass
            else:
                if cd_action == 'create':
                    self.create_namespace()
                elif cd_action == 'delete':
                    self.delete_namespace()

        self.module.exit_json(changed=self.na_helper.changed)
    def apply(self):
        """
        calling all cifs_server features
        """

        changed = False
        cifs_server_exists = False
        netapp_utils.ems_log_event("na_ontap_cifs_server", self.server)
        cifs_server_detail = self.get_cifs_server()

        if cifs_server_detail:
            cifs_server_exists = True

            if self.state == 'present':
                administrative_status = cifs_server_detail[
                    'administrative-status']
                if self.service_state == 'started' and administrative_status == 'down':
                    changed = True
                if self.service_state == 'stopped' and administrative_status == 'up':
                    changed = True
            else:
                # we will delete the CIFs server
                changed = True
        else:
            if self.state == 'present':
                changed = True

        if changed:
            if self.module.check_mode:
                pass
            else:
                if self.state == 'present':
                    if not cifs_server_exists:
                        self.create_cifs_server()

                    elif self.service_state == 'stopped':
                        self.stop_cifs_server()

                    elif self.service_state == 'started':
                        self.start_cifs_server()

                elif self.state == 'absent':
                    self.delete_cifs_server()

        self.module.exit_json(changed=changed)
예제 #25
0
    def apply(self):
        netapp_utils.ems_log_event("na_ontap_lun_map", self.server)
        lun_details = self.get_lun()
        lun_map_details = self.get_lun_map()

        if self.state == 'present' and lun_details:
            self.result.update(lun_details)

        if self.state == 'present' and not lun_map_details:
            self.result['changed'] = True
            if not self.module.check_mode:
                self.create_lun_map()
        elif self.state == 'absent' and lun_map_details:
            self.result['changed'] = True
            if not self.module.check_mode:
                self.delete_lun_map()

        self.module.exit_json(**self.result)
    def apply(self):
        """
        Apply action to create/delete or accept vserver peer
        """
        results = netapp_utils.get_cserver(self.server)
        cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
        netapp_utils.ems_log_event("na_ontap_vserver_peer", cserver)
        current = self.vserver_peer_get()
        cd_action = self.na_helper.get_cd_action(current, self.parameters)
        if cd_action == 'create':
            self.vserver_peer_create()
            # accept only if the peer relationship is on a remote cluster
            if self.is_remote_peer():
                self.vserver_peer_accept()
        elif cd_action == 'delete':
            self.vserver_peer_delete()

        self.module.exit_json(changed=self.na_helper.changed)
예제 #27
0
    def apply(self):
        """
        Run Module based on play book
        """
        netapp_utils.ems_log_event("na_ontap_net_routes", self.server)
        current = self.get_net_route()
        modify, cd_action = None, None
        modify_params = {
            'destination': self.parameters.get('from_destination'),
            'gateway': self.parameters.get('from_gateway'),
            'metric': self.parameters.get('from_metric')
        }
        # if any from_* param is present in playbook, check for modify action
        if any(modify_params.values()):
            # destination and gateway combination is unique, and is considered like a id. so modify destination
            # or gateway is considered a rename action. metric is considered an attribute of the route so it is
            # considered as modify.
            if modify_params.get('metric') is not None:
                modify = True
                old_params = current
            else:
                # get parameters that are eligible for modify
                old_params = self.get_net_route(modify_params)
                modify = self.na_helper.is_rename_action(old_params, current)
            if modify is None:
                self.module.fail_json(
                    msg="Error modifying: route %s does not exist" %
                    self.parameters['from_destination'])
        else:
            cd_action = self.na_helper.get_cd_action(current, self.parameters)

        if cd_action == 'create':
            self.create_net_route()
        elif cd_action == 'delete':
            self.delete_net_route()
        elif modify:
            desired = {}
            for key, value in old_params.items():
                desired[key] = value
            for key, value in modify_params.items():
                if value is not None:
                    desired[key] = self.parameters.get(key)
            self.modify_net_route(old_params, desired)
        self.module.exit_json(changed=self.na_helper.changed)
    def apply(self):
        '''Call create/modify/delete operations.'''
        current = self.get_krbrealm()
        cd_action = self.na_helper.get_cd_action(current, self.parameters)
        modify = self.na_helper.get_modified_attributes(current, self.parameters)
        #  create an ems log event for users with auto support turned on
        netapp_utils.ems_log_event("na_ontap_kerberos_realm", self.server)

        if self.na_helper.changed:
            if self.module.check_mode:
                pass
            else:
                if cd_action == 'create':
                    self.create_krbrealm()
                elif cd_action == 'delete':
                    self.delete_krbrealm()
                elif modify:
                    self.modify_krbrealm(modify)
        self.module.exit_json(changed=self.na_helper.changed)
예제 #29
0
    def apply(self):
        # logging ems event
        results = netapp_utils.get_cserver(self.cluster)
        cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
        netapp_utils.ems_log_event("na_ontap_node", cserver)

        exists = self.get_node(self.parameters['name'])
        from_exists = self.get_node(self.parameters['from_name'])
        changed = False
        if exists:
            pass
        else:
            if from_exists:
                self.rename_node()
                changed = True
            else:
                self.module.fail_json(msg='Error renaming node, from_name %s does not exist' % self.parameters['from_name'])

        self.module.exit_json(changed=changed)
 def apply(self):
     '''Apply action to cifs share'''
     netapp_utils.ems_log_event("na_ontap_cifs", self.server)
     current = self.get_cifs_share()
     cd_action = self.na_helper.get_cd_action(current, self.parameters)
     if cd_action is None:
         modify = self.na_helper.get_modified_attributes(
             current, self.parameters)
     if self.na_helper.changed:
         if self.module.check_mode:
             pass
         else:
             if cd_action == 'create':
                 self.create_cifs_share()
             elif cd_action == 'delete':
                 self.delete_cifs_share()
             elif modify:
                 self.modify_cifs_share()
     self.module.exit_json(changed=self.na_helper.changed)