示例#1
0
 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)
    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)
 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):
        '''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)
 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)
示例#6
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)
示例#7
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)
 def autosupport_log(self, event_name):
     """
     Create a log event against the provided vserver
     """
     server = netapp_utils.setup_na_ontap_zapi(
         module=self.module, vserver=self.parameters['vserver'])
     netapp_utils.ems_log_event(event_name, server)
示例#9
0
    def apply(self):
        """
        Run Module based on play book
        """
        changed = False
        broadcast_domain_details = self.get_broadcast_domain_ports()
        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_broadcast_domain_ports", cserver)
        if broadcast_domain_details is None:
            self.module.fail_json(msg='Error broadcast domain not found: %s' %
                                  self.broadcast_domain)
        if self.module.check_mode:
            pass
        else:
            if self.state == 'present':  # execute create
                ports_to_add = [
                    port for port in self.ports
                    if port not in broadcast_domain_details['ports']
                ]
                if len(ports_to_add) > 0:
                    changed = self.create_broadcast_domain_ports(ports_to_add)
            elif self.state == 'absent':  # execute delete
                ports_to_delete = [
                    port for port in self.ports
                    if port in broadcast_domain_details['ports']
                ]
                if len(ports_to_delete) > 0:
                    changed = self.delete_broadcast_domain_ports(
                        ports_to_delete)

        self.module.exit_json(changed=changed)
    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)
示例#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)
示例#13
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 autosupport_log(self):
     """
     Autosupport log for job_schedule
     :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_job_schedule", cserver)
def test_ems_log_event_version():
    ''' validate Ansible version is correctly read '''
    source = 'unittest'
    server = MockONTAPConnection()
    netapp_utils.ems_log_event(source, server)
    xml = server.xml_in
    version = xml.get_child_content('app-version')
    assert version == ansible_version
    print("Ansible version: %s" % ansible_version)
示例#16
0
 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)
示例#17
0
 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
 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)
示例#21
0
    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)
    def apply(self):
        '''Apply action to subnet'''
        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_subnet", cserver)
        current = self.get_subnet()
        cd_action, rename = None, None

        if self.parameters.get('from_name'):
            rename = self.na_helper.is_rename_action(
                self.get_subnet(self.parameters.get('from_name')), current)
            if rename is False:
                self.module.fail_json(
                    msg="Error renaming: subnet %s does not exist" %
                    self.parameters.get('from_name'))
        else:
            cd_action = self.na_helper.get_cd_action(current, self.parameters)

        modify = self.na_helper.get_modified_attributes(
            current, self.parameters)
        for attribute in modify:
            if attribute in ['broadcast_domain']:
                self.module.fail_json(
                    msg=
                    'Error modifying subnet %s: cannot modify broadcast_domain parameter.'
                    % self.parameters.get('name'))

        if self.na_helper.changed:
            if self.module.check_mode:
                pass
            else:
                if rename:
                    self.rename_subnet()
                # If rename is True, cd_action is NOne but modify could be true
                if cd_action == 'create':
                    for attribute in ['subnet', 'broadcast_domain']:
                        if not self.parameters.get(attribute):
                            self.module.fail_json(
                                msg='Error - missing required arguments: %s.' %
                                attribute)
                    self.create_subnet()
                elif cd_action == 'delete':
                    self.delete_subnet()
                elif modify:
                    self.modify_subnet()
        self.module.exit_json(changed=self.na_helper.changed)
示例#23
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)
示例#24
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)
示例#25
0
    def apply(self):
        property_changed = False
        size_changed = False
        lun_exists = False
        netapp_utils.ems_log_event("na_ontap_lun", self.server)
        lun_detail = self.get_lun()

        if lun_detail:
            lun_exists = True
            current_size = lun_detail['size']

            if self.state == 'absent':
                property_changed = True

            elif self.state == 'present':
                if not int(current_size) == self.size:
                    size_changed = True
                    property_changed = True

        else:
            if self.state == 'present':
                property_changed = True

        if property_changed:
            if self.module.check_mode:
                pass
            else:
                if self.state == 'present':
                    if not lun_exists:
                        self.create_lun()

                    else:
                        if size_changed:
                            # Ensure that size was actually changed. Please
                            # read notes in 'resize_lun' function for details.
                            size_changed = self.resize_lun()
                            if not size_changed:
                                property_changed = False

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

        changed = property_changed or size_changed
        # TODO: include other details about the lun (size, etc.)
        self.module.exit_json(changed=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)
示例#27
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 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)
    def apply(self):
        '''Call add, delete or modify methods'''
        changed = False
        create_license = False
        remove_license = 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_license", cserver)
        # Add / Update licenses.
        license_status = self.get_licensing_status()

        if self.state == 'absent':  # delete
            changed = True
        else:  # add or update
            if self.license_codes is not None:
                create_license = True
                changed = True
            if self.remove_unused is not None:
                remove_license = True
                changed = True
            if self.remove_expired is not None:
                remove_license = True
                changed = True
        if changed:
            if self.state == 'present':  # execute create
                if create_license:
                    self.add_licenses()
                if self.remove_unused is not None:
                    self.remove_unused_licenses()
                if self.remove_expired is not None:
                    self.remove_expired_licenses()
                if create_license or remove_license:
                    new_license_status = self.get_licensing_status()
                    if local_cmp(license_status, new_license_status) == 0:
                        changed = False
            else:  # execute delete
                license_deleted = False
                for package in self.license_names:
                    license_deleted |= self.remove_licenses(package)
                    changed = license_deleted

        self.module.exit_json(changed=changed)
示例#30
0
    def apply(self):
        """
        Apply action to SNMP community
        This module is not idempotent:
        Add doesn't fail the playbook if user is trying
        to add an already existing snmp community
        """
        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_snmp", cserver)
        if self.state == 'present':  # add
            if self.add_snmp_community():
                changed = True
        elif self.state == 'absent':  # delete
            if self.delete_snmp_community():
                changed = True

        self.module.exit_json(changed=changed)