Stops the instance gracefully.

        :param str instance_id: instance identifier
509909
def stop_instance(self, instance_id):
        
        instance = self._load_instance(instance_id)
        instance.terminate()
        del self._instances[instance_id]
845856
def terminate(self):
        
        rs = self.connection.terminate_instances([self.id])
        if len(rs) > 0:
            self._update(rs[0])
1309573
def stop(name, force=False, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The stop action must be called with -a or --action.'
        )

    log.info('Stopping node %s', name)

    instanceId = _get_node(name)['InstanceId']

    params = {
        'Action': 'StopInstance',
        'InstanceId': instanceId,
        'ForceStop': six.text_type(force).lower()
    }
    result = query(params)

    return result
617617
def stop(id, reason = '')
      params = { :id => id }
      requires params
      params[:reason] = reason
      DataSift.request(:POST, 'historics/stop', @config, params)
    end
969454
def suspend(self, instance_id):
        '''
        
        '''
        nt_ks = self.compute_conn
        response = nt_ks.servers.suspend(instance_id)
        return True
1176833
def cleanup(self):

        '''
            
        '''

    # find non-running instances
        self.iam.printer('Cleaning up AWS region %s.' % self.iam.region_name)
        response = self.connection.describe_instances()
        instance_list = response['Reservations']
        for instance in instance_list:
            instance_info = instance['Instances'][0]
            if instance_info['State']['Name'] == 'pending':
                self.check_instance_state(instance_info['InstanceId'])
                response = self.connection.describe_instances(
                    InstanceIds=[ instance_info['InstanceId'] ]
                )
                instance_info = response['Reservations'][0]['Instances'][0]
            if instance_info['State']['Name'] != 'running':

    # try to remove tags associated with non-running instance
                try:
                    response = self.connection.describe_tags(
                        Filters=[ { 'Name': 'resource-id', 'Values': [ instance_info['InstanceId'] ] } ]
                    )
                    tag_list = []
                    import re
                    aws_tag_pattern = re.compile('aws:')
                    for i in range(0, len(response['Tags'])):
                        if not aws_tag_pattern.findall(response['Tags'][i]['Key']):
                            tag = {}
                            tag['Key'] = response['Tags'][i]['Key']
                            tag['Value'] = response['Tags'][i]['Value']
                            tag_list.append(tag)
                    self.connection.delete_tags(
                        Resources=[ instance_info['InstanceId'] ],
                        Tags=tag_list
                    )
                    self.iam.printer('Tags have been deleted from instance %s.' % instance_info['InstanceId'])
                except:
                    pass

    # try stopping non-running instance
                try:
                    self.connection.stop_instances(
                        InstanceIds=[ instance_info['InstanceId'] ]
                    )
                    self.iam.printer('Instance %s is stopping.' % instance_info['InstanceId'])
                except:
                    pass

    # try terminating non-running instance
                try:
                    self.connection.terminate_instances(
                        InstanceIds=[ instance_info['InstanceId'] ]
                    )
                    self.iam.printer('Instance %s is terminating.' % instance_info['InstanceId'])
                except:
                    pass

    # find non-available images
        response = self.connection.describe_images(
            Owners=[ self.iam.owner_id ]
        )
        image_list = response['Images']
        for image in image_list:
            image_info = image.copy()
            if image_info['State'] == 'pending':
                self.check_image_state(image_info['ImageId'])
                response = self.connection.describe_images(
                    ImageIds=[ image_info['ImageId'] ]
                )
                image_info = response['Images'][0]
            if image_info['State'] != 'available':

    # try removing tags from non-available images
                try:
                    response = self.connection.describe_images(
                        ImageIds=[ image_info['ImageId'] ]
                    )
                    image_tags = response['Images'][0]['Tags']
                    tag_list = []
                    for i in range(0, len(image_tags)):
                        tag = {}
                        tag['Key'] = image_tags[i]['Key']
                        tag['Value'] = image_tags[i]['Value']
                        tag_list.append(tag)
                    self.connection.delete_tags(
                        Resources=[ image_info['ImageId'] ],
                        Tags=tag_list
                    )
                    self.iam.printer('Tags have been deleted from image %s.' % image_info['ImageId'])
                except:
                    pass

    # try deregistering non-available image
                try:
                    self.connection.deregister_image(
                        ImageId=image_info['ImageId']
                    )
                    self.iam.printer('Image %s has been deregistered.' % image_info['ImageId'])
                except:
                    pass

    # try deleting snapshot associated with non-available image
                try:
                    self.connection.delete_snapshot(
                        SnapshotId=image_info['BlockDeviceMappings'][0]['Ebs']['SnapshotId']
                    )
                    snap_id = image_info['BlockDeviceMappings'][0]['Ebs']['SnapshotId']
                    image_id = image_info['ImageId']
                    self.iam.printer('Snapshot %s associated with image %s has been deleted.' % (snap_id, image_id))
                except:
                    pass

    # find snapshots with errors
        response = self.connection.describe_snapshots(
            OwnerIds=[ self.iam.owner_id ]
        )
        snapshot_list = response['Snapshots']
        for snapshot in snapshot_list:
            snapshot_info = snapshot.copy()
            if snapshot_info['State'] == 'error':

    # try deleting snapshot with errors
                try:
                    self.connection.delete_snapshot(
                        SnapshotId=snapshot_info['SnapshotId']
                    )
                    self.iam.printer('Snapshot %s has been deleted.' % snapshot_info['SnapshotId'])
                except:
                    pass

        return True
