コード例 #1
0
 def close_connection(self):
     try:
         LOG.info("Closing unisphere connection %s", self.conn)
         utils.close_connection(self.conn)
         LOG.info("Connection closed successfully")
     except Exception as e:
         err_msg = ("Failed to close unisphere connection with error:"
                    " %s", str(e))
         LOG.error(err_msg)
コード例 #2
0
 def show_error_exit(self, msg):
     if self.u4v_conn is not None:
         try:
             LOG.info("Closing unisphere connection %s", 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:"
                        " %s", str(e))
             LOG.error(err_msg)
     LOG.error(msg)
     self.module.fail_json(msg=msg)
コード例 #3
0
ファイル: maskingview.py プロジェクト: dell/ansible-powermax
    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']

        self.validate_host_params()
        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 %s', 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 %s', mv_name)
            result['modify_mv'] = self.rename_masking_view(
                mv_name, new_mv_name)
            if not self.module.check_mode:
                mv_name = new_mv_name

        if state == 'absent' and masking_view:
            LOG.info('Delete masking view %s', 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 %s", 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)
コード例 #4
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 %s', portgroup_name)
            changed = self.create_portgroup(portgroup_name)
        elif state == 'present' and portgroup and new_name:
            LOG.info('Modifying port group %s', portgroup_name)
            changed_name = self.modify_portgroup(portgroup_name)
            if changed_name:
                if not self.module.check_mode:
                    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 %s', 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 %s', portgroup_name)
            changed = self.remove_ports_from_portgroup(
                portgroup_name) or changed
        elif state == 'absent' and portgroup:
            LOG.info('Delete post group %s', 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':
            self.result["portgroup_details"] = {}
        else:
            self.result["portgroup_details"] = self.get_portgroup(
                portgroup_name)
        LOG.info("Closing unisphere connection %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
コード例 #5
0
ファイル: port.py プロジェクト: dell/ansible-powermax
    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 %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
コード例 #6
0
    def perform_module_operation(self):

        job_id = self.module.params['job_id']
        if job_id and job_id.isdigit():
            job_details = self.get_job_details(job_id)
        else:
            errorMsg = 'Invalid job_id: %s' % job_id
            self.show_error_exit(msg=errorMsg)

        LOG.info("Closing unisphere connection %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")

        self.module.exit_json(changed=False, Job_details=job_details)
コード例 #7
0
    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 %s", 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 host group based on user parameter
        chosen 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']
        host_type = self.module.params['host_type']

        if (hostgroup_name is None) or (hostgroup_name is not None and
                                        len(hostgroup_name.strip()) == 0):
            error_msg = "hostgroup_name is mandatory parameter. Please " \
                        "provide valid host group name."
            LOG.error(error_msg)
            self.module.fail_json(msg=error_msg)

        hostgroup = self.get_hostgroup(hostgroup_name)
        changed = False

        if state == 'present' and not hostgroup and hostgroup_name:
            if new_name:
                error_msg = "Invalid argument 'new_name' while " \
                            "creating a host"
                LOG.error(error_msg)
                self.show_error_exit(msg=error_msg)

            if host_state and host_state != "present-in-group":
                error_msg = "Incorrect host_state specified for Create" \
                            " hostgroup functionality"
                LOG.error(error_msg)
                self.show_error_exit(msg=error_msg)

            LOG.info('Creating host group %s', 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 %s', 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 %s', hostgroup_name)
            changed = self.remove_hosts_from_hostgroup(
                hostgroup_name, hosts) or changed

        if state == 'present' and hostgroup and (host_flags or host_type):
            LOG.info('Modifying host group flags of hostgroup %s',
                     hostgroup_name)
            changed = (self.modify_host_flags(hostgroup_name,
                                              received_host_flags=host_flags,
                                              host_type=host_type) or changed)

        if state == 'present' and hostgroup and new_name is not None:
            if len(new_name.strip()) == 0:
                self.show_error_exit(msg="Please provide valid hostgroup "
                                         "name.")

            if hostgroup['hostGroupId'] != new_name:
                LOG.info('Renaming host group %s to %s',
                         hostgroup_name, new_name)
                changed = self.rename_hostgroup(hostgroup_name, new_name)

        if state == 'absent' and hostgroup:
            LOG.info('Delete host group %s ', hostgroup_name)
            changed = self.delete_hostgroup(hostgroup_name) or changed

        self._create_result_dict(changed, hostgroup)
        # Update the module's final state
        LOG.info('changed %s', changed)
        LOG.info("Closing unisphere connection %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
コード例 #9
0
ファイル: info.py プロジェクト: dell/ansible-powermax
    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 == '':
            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 = []
            alert = []
            metro_dr_env = []
            snapshot_policies = []
            initiators = []
            if 'alert' in str(subset):
                alert = self.get_system_alerts(filters_dict=filters_dict)
            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()
            if 'metro_dr_env' in str(subset):
                metro_dr_env = \
                    self.get_metro_dr_env_list()
            if 'snapshot_policies' in str(subset):
                snapshot_policies = \
                    self.get_snapshot_policies_list()
            if 'initiators' in str(subset):
                initiators = \
                    self.get_initiators_list(filters_dict=filters_dict)

            LOG.info("Closing unisphere connection %s", self.u4v_conn)
            utils.close_connection(self.u4v_conn)
            LOG.info("Connection closed successfully")

            self.module.exit_json(Alerts=alert,
                                  Health=health_check,
                                  Volumes=vol,
                                  StorageGroups=sg,
                                  StorageResourcePools=srp,
                                  PortGroups=pg,
                                  Hosts=host,
                                  HostGroups=hg,
                                  Ports=port,
                                  MaskingViews=mv,
                                  RDFGroups=rdf,
                                  MetroDREnvironments=metro_dr_env,
                                  SnapshotPolicies=snapshot_policies,
                                  Initiators=initiators)
コード例 #10
0
ファイル: snapshot.py プロジェクト: dell/ansible-powermax
    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']
        snap_id = self.module.params['snapshot_id']
        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 snap_id is not None and not self.is_snap_id_supported():
            self.show_error_exit("snapshot_id is not supported by this"
                                 " platform")

        if state == 'present' and ttl and not \
                (new_snapshot_name or link):
            LOG.info('Creating snapshot %s for storage group %s ',
                     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':
            if not (isinstance(generation, int) or isinstance(snap_id, int)):
                self.show_error_exit(msg="Please specify a valid generation "
                                         "or a snapshot_id to delete a "
                                         "snapshot.")
            else:
                LOG.info('Delete storage group %s snapshot %s generation %s ',
                         sg_name, snapshot_name, generation)
                result['delete_sg_snap'] = self.delete_sg_snapshot(
                    sg_name,
                    snapshot_name,
                    generation,
                    snap_id)

        if state == 'present' and snapshot_name \
                and link and target_sg_name:
            if not (isinstance(generation, int) or isinstance(snap_id, int)):
                self.show_error_exit(msg="Please specify a valid generation "
                                         "or a snapshot_id to change the "
                                         "link status of a snapshot.")
            else:
                LOG.info('Change storage group %s snapshot %s link status ',
                         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,
                                                     snap_id)

        if state == 'present' and sg_name and snapshot_name and \
                new_snapshot_name:
            if not (isinstance(generation, int) or isinstance(snap_id, int)):
                self.show_error_exit("Please specify a valid generation or "
                                     "a snapshot_id to rename a snapshot.")
            elif snap_id is not None or generation == 0:
                LOG.info('Rename storage group %s snapshot %s ',
                         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,
                                            snap_id)

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

        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 %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")

        # Finally update the module result!
        self.module.exit_json(**result)
コード例 #11
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.debug('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
                if self.result['SRDF_link_details']\
                        and self.module.params['remote_serial_no'] \
                        and not changed:
                    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()

                if self.result['SRDF_link_details'] \
                        and (srdf_mode or srdf_state) and not changed:
                    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 %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)
コード例 #12
0
ファイル: volume.py プロジェクト: dell/ansible-powermax
    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')

        if size and cap_unit is None:
            cap_unit = 'GB'
        elif cap_unit and size is None:
            self.show_error_exit(msg='Parameters size and cap_unit are '
                                 'required together')
        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 new_name:
                self.show_error_exit(msg="Invalid argument new_name "
                                     "while creating a volume")
            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, 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 is not None:
            if len(new_name.strip()) == 0:
                self.show_error_exit(msg="Please provide valid volume "
                                     "name.")
            if 'volume_identifier' in vol:
                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
            else:
                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:
            vol_sg = vol['storageGroupId'][0]
            if vol_sg != new_sg_name:
                LOG.info('Moving volume from %s to %s', vol_sg, new_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 %s", self.u4v_conn)
        utils.close_connection(self.u4v_conn)
        LOG.info("Connection closed successfully")
        self.module.exit_json(**self.result)