예제 #1
0
 def _load_keypair(self, keypair=None):
     key_location = None
     if keypair:
         kp = self.ec2.get_keypair(keypair)
         key = self.cfg.get_key(kp.name)
         key_location = key.get('key_location', '')
     else:
         self.log.info("No keypair specified, picking one from config...")
         for kp in self.ec2.keypairs:
             if kp.name in self.cfg.keys:
                 keypair = kp.name
                 kl = self.cfg.get_key(kp.name).get('key_location', '')
                 if os.path.exists(kl) and os.path.isfile(kl):
                     self.log.info('Using keypair: %s' % keypair)
                     key_location = kl
                     break
     if not keypair:
         raise exception.ConfigError(
             "no keypairs in region %s defined in config" %
             self.ec2.region.name)
     if not key_location:
         raise exception.ConfigError(
             "cannot determine key_location for keypair %s" % keypair)
     if not os.path.exists(key_location):
         raise exception.ValidationError(
             "key_location '%s' does not exist." % key_location)
     elif not os.path.isfile(key_location):
         raise exception.ValidationError(
             "key_location '%s' is not a file." % key_location)
     return (keypair, key_location)
예제 #2
0
 def _validate_size(self, size):
     try:
         volume_size = int(size)
         if volume_size < 1:
             raise exception.ValidationError(
                 "volume_size must be an integer >= 1")
     except ValueError:
         raise exception.ValidationError("volume_size must be an integer")
예제 #3
0
 def _validate_host_instance(self, instance, zone):
     if instance.state not in ['pending', 'running']:
         raise exception.InstanceNotRunning(instance.id)
     if instance.placement != zone:
         raise exception.ValidationError(
             "specified host instance %s is not in zone %s" %
             (instance.id, zone))
     return True
예제 #4
0
 def _validate_image_and_type(self, image, itype):
     img = self.ec2.get_image_or_none(image)
     if not img:
         raise exception.ValidationError('image %s does not exist' % image)
     if not itype in static.INSTANCE_TYPES:
         choices = ', '.join(static.INSTANCE_TYPES)
         raise exception.ValidationError(
             'instance_type must be one of: %s' % choices)
     itype_platform = static.INSTANCE_TYPES.get(itype)
     img_platform = img.architecture
     if img_platform not in itype_platform:
         error_msg = "instance_type %(itype)s is for an " + \
                       "%(iplat)s platform while image_id " + \
                       "%(img)s is an %(imgplat)s platform"
         error_dict = {
             'itype': itype,
             'iplat': ', '.join(itype_platform),
             'img': img.id,
             'imgplat': img_platform
         }
         raise exception.ValidationError(error_msg % error_dict)
예제 #5
0
 def _validate_device(self, device):
     if not utils.is_valid_device(device):
         raise exception.ValidationError("volume device %s is not valid" % \
                                         device)