287452
def db_aws_delete_instance(self, instance_id):
        '''  '''
        interactive = False
        if instance_id is None:
            interactive = True

        instances = self.db_services.get_db_instances()
        instance_list = [dbinst.id for dbinst in instances]

        if interactive:
            valid = False
            if len(instances) == 0:
                print("There are no instances you can delete currently.  Use "
                      "`db aws_create_instance` to make one.")
                return
            print "Here are the available instances you can delete:"
            for inst in instances:
                print "\t ", inst.id, "(", inst.status, ")"
            while not valid:
                instance_id = raw_input('Enter the instance identity you would '
                                        'like to delete: ')
                res = self.db_services.validate_instance_id(instance_id)
                if res is True:
                    valid = True
                else:
                    print(res + " Try again, instance name not valid.  Check " \
                        "for typos.")
                if instance_id in instance_list:
                    valid = True
                else:
                    valid = False
                    print("Try again, instance not present in this account.  "
                          "Try again checking for typos.")
        else:
            res = self.db_services.validate_instance_id(instance_id)
            if res is not True:
                print("*** Error, instance name either not valid.  Try again "
                     "checking for typos.")
                return
            if instance_id not in instance_list:
                print("*** Error, This instance not present in this account.  "
                     "Try again checking for typos.  Run `db aws_list_instances` to "
                     "see valid list.")
                return

        user_input = raw_input(
            "Deleting an instance will erase all your data associated with the "
            "database in that instance.  Really quit? y or n:"
        )
        if user_input == 'y':
            res = self.db_services.delete_db_instance(instance_id)
            if res:
                print("AWS RDS database instance %s deleted.  Run `db " \
                    "aws_list_instances` for current status." % instance_id)
            else:
                print("*** Error deleting database instance %s.  " \
                    "It maybe because it is still being created, deleted, or is " \
                    "being backed up.  Run `db aws_list_instances` for current " \
                    "status." % instance_id)
        else:
            return
180864
def stop(args):
    
    p = OptionParser(stop.__doc__)
    p.add_option("--profile", default="mvrad-datasci-role", help="Profile name")
    opts, args = p.parse_args(args)

    if len(args) != 0:
        sys.exit(not p.print_help())

    role(["htang"])
    session = boto3.Session(profile_name=opts.profile)
    client = session.client('ec2')
    s = InstanceSkeleton()

    # Make sure the instance id is NOT empty
    instance_id = s.instance_id
    if instance_id == "":
        logging.error("Cannot find instance_id {}".format(instance_id))
        sys.exit(1)

    block_device_mappings = []
    for volume in s.volumes:
        block_device_mappings.append(
            {
                "DeviceName": volume["Device"],
                "NoDevice": ""
            }
        )

    new_image_name = "htang-dev-{}-{}".format(timestamp(), int(time.time()))
    response = client.create_image(
        InstanceId=instance_id,
        Name=new_image_name,
        BlockDeviceMappings=block_device_mappings
    )
    print(response, file=sys.stderr)
    new_image_id = response["ImageId"]

    image_status = ""
    while image_status != "available":
        logging.debug("Waiting for image to be ready")
        time.sleep(10)
        response = client.describe_images(ImageIds=[new_image_id])
        image_status = response["Images"][0]["State"]

    # Delete old image, snapshot and shut down instance
    old_image_id = s.image_id
    response = client.describe_images(ImageIds=[old_image_id])
    old_snapshot_id = response["Images"][0]["BlockDeviceMappings"][0]["Ebs"]["SnapshotId"]
    response = client.deregister_image(ImageId=old_image_id)
    print(response, file=sys.stderr)
    response = client.delete_snapshot(SnapshotId=old_snapshot_id)
    print(response, file=sys.stderr)
    response = client.terminate_instances(InstanceIds=[instance_id])
    print(response, file=sys.stderr)

    # Save new image id
    s.save_image_id(new_image_id)
    s.save_instance_id("", "")
15384
def _stop_instance(self):
        
        try:
            vm_stop = self.compute.virtual_machines.power_off(
                self.running_instance_id, self.running_instance_id
            )
        except Exception as error:
            raise AzureCloudException(
                'Unable to stop instance: {0}.'.format(error)
            )

        vm_stop.wait()
667977
def shutdown_instances(self):
        
        self.min_size = 0
        self.max_size = 0
        self.desired_capacity = 0
        self.update()
442088
def down_ec2(connection, instance_id, region, log=False):
    
    # get the instance_id from the state file, and stop the instance
    instance = connection.stop_instances(instance_ids=instance_id)[0]
    while instance.state != "stopped":
        if log:
            log_yellow("Instance state: %s" % instance.state)
        sleep(10)
        instance.update()
    if log:
        log_green('Instance state: %s' % instance.state)
1047393
def resume(instance_id, profile=None, **kwargs):
    '''
    

    '''
    conn = _auth(profile, **kwargs)
    return conn.resume(instance_id)
362042
public void stop() {
    syncLock.lock();
    try {
      if (syncThread == null) {
        return;
      }
      instanceChangeStreamListener.stop();
      syncThread.interrupt();
      try {
        syncThread.join();
      } catch (final InterruptedException e) {
        return;
      }
      syncThread = null;
      isRunning = false;
    } finally {
      syncLock.unlock();
    }
  }
879124
def remove(self, server_id):
        
        server = self._storage.pop(server_id)
        server.stop()
        server.cleanup()
810708
def stop_instance(self, instance_id):
        
        self._restore_from_storage(instance_id)
        if self._start_failed:
            raise Exception('stop_instance for node %s: failing due to'
                            ' previous errors.' % instance_id)

        with self._resource_lock:
            try:
                v_m = self._qualified_name_to_vm(instance_id)
                if not v_m:
                    err = "stop_instance: can't find instance %s" % instance_id
                    log.error(err)
                    raise Exception(err)
                v_m._cloud_service._stop_vm(v_m)
                # note: self._n_instances is a derived property, doesn't need
                # to be updated
                if self._n_instances == 0:
                    log.debug('last instance deleted, destroying '
                              'global resources')
                    self._delete_global_reqs()
                    self._delete_cloud_provider_storage()
            except Exception as exc:
                log.error(traceback.format_exc())
                log.error("error stopping instance %s: %s", instance_id, exc)
                raise
        log.debug('stopped instance %s', instance_id)
1270567
def delete_instance(self, uid):
        
        uri = "%s/%s" % (self.uri, uid)
        response, instance = self.request("DELETE", uri)
        return response.status == 204
997224
def stop(self):
        
        if self._fd is not None:
            self._pollobj.unregister(self._fd)
            os.close(self._fd)
            self._fd = None
        self._sys_proc_fun = None