예제 #1
0
파일: ebs.py 프로젝트: merckhung/libui
 def attach(self):
     ec2 = boto.connect_ec2()
     if self.logical_volume_name:
         # if a logical volume was specified, override the specified volume_id
         # (if there was one) with the current AWS volume for the logical volume:
         logical_volume = next(Volume.find(name = self.logical_volume_name))
         self.volume_id = logical_volume._volume_id
     volume = ec2.get_all_volumes([self.volume_id])[0]
     # wait for the volume to be available. The volume may still be being created
     # from a snapshot.
     while volume.update() != 'available':
         boto.log.info('Volume %s not yet available. Current status = %s.' % (volume.id, volume.status))
         time.sleep(5)
     instance = ec2.get_only_instances([self.instance_id])[0]
     attempt_attach = True
     while attempt_attach:
         try:
             ec2.attach_volume(self.volume_id, self.instance_id, self.device)
             attempt_attach = False
         except EC2ResponseError as e:
             if e.error_code != 'IncorrectState':
                 # if there's an EC2ResonseError with the code set to IncorrectState, delay a bit for ec2
                 # to realize the instance is running, then try again. Otherwise, raise the error:
                 boto.log.info('Attempt to attach the EBS volume %s to this instance (%s) returned %s. Trying again in a bit.' % (self.volume_id, self.instance_id, e.errors))
                 time.sleep(2)
             else:
                 raise e
     boto.log.info('Attached volume %s to instance %s as device %s' % (self.volume_id, self.instance_id, self.device))
     # now wait for the volume device to appear
     while not os.path.exists(self.device):
         boto.log.info('%s still does not exist, waiting 2 seconds' % self.device)
         time.sleep(2)
예제 #2
0
 def attach(self):
     ec2 = boto.connect_ec2()
     if self.logical_volume_name:
         # if a logical volume was specified, override the specified volume_id
         # (if there was one) with the current AWS volume for the logical volume:
         logical_volume = Volume.find(name=self.logical_volume_name).next()
         self.volume_id = logical_volume._volume_id
     volume = ec2.get_all_volumes([self.volume_id])[0]
     # wait for the volume to be available. The volume may still be being created
     # from a snapshot.
     while volume.update() != 'available':
         boto.log.info('Volume %s not yet available. Current status = %s.' %
                       (volume.id, volume.status))
         time.sleep(5)
     instance = ec2.get_only_instances([self.instance_id])[0]
     attempt_attach = True
     while attempt_attach:
         try:
             ec2.attach_volume(self.volume_id, self.instance_id,
                               self.device)
             attempt_attach = False
         except EC2ResponseError, e:
             if e.error_code != 'IncorrectState':
                 # if there's an EC2ResonseError with the code set to IncorrectState, delay a bit for ec2
                 # to realize the instance is running, then try again. Otherwise, raise the error:
                 boto.log.info(
                     'Attempt to attach the EBS volume %s to this instance (%s) returned %s. Trying again in a bit.'
                     % (self.volume_id, self.instance_id, e.errors))
                 time.sleep(2)
             else:
                 raise e
예제 #3
0
파일: ebs.py 프로젝트: rlotun/boto
 def attach(self):
     ec2 = boto.connect_ec2()
     if self.logical_volume_name:
         # if a logical volume was specified, override the specified volume_id
         # (if there was one) with the current AWS volume for the logical volume:
         logical_volume = Volume.find(name=self.logical_volume_name).next()
         self.volume_id = logical_volume._volume_id
     volume = ec2.get_all_volumes([self.volume_id])[0]
     # wait for the volume to be available. The volume may still be being created
     # from a snapshot.
     while volume.update() != "available":
         boto.log.info("Volume %s not yet available. Current status = %s." % (volume.id, volume.status))
         time.sleep(5)
     instance = ec2.get_all_instances([self.instance_id])[0].instances[0]
     attempt_attach = True
     while attempt_attach:
         try:
             ec2.attach_volume(self.volume_id, self.instance_id, self.device)
             attempt_attach = False
         except EC2ResponseError, e:
             if e.error_code != "IncorrectState":
                 # if there's an EC2ResonseError with the code set to IncorrectState, delay a bit for ec2
                 # to realize the instance is running, then try again. Otherwise, raise the error:
                 boto.log.info(
                     "Attempt to attach the EBS volume %s to this instance (%s) returned %s. Trying again in a bit."
                     % (self.volume_id, self.instance_id, e.errors)
                 )
                 time.sleep(2)
             else:
                 raise e
예제 #4
0
 def attach(self):
     ec2 = boto.connect_ec2()
     if self.logical_volume_name:
         # if a logical volume was specified, override the specified volume_id
         # (if there was one) with the current AWS volume for the logical volume:
         logical_volume = Volume.find(name = self.logical_volume_name).next()
         self.volume_id = logical_volume._volume_id
     volume = ec2.get_all_volumes([self.volume_id])[0]
     # wait for the volume to be available. The volume may still be being created
     # from a snapshot.
     while volume.update() != 'available':
         boto.log.info('Volume %s not yet available. Current status = %s.' % (volume.id, volume.status))
         time.sleep(5)
     ec2.attach_volume(self.volume_id, self.instance_id, self.device)
     # now wait for the volume device to appear
     while not os.path.exists(self.device):
         boto.log.info('%s still does not exist, waiting 10 seconds' % self.device)
         time.sleep(10)
예제 #5
0
 def attach(self):
     ec2 = boto.connect_ec2()
     if self.logical_volume_name:
         # if a logical volume was specified, override the specified volume_id
         # (if there was one) with the current AWS volume for the logical volume:
         logical_volume = Volume.find(name=self.logical_volume_name).next()
         self.volume_id = logical_volume._volume_id
     volume = ec2.get_all_volumes([self.volume_id])[0]
     # wait for the volume to be available. The volume may still be being created
     # from a snapshot.
     while volume.update() != 'available':
         boto.log.info('Volume %s not yet available. Current status = %s.' %
                       (volume.id, volume.status))
         time.sleep(5)
     ec2.attach_volume(self.volume_id, self.instance_id, self.device)
     # now wait for the volume device to appear
     while not os.path.exists(self.device):
         boto.log.info('%s still does not exist, waiting 10 seconds' %
                       self.device)
         time.sleep(10)