Exemplo n.º 1
0
    def check_for_setup_error(self):
        """Returns an error if prerequisites aren't met."""
        if not self.configuration.san_password:
            raise exception.InvalidInput(reason=translate('Specify san_password'))

        # The san_ip must always be set, because we use it for the target
        if not self.configuration.san_ip:
            raise exception.InvalidInput(reason=translate("san_ip must be set"))
Exemplo n.º 2
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""
        # Replace the body with fault details.
        locale = req.best_match_language()
        code = self.wrapped_exc.status_int
        fault_name = self._fault_names.get(code, "computeFault")
        explanation = self.wrapped_exc.explanation
        fault_data = {
            fault_name: {
                'code': code,
                'message': i18n.translate(explanation, locale)}}
        if code == 413:
            retry = self.wrapped_exc.headers.get('Retry-After', None)
            if retry:
                fault_data[fault_name]['retryAfter'] = retry

        # 'code' is an attribute on the fault tag itself
        metadata = {'attributes': {fault_name: 'code'}}

        xml_serializer = XMLDictSerializer(metadata, XML_NS_V2)

        content_type = req.best_match_content_type()
        serializer = {
            'application/xml': xml_serializer,
            'application/json': JSONDictSerializer(),
        }[content_type]

        self.wrapped_exc.body = serializer.serialize(fault_data)
        self.wrapped_exc.content_type = content_type
        _set_request_id_header(req, self.wrapped_exc.headers)

        return self.wrapped_exc
Exemplo n.º 3
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""
        # Replace the body with fault details.
        locale = req.best_match_language()
        code = self.wrapped_exc.status_int
        fault_name = self._fault_names.get(code, "computeFault")
        explanation = self.wrapped_exc.explanation
        fault_data = {
            fault_name: {
                'code': code,
                'message': i18n.translate(explanation, locale)}}
        if code == 413:
            retry = self.wrapped_exc.headers.get('Retry-After', None)
            if retry:
                fault_data[fault_name]['retryAfter'] = retry

        if (not req.api_version_request.is_null() and not
           _is_legacy_endpoint(req)):
            self.wrapped_exc.headers[API_VERSION_REQUEST_HEADER] = (
                VOLUME_SERVICE + ' ' + req.api_version_request.get_string())
            self.wrapped_exc.headers['Vary'] = API_VERSION_REQUEST_HEADER

        content_type = req.best_match_content_type()
        serializer = {
            'application/json': JSONDictSerializer(),
        }[content_type]

        body = serializer.serialize(fault_data)
        if isinstance(body, six.text_type):
            body = body.encode('utf-8')
        self.wrapped_exc.body = body
        self.wrapped_exc.content_type = content_type
        _set_request_id_header(req, self.wrapped_exc.headers)

        return self.wrapped_exc
Exemplo n.º 4
0
 def _get_pool(self):
     if not self.pool:
         pools = self.system.pools.find(id=int(self.configuration.infinidat_pool_id))
         if not pools:
             raise exception.InvalidInput(translate("pool {0} not found".format(int(self.configuration.infinidat_pool_id))))
         self.pool = pools[0]
     return self.pool
Exemplo n.º 5
0
 def create_cloned_volume(self, tgt_cinder_volume, src_cinder_volume):
     if tgt_cinder_volume.size < src_cinder_volume.size:
         msg = "cannot shrink clone. original size={}, target size={}".format(src_cinder_volume.size, tgt_cinder_volume.size)
         raise exception.InvalidInput(reason=translate(msg))
     src_infinidat_volume = self._find_volume(src_cinder_volume)
     # We first create a snapshot and then a clone from that snapshot.
     snapshot = src_infinidat_volume.create_snapshot(name=self._create_snapshot_name(src_cinder_volume) + "-internal")
     self._set_obj_metadata(snapshot, {
         "cinder_id": "",
         "internal": "true"
         })
     # We now create a clone from the snapshot
     tgt_infinidat_volume = snapshot.create_child(name=self._create_volume_name(tgt_cinder_volume))
     tgt_infinidat_volume.disable_write_protection()
     tgt_infinidat_volume.update_size(tgt_cinder_volume.size * GiB)
     if hasattr(tgt_cinder_volume, "consistencygroup") and tgt_cinder_volume.consistencygroup:
         cinder_cg = tgt_cinder_volume.consistencygroup
         self._add_volume_to_cg(tgt_infinidat_volume, cinder_cg)
     else:
         cinder_cg = None
     self._set_volume_or_snapshot_metadata(
         tgt_infinidat_volume,
         tgt_cinder_volume,
         delete_parent=True,
         cinder_cg=cinder_cg)
Exemplo n.º 6
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""
        # Replace the body with fault details.
        locale = req.best_match_language()
        code = self.wrapped_exc.status_int
        fault_name = self._fault_names.get(code, "computeFault")
        explanation = self.wrapped_exc.explanation
        fault_data = {
            fault_name: {
                'code': code,
                'message': i18n.translate(explanation, locale)
            }
        }
        if code == 413:
            retry = self.wrapped_exc.headers.get('Retry-After', None)
            if retry:
                fault_data[fault_name]['retryAfter'] = retry

        # 'code' is an attribute on the fault tag itself
        metadata = {'attributes': {fault_name: 'code'}}

        xml_serializer = XMLDictSerializer(metadata, XML_NS_V2)

        content_type = req.best_match_content_type()
        serializer = {
            'application/xml': xml_serializer,
            'application/json': JSONDictSerializer(),
        }[content_type]

        self.wrapped_exc.body = serializer.serialize(fault_data)
        self.wrapped_exc.content_type = content_type
        _set_request_id_header(req, self.wrapped_exc.headers)

        return self.wrapped_exc
Exemplo n.º 7
0
 def extend_volume(self, cinder_volume, new_size):
     LOG.info("InfiniboxVolumeDriver.extend_volume")
     infinidat_volume = self._find_volume(cinder_volume)
     new_size_in_bytes = new_size * GiB
     if infinidat_volume.get_size() != new_size_in_bytes:
         if infinidat_volume.get_size() > new_size_in_bytes:
             msg = "cannot shrink volume: new size must be greater or equal to current size. original size={}, new size={}"
             raise exception.InvalidInput(reason=translate(msg.format(infinidat_volume.get_size(), new_size_in_bytes)))
         infinidat_volume.update_size(new_size_in_bytes)
Exemplo n.º 8
0
 def _handle_connection(self, protocol_methods, cinder_volume, connector, *args, **kwargs):
     preferred_fc = self.configuration.infinidat_prefer_fc
     fc, iscsi = connector.get('wwpns'), connector.get('initiator')
     if not fc and not iscsi:
         raise exception.Invalid(translate(("no wwpns or iscsi initiator in connector {0}".format(connector))))
     elif fc and (not iscsi or preferred_fc):
         return protocol_methods['fc'](cinder_volume, connector, *args, **kwargs)
     else:
         return protocol_methods['iscsi'](cinder_volume, connector, *args, **kwargs)
Exemplo n.º 9
0
    def do_setup(self, context):
        from infinisdk.core.exceptions import ObjectNotFound
        from infinidat_openstack.config import is_masked, unmask
        for key in ('infinidat_provision_type', 'infinidat_pool_id', 'san_login', 'san_password'):
            if not self.configuration.safe_get(key):
                raise exception.InvalidInput(reason=translate("{0} must be set".format(key)))

        provision_type = self.configuration.infinidat_provision_type
        if provision_type.upper() not in ('THICK', 'THIN'):
            raise exception.InvalidInput(reason=translate("infinidat_provision_type must be THICK or THIN"))

        from infinisdk import InfiniBox
        self.system = InfiniBox(self.configuration.san_ip,
                                auth=(self.configuration.san_login,
                                      unmask(self.configuration.san_password) if \
                                      is_masked(self.configuration.san_password) else \
                                      self.configuration.san_password))
        self.system.login()
        try:
            self._get_pool()  # we want to search for the pool here so we fail if we can't find it.
        except (ObjectNotFound, exception.InvalidInput):
            if not self.configuration.infinidat_allow_pool_not_found:
                raise
            LOG.info("InfiniBox pool not found, but infinidat_allow_pool_not_found is set")
Exemplo n.º 10
0
 def create_volume_from_snapshot(self, cinder_volume, cinder_snapshot):
     infinidat_snapshot = self._find_snapshot(cinder_snapshot)
     if cinder_volume.size * GiB < infinidat_snapshot.get_size():
         msg = "cannot shrink snapshot. original size={}, target size={}".format(infinidat_snapshot.get_size(), cinder_volume.size * GiB)
         raise exception.InvalidInput(reason=translate(msg))
     infinidat_volume = infinidat_snapshot.create_child(name=self._create_volume_name(cinder_volume))
     infinidat_volume.disable_write_protection()
     infinidat_volume.update_size(cinder_volume.size * GiB)
     if hasattr(cinder_volume, 'consistencygroup') and cinder_volume.consistencygroup:
         cinder_cg = cinder_volume.consistencygroup
         self._add_volume_to_cg(infinidat_volume, cinder_cg)
     else:
         cinder_cg = None
     self._set_volume_or_snapshot_metadata(
         infinidat_volume,
         cinder_volume,
         cinder_cg=cinder_cg)
Exemplo n.º 11
0
    def delete_volume(self, cinder_volume):
        from infinisdk.core.exceptions import ObjectNotFound
        try:
            infinidat_volume = self._find_volume(cinder_volume)
        except ObjectNotFound:
            LOG.info("delete_volume: volume {0!r} not found in InfiniBox, returning None".format(cinder_volume))
            return
        metadata = infinidat_volume.get_all_metadata()

        if infinidat_volume.has_children():
            raise exception.VolumeIsBusy(volume_name=translate(infinidat_volume.get_name()))

        delete_parent = metadata.get("delete_parent", "false").lower() == "true"
        object_to_delete = infinidat_volume.get_parent() if delete_parent else infinidat_volume

        if self.configuration.infinidat_purge_volume_on_deletion:
            self._purge_infinidat_volume(object_to_delete)
        else:
            object_to_delete.delete()
Exemplo n.º 12
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""
        # Replace the body with fault details.
        locale = req.best_match_language()
        code = self.wrapped_exc.status_int
        fault_name = self._fault_names.get(code, "computeFault")
        explanation = self.wrapped_exc.explanation
        fault_data = {
            fault_name: {
                'code': code,
                'message': i18n.translate(explanation, locale)}}
        if code == 413:
            retry = self.wrapped_exc.headers.get('Retry-After', None)
            if retry:
                fault_data[fault_name]['retryAfter'] = retry

        # 'code' is an attribute on the fault tag itself
        metadata = {'attributes': {fault_name: 'code'}}

        xml_serializer = XMLDictSerializer(metadata, XML_NS_V2)

        content_type = req.best_match_content_type()
        serializer = {
            'application/xml': xml_serializer,
            'application/json': JSONDictSerializer(),
        }[content_type]

        if content_type == 'application/xml':
            global XML_WARNING
            if not XML_WARNING:
                msg = _('XML support has been deprecated and will be removed '
                        'in the N release.')
                versionutils.report_deprecated_feature(LOG, msg)
            XML_WARNING = True

        body = serializer.serialize(fault_data)
        if isinstance(body, six.text_type):
            body = body.encode('utf-8')
        self.wrapped_exc.body = body
        self.wrapped_exc.content_type = content_type
        _set_request_id_header(req, self.wrapped_exc.headers)

        return self.wrapped_exc
Exemplo n.º 13
0
 def translate(msg):
     locale = request.best_match_language()
     return i18n.translate(msg, locale)
Exemplo n.º 14
0
 def _assert_connector(self, connector):
     if ((u'wwpns' not in connector or not connector[u'wwpns']) and
         (u'initiator' not in connector or not connector[u'initiator'])):
         LOG.warn("no WWPN or iSCSI initiator was provided in connector: {0!r}".format(connector))
         raise exception.Invalid(translate('No WWPN or iSCSI initiator was received'))
Exemplo n.º 15
0
 def delete_snapshot(self, cinder_snapshot):
     infinidat_snapshot = self._find_snapshot(cinder_snapshot)
     if infinidat_snapshot.has_children():
         raise exception.SnapshotIsBusy(snapshot_name=translate(infinidat_snapshot.get_name()))
     infinidat_snapshot.delete()
Exemplo n.º 16
0
 def translate(msg):
     locale = request.best_match_language()
     return i18n.translate(msg, locale)
Exemplo n.º 17
0
 def create_snapshot(self, cinder_snapshot):
     infinidat_volume = self._find_volume(cinder_snapshot.volume)
     infinidat_snapshot = infinidat_volume.create_snapshot(name=translate(self._create_snapshot_name(cinder_snapshot)))
     self._set_volume_or_snapshot_metadata(infinidat_snapshot, cinder_snapshot)