예제 #1
0
파일: cinder.py 프로젝트: 2Exception/patron
 def check_attach(self, context, volume, instance=None):
     # TODO(vish): abstract status checking?
     if volume['status'] != "available":
         msg = _("volume '%(vol)s' status must be 'available'. Currently "
                 "in '%(status)s'") % {
                     'vol': volume['id'],
                     'status': volume['status']
                 }
         raise exception.InvalidVolume(reason=msg)
     if volume['attach_status'] == "attached":
         msg = _("volume %s already attached") % volume['id']
         raise exception.InvalidVolume(reason=msg)
     if instance and not CONF.cinder.cross_az_attach:
         # NOTE(sorrison): If instance is on a host we match against it's AZ
         #                 else we check the intended AZ
         if instance.get('host'):
             instance_az = az.get_instance_availability_zone(
                 context, instance)
         else:
             instance_az = instance['availability_zone']
         if instance_az != volume['availability_zone']:
             msg = _("Instance %(instance)s and volume %(vol)s are not in "
                     "the same availability_zone. Instance is in "
                     "%(ins_zone)s. Volume is in %(vol_zone)s") % {
                         "instance": instance['id'],
                         "vol": volume['id'],
                         'ins_zone': instance_az,
                         'vol_zone': volume['availability_zone']
                     }
             raise exception.InvalidVolume(reason=msg)
예제 #2
0
 def check_attach(self, context, volume, instance=None):
     if volume['status'] != 'available':
         msg = "status must be available"
         msg = "%s" % volume
         raise exception.InvalidVolume(reason=msg)
     if volume['attach_status'] == 'attached':
         msg = "already attached"
         raise exception.InvalidVolume(reason=msg)
     if instance and not CONF.cinder.cross_az_attach:
         if instance['availability_zone'] != volume['availability_zone']:
             msg = "Instance and volume not in same availability_zone"
             raise exception.InvalidVolume(reason=msg)
예제 #3
0
파일: cinder.py 프로젝트: 2Exception/patron
 def check_attached(self, context, volume):
     if volume['status'] != "in-use":
         msg = _("volume '%(vol)s' status must be 'in-use'. Currently in "
                 "'%(status)s' status") % {
                     "vol": volume['id'],
                     "status": volume['status']
                 }
         raise exception.InvalidVolume(reason=msg)
예제 #4
0
 def get_by_volume_id(cls,
                      context,
                      volume_id,
                      instance_uuid=None,
                      expected_attrs=None):
     if expected_attrs is None:
         expected_attrs = []
     db_bdm = db.block_device_mapping_get_by_volume_id(
         context, volume_id, _expected_cols(expected_attrs))
     if not db_bdm:
         raise exception.VolumeBDMNotFound(volume_id=volume_id)
     # NOTE (ndipanov): Move this to the db layer into a
     # get_by_instance_and_volume_id method
     if instance_uuid and instance_uuid != db_bdm['instance_uuid']:
         raise exception.InvalidVolume(
             reason=_("Volume does not belong to the "
                      "requested instance."))
     return cls._from_db_object(context,
                                cls(),
                                db_bdm,
                                expected_attrs=expected_attrs)
예제 #5
0
 def check_detach(self, context, volume):
     if volume['status'] == "available":
         msg = "already detached"
         raise exception.InvalidVolume(reason=msg)
예제 #6
0
파일: cinder.py 프로젝트: 2Exception/patron
 def check_detach(self, context, volume):
     # TODO(vish): abstract status checking?
     if volume['status'] == "available":
         msg = _("volume %s already detached") % volume['id']
         raise exception.InvalidVolume(reason=msg)