def perform_module_operation(self):
        '''
        Perform different actions on host group based on user parameter
        choosen in playbook
        '''
        state = self.module.params['state']
        host_state = self.module.params['host_state']
        hostgroup_name = self.module.params['hostgroup_name']
        hosts = self.module.params['hosts']
        new_name = self.module.params['new_name']
        host_flags = self.module.params['host_flags']

        hostgroup = self.get_hostgroup(hostgroup_name)
        changed = False

        if (state == 'present' and not hostgroup and hostgroup_name):
            LOG.info('Creating host group {0}'.format(hostgroup_name))
            changed = self.create_hostgroup(hostgroup_name)

        if (state == 'present' and host_state == 'present-in-group'
                and hostgroup and hosts and len(hosts) > 0):
            LOG.info('Add hosts to host group {0}'.format(hostgroup_name))
            changed = self.add_hosts_to_hostgroup(hostgroup_name,
                                                  hosts) or changed

        if (state == 'present' and host_state == 'absent-in-group'
                and hostgroup and hosts and len(hosts) > 0):
            LOG.info('Remove hosts from host group {0}'.format(hostgroup_name))
            changed = self.remove_hosts_from_hostgroup(hostgroup_name,
                                                       hosts) or changed

        if (state == 'present' and hostgroup and host_flags):
            LOG.info(
                'Modifying host group flags of hostgroup {0} to {1}'.format(
                    hostgroup_name, host_flags))
            changed = (self.modify_host_flags(hostgroup_name, host_flags)
                       or changed)

        if (state == 'present' and hostgroup and new_name):
            if hostgroup['hostGroupId'] != new_name:
                LOG.info('Renaming host group {0} to {1}'.format(
                    hostgroup_name, new_name))
                changed = self.rename_hostgroup(hostgroup_name, new_name)
                self.module.params['hostgroup_name'] = new_name

        if (state == 'absent' and hostgroup):
            LOG.info('Delete host group {0} '.format(hostgroup_name))
            changed = self.delete_hostgroup(hostgroup_name) or changed

        self._create_result_dict(changed)
        # Update the module's final state
        LOG.info('changed {0}'.format(changed))
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
Пример #2
0
    def perform_module_operation(self):
        '''
        Perform different actions on host based on user parameter
        chosen in playbook
        '''
        state = self.module.params['state']
        intiator_state = self.module.params['initiator_state']
        host_name = self.module.params['host_name']
        initiators = self.module.params['initiators']
        new_name = self.module.params['new_name']
        host_flags = self.module.params['host_flags']

        host = self.get_host(host_name)
        changed = False

        if state == 'present' and not host and host_name:
            LOG.info('Creating host {0}'.format(host_name))
            changed = self.create_host(host_name)

        if (state == 'present' and host and intiator_state == 'present-in-host'
                and initiators and len(initiators) > 0):
            LOG.info('Adding initiators to host {0}'.format(host_name))
            changed = (self.add_host_initiators(host_name, initiators)
                       or changed)

        if (state == 'present' and host and intiator_state == 'absent-in-host'
                and initiators and len(initiators) > 0):
            LOG.info('Remove initiators from host {0}'.format(host_name))
            changed = (self.remove_host_initiators(host_name, initiators)
                       or changed)

        if state == 'present' and host and host_flags:
            LOG.info('Modifying host flags of host {0} to {1}'.format(
                host_name, host_flags))
            changed = self.modify_host_flags(host_name, host_flags) or changed

        if state == 'present' and host and new_name:
            if host['hostId'] != new_name:
                LOG.info('Renaming host {0} to {1}'.format(
                    host_name, new_name))
                changed = self.rename_host(host_name, new_name)
                if changed is True:
                    self.module.params['host_name'] = new_name

        if state == 'absent' and host:
            LOG.info('Delete host {0} '.format(host_name))
            changed = self.delete_host(host_name) or changed

        self._create_result_dict(changed)
        # Update the module's final state
        LOG.info('changed {0}'.format(changed))
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
 def show_error_exit(self, msg):
     if self.u4v_conn is not None:
         try:
             LOG.info("Closing unisphere connection {0}".format(
                 self.u4v_conn))
             utils.close_connection(self.u4v_conn)
             LOG.info("Connection closed successfully")
         except Exception as e:
             err_msg = "Failed to close unisphere connection with error:" \
                       " {0}".format(str(e))
             LOG.error(err_msg)
     LOG.error(msg)
     self.module.fail_json(msg=msg)
Пример #4
0
    def perform_module_operation(self):
        """
        Perform different actions on port based on user parameter
        chosen in playbook
        """

        changed = False
        self.get_port_details()
        # Finally update the module changed state
        self.result["changed"] = changed
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
Пример #5
0
    def perform_module_operation(self):
        """
        Perform different actions on masking view based on user parameter
        chosen in playbook
        """
        state = self.module.params['state']
        mv_name = self.module.params['mv_name']
        new_mv_name = self.module.params['new_mv_name']

        masking_view = self.get_masking_view(mv_name)
        if masking_view is not None:
            self.is_mv_changed(masking_view)

        result = dict(
            changed=False,
            create_mv='',
            modify_mv='',
            delete_mv='',
        )

        if state == 'present' and not masking_view and not new_mv_name \
                and mv_name:
            LOG.info('Creating masking view {0}'.format(mv_name))
            result['create_mv'], result['mv_details'] = \
                self.create_masking_view(mv_name)

        if state == 'present' and masking_view and new_mv_name:
            LOG.info('Renaming masking view {0}'.format(mv_name))
            result['modify_mv'] = self.rename_masking_view(
                mv_name, new_mv_name)
            mv_name = new_mv_name

        if state == 'absent' and masking_view:
            LOG.info('Delete masking view {0} '.format(mv_name))
            result['delete_mv'] = self.delete_masking_view(mv_name)

        if state == 'present' and masking_view:
            updated_mv = self.get_masking_view(mv_name)
            result['mv_details'] = updated_mv

        if result['create_mv'] or result['modify_mv'] or \
                result['delete_mv']:
            result['changed'] = True

        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")

        # Finally update the module changed state!!!
        self.module.exit_json(**result)
Пример #6
0
    def perform_module_operation(self):
        """
        Perform different actions on port group based on user parameter
        chosen in playbook
        """
        state = self.module.params['state']
        port_state = self.module.params['port_state']
        portgroup_name = self.module.params['portgroup_name']
        new_name = self.module.params['new_name']

        portgroup = self.get_portgroup(portgroup_name)
        changed = False
        if state == 'present' and not portgroup and \
                portgroup_name and not new_name:
            LOG.info('Creating port group {0}'.format(portgroup_name))
            changed = self.create_portgroup(portgroup_name)
        elif state == 'present' and portgroup and new_name:
            LOG.info('Modifying port group {0}'.format(portgroup_name))
            changed_name = self.modify_portgroup(portgroup_name)
            if changed_name:
                portgroup_name = new_name
            changed = changed or changed_name
        if state == 'present' and port_state == 'present-in-group' and \
                portgroup:
            LOG.info('Adding ports to port group {0}'.format(portgroup_name))
            changed = self.add_ports_to_portgroup(portgroup_name) or changed
        elif state == 'present' and port_state == 'absent-in-group' and \
                portgroup:
            LOG.info(
                'Removing ports from port group {0}'.format(portgroup_name))
            changed = self.remove_ports_from_portgroup(
                portgroup_name) or changed
        elif state == 'absent' and portgroup:
            LOG.info('Delete post group {0} '.format(portgroup_name))
            changed = self.delete_portgroup(portgroup_name) or changed
        '''
        Finally update the module changed state and saving updated portgroup
        details
        '''
        self.result["changed"] = changed
        if state == 'absent':
            del self.result["portgroup_details"]
        else:
            self.result["portgroup_details"] = self.get_portgroup(
                portgroup_name)
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
    def perform_module_operation(self):

        rdfgroup_number = self.module.params['rdfgroup_number']

        rdf_group_details = self.get_rdf_group_details(rdfgroup_number)
        rdf_vols_details = self.get_rdf_group_volumes(rdfgroup_number)
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")

        self.module.exit_json(
            changed=False,
            RDFGroupDetails=rdf_group_details,
            RDFGroupVolumes=rdf_vols_details,
            )
Пример #8
0
    def perform_module_operation(self):
        '''
        Perform different actions on srdf_link based on user parameter
        chosen in playbook
        '''
        state = self.module.params['state']
        sg_name = self.module.params['sg_name']
        srdf_mode = self.module.params['srdf_mode']
        srdf_state = self.module.params['srdf_state']
        job_id = self.module.params['job_id']
        changed = False
        remoteSymmetrixIDs = []

        if (job_id and sg_name) or (not job_id and not sg_name):
            errorMsg = 'Please specify either job ID or SG name in one ' \
                       'Ansible task'
            self.show_error_exit(msg=errorMsg)

        if job_id:
            if state == 'present':
                LOG.info('Geting details of the Job %s', job_id)
                self.get_job_details(job_id)
            else:
                errorMsg = 'Set state=present for getting Job status'
                self.show_error_exit(msg=errorMsg)
        else:
            srdf_link = self.get_srdf_link(sg_name)
            self.result['SRDF_link_details'] = srdf_link
            LOG.info('srdf_link details: %s', self.result['SRDF_link_details'])

            self.current_rdfg_no\
                = self.check_for_multiple_rdf_groups(srdf_link)

            if state == 'present':
                if not self.result['SRDF_link_details']:
                    LOG.debug('srdf_link details not found.')
                    changed = self.create_srdf_link()

                # Create 2nd link for Multisite SRDF
                elif self.result['SRDF_link_details']\
                        and self.module.params['remote_serial_no']:
                    LOG.debug('srdf_link details found.')
                    remoteSymmetrixIDcount = len(srdf_link)
                    for id in range(remoteSymmetrixIDcount):
                        remoteSymmetrixIDs.append(
                            self.result['SRDF_link_details'][id]
                            ['remoteSymmetrix'])
                    remote_serial_no = self.module.params['remote_serial_no']
                    if remote_serial_no not in remoteSymmetrixIDs:
                        changed = self.create_srdf_link()

                elif self.result['SRDF_link_details'] \
                        and (srdf_mode or srdf_state):
                    LOG.info('Modifying SRDF mode/state')
                    self.current_rdfg_no\
                        = self.check_for_multiple_rdf_groups(srdf_link, False)
                    for link in self.result['SRDF_link_details']:
                        if link['rdfGroupNumber'] == self.current_rdfg_no:
                            if (srdf_mode != link['modes'][0] and srdf_mode):
                                LOG.info('Modifying SRDF mode from %s to %s',
                                         link['modes'][0], srdf_mode)
                                changed = self.modify_srdf_mode(srdf_mode) \
                                    or changed
                            else:
                                LOG.info('Modification of SRDF state not'
                                         ' required')

                    if srdf_state is not None:
                        changed = self._check_for_SRDF_state_modification(
                            srdf_state) or changed

            elif state == 'absent' and self.result['SRDF_link_details']:
                self.current_rdfg_no\
                    = self.check_for_multiple_rdf_groups(srdf_link, False)
                LOG.info('Deleting srdf_link with SG %s ', sg_name)
                changed = self.delete_srdf_link() or changed

        # Update the module's final state
        LOG.info('changed %s', changed)
        self.result['changed'] = changed
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
    def perform_module_operation(self):
        """ Perform different actions on Gatherfacts based on user parameters
            chosen in playbook """

        serial_no = self.module.params['serial_no']
        if serial_no is '':
            array_list = self.get_array_list()
            self.module.exit_json(Arrays=array_list)
        else:
            subset = self.module.params['gather_subset']
            tdev_volumes = self.module.params['tdev_volumes']
            filters = []
            filters = self.module.params['filters']
            if len(subset) == 0:
                self.show_error_exit(msg="Please specify gather_subset")

            filters_dict = {}
            if filters:
                filters_dict = self.get_filters(filters=filters)

            health_check = []
            vol = []
            srp = []
            sg = []
            pg = []
            host = []
            hg = []
            port = []
            mv = []
            rdf = []
            if 'health' in str(subset):
                health_check = self.get_system_health()
            if 'vol' in str(subset):
                vol = self.get_volume_list(tdev_volumes=tdev_volumes,
                                           filters_dict=filters_dict)
            if 'sg' in str(subset):
                sg = self.get_storage_group_list(filters_dict=filters_dict)
            if 'srp' in str(subset):
                srp = self.get_srp_list(filters_dict=filters_dict)
            if 'pg' in str(subset):
                pg = self.get_portgroup_list(filters_dict=filters_dict)
            if 'host' in str(subset):
                host = self.get_host_list(filters_dict=filters_dict)
            if 'hg' in str(subset):
                hg = self.get_hostgroup_list(filters_dict=filters_dict)
            if 'port' in str(subset):
                port = self.get_port_list(filters_dict=filters_dict)
            if 'mv' in str(subset):
                mv = self.get_masking_view_list(filters_dict=filters_dict)
            if 'rdf' in str(subset):
                rdf = self.get_rdfgroup_list(filters_dict=filters_dict)

            LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
            utils.close_connection(self.u4v_conn)
            LOG.info("Connection closed successfully")

            self.module.exit_json(Health=health_check,
                                  Volumes=vol,
                                  StorageGroups=sg,
                                  StorageResourcePools=srp,
                                  PortGroups=pg,
                                  Hosts=host,
                                  HostGroups=hg,
                                  Ports=port,
                                  MaskingViews=mv,
                                  RDFGroups=rdf)
Пример #10
0
    def perform_module_operation(self):
        """
        Perform different actions on Snapshot based on user parameter
        chosen in playbook
        """

        sg_name = self.module.params['sg_name']
        snapshot_name = self.module.params['snapshot_name']
        ttl = self.module.params['ttl']
        ttl_unit = self.module.params['ttl_unit']
        generation = self.module.params['generation']
        new_snapshot_name = self.module.params['new_snapshot_name']
        target_sg_name = self.module.params['target_sg_name']
        link = self.module.params['link_status']
        state = self.module.params['state']

        result = dict(
            changed=False,
            create_sg_snap='',
            delete_sg_snap='',
            rename_sg_snap='',
            change_snap_link_status='',
        )

        if state == 'present' and ttl and not \
                (new_snapshot_name or link):
            LOG.info('Creating snapshot {0} for storage group {1} '.format(
                snapshot_name, sg_name))
            result['create_sg_snap'], result['sg_snap_details'] = \
                self.create_sg_snapshot(sg_name,
                                        snapshot_name,
                                        ttl,
                                        ttl_unit)
        elif state == 'absent':
            LOG.info(
                'Delete storage group {0} snapshot {1} generation {2} '.format(
                    sg_name, snapshot_name, generation))
            result['delete_sg_snap'] = self.delete_sg_snapshot(
                sg_name, snapshot_name, generation)

        if state == 'present' and snapshot_name \
                and link and target_sg_name:
            LOG.info(
                'Change storage group {0} snapshot {1} link status '.format(
                    sg_name, snapshot_name))
            result['change_snap_link_status'], \
                result['sg_snap_link_details'] = \
                self.change_snapshot_link_status(sg_name,
                                                 target_sg_name,
                                                 snapshot_name,
                                                 link,
                                                 generation)

        if state == 'present' and sg_name and snapshot_name and \
                new_snapshot_name and generation == 0:
            LOG.info('Rename storage group {0} snapshot {1} '.format(
                sg_name, snapshot_name))
            result['rename_sg_snap'], result['sg_snap_rename_details'] = \
                self.rename_sg_snapshot(sg_name,
                                        snapshot_name,
                                        new_snapshot_name,
                                        generation)

        if state == 'present' and not ttl and not link and \
                not new_snapshot_name:
            LOG.info(
                'Returning storage group {0} snapshot {1} details '.format(
                    sg_name, snapshot_name))
            result['sg_snap_details'] = self.get_snapshot(
                sg_name, snapshot_name, generation)

        if result['create_sg_snap'] or result['delete_sg_snap'] or result[
                'rename_sg_snap'] or result['change_snap_link_status']:
            result['changed'] = True
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")

        # Finally update the module result!
        self.module.exit_json(**result)
    def perform_module_operation(self):
        """
        Perform different actions on volume based on user parameter
        chosen in playbook
        """
        size = self.module.params['size']
        state = self.module.params['state']
        new_name = self.module.params['new_name']
        vol_id = self.module.params['vol_id']
        vol_name = self.module.params['vol_name']
        sg_name = self.module.params['sg_name']
        cap_unit = self.module.params['cap_unit']
        new_sg_name = self.module.params['new_sg_name']

        if vol_name is not None and sg_name is None:
            self.show_error_exit(msg='Specify Storage group name along '
                                 'with volume name')

        self.volume_id = vol_id

        vol = self.get_volume()

        existing_vol_size = 0
        if vol is not None:
            self.volume_id = vol['volumeId']
            vol_id = vol['volumeId']
            existing_vol_size = vol['cap_gb']

        changed = False

        # Call to create volume in storage group
        if state == 'present' and vol is None:
            if size is None:
                self.show_error_exit(msg='Size is required to create volume')
            vol_id = self.create_volume(vol_name, sg_name, size, cap_unit)
            changed = True

        if state == 'present' and vol and size:
            if size is None:
                self.show_error_exit(msg='Size is required to expand volume')
            # Convert the given size to GB
            if size is not None and size > 0:
                size = utils.get_size_in_gb(size,
                                            self.module.params['cap_unit'])
                LOG.info('Existing Size: %s GB, Specified Size: %s GB',
                         existing_vol_size, size)
            changed = self.expand_volume_helper(vol, size, existing_vol_size)

        if state == 'present' and vol and new_name:
            vol_name = vol['volume_identifier']
            if new_name != vol_name:
                LOG.info('Changing the name of volume %s to %s', vol_name,
                         new_name)
                changed = self.rename_volume(vol_id, new_name) or changed

        if state == 'absent' and vol:
            LOG.info('Deleting volume %s ', vol_id)
            changed = self.delete_volume(vol_id) or changed

        if state == 'present' and vol and new_sg_name:
            changed = self.move_volume_between_storage_groups(
                vol, sg_name, new_sg_name) or changed
        '''
        Finally update the module changed state and saving updated volume
        details
        '''
        self.u4v_conn.set_array_id(array_id=self.module.params['serial_no'])
        self.result["changed"] = changed
        if state == 'present':
            self.result["volume_details"] = self.get_volume()
        LOG.info("Closing unisphere connection {0}".format(self.u4v_conn))
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)