def create(vm_):
    '''
    Create a single instance from a data dict.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -p qingcloud-ubuntu-c1m1 hostname1
        salt-cloud -m /path/to/mymap.sls -P
    '''
    try:
        # Check for required profile parameters before sending any API calls.
        if vm_['profile'] and config.is_profile_configured(__opts__,
                                                           __active_provider_name__ or 'qingcloud',
                                                           vm_['profile'],
                                                           vm_=vm_) is False:
            return False
    except AttributeError:
        pass

    __utils__['cloud.fire_event'](
        'event',
        'starting create',
        'salt/cloud/{0}/creating'.format(vm_['name']),
        args=__utils__['cloud.filter_event']('creating', vm_, ['name', 'profile', 'provider', 'driver']),
        sock_dir=__opts__['sock_dir'],
        transport=__opts__['transport']
    )

    log.info('Creating Cloud VM %s', vm_['name'])

    # params
    params = {
        'action': 'RunInstances',
        'instance_name': vm_['name'],
        'zone': _get_location(vm_),
        'instance_type': _get_size(vm_),
        'image_id': _get_image(vm_),
        'vxnets.1': vm_['vxnets'],
        'login_mode': vm_['login_mode'],
        'login_keypair': vm_['login_keypair'],
    }

    __utils__['cloud.fire_event'](
        'event',
        'requesting instance',
        'salt/cloud/{0}/requesting'.format(vm_['name']),
        args={
            'kwargs': __utils__['cloud.filter_event']('requesting', params, list(params)),
        },
        sock_dir=__opts__['sock_dir'],
        transport=__opts__['transport']
    )

    result = query(params)
    new_instance_id = result['instances'][0]

    try:
        data = salt.utils.cloud.wait_for_ip(
            _query_node_data,
            update_args=(new_instance_id,),
            timeout=config.get_cloud_config_value(
                'wait_for_ip_timeout', vm_, __opts__, default=10 * 60
            ),
            interval=config.get_cloud_config_value(
                'wait_for_ip_interval', vm_, __opts__, default=10
            ),
        )
    except (SaltCloudExecutionTimeout, SaltCloudExecutionFailure) as exc:
        try:
            # It might be already up, let's destroy it!
            destroy(vm_['name'])
        except SaltCloudSystemExit:
            pass
        finally:
            raise SaltCloudSystemExit(six.text_type(exc))

    private_ip = data['private_ips'][0]

    log.debug('VM %s is now running', private_ip)

    vm_['ssh_host'] = private_ip

    # The instance is booted and accessible, let's Salt it!
    __utils__['cloud.bootstrap'](vm_, __opts__)

    log.info('Created Cloud VM \'%s\'', vm_['name'])

    log.debug('\'%s\' VM creation details:\n%s', vm_['name'], pprint.pformat(data))

    __utils__['cloud.fire_event'](
        'event',
        'created instance',
        'salt/cloud/{0}/created'.format(vm_['name']),
        args=__utils__['cloud.filter_event']('created', vm_, ['name', 'profile', 'provider', 'driver']),
        sock_dir=__opts__['sock_dir'],
        transport=__opts__['transport']
    )

    return data
def create ( vm_ ) : try : if vm_ [ 'profile' ] and config . is_profile_configured ( __opts__ , __active_provider_name__ or 'qingcloud' , vm_ [ 'profile' ] , vm_ = vm_ ) is False : return False except AttributeError : pass __utils__ [ 'cloud.fire_event' ] ( 'event' , 'starting create' , 'salt/cloud/{0}/creating' . format ( vm_ [ 'name' ] ) , args = __utils__ [ 'cloud.filter_event' ] ( 'creating' , vm_ , [ 'name' , 'profile' , 'provider' , 'driver' ] ) , sock_dir = __opts__ [ 'sock_dir' ] , transport = __opts__ [ 'transport' ] ) log . info ( 'Creating Cloud VM %s' , vm_ [ 'name' ] ) params = { 'action' : 'RunInstances' , 'instance_name' : vm_ [ 'name' ] , 'zone' : _get_location ( vm_ ) , 'instance_type' : _get_size ( vm_ ) , 'image_id' : _get_image ( vm_ ) , 'vxnets.1' : vm_ [ 'vxnets' ] , 'login_mode' : vm_ [ 'login_mode' ] , 'login_keypair' : vm_ [ 'login_keypair' ] , } __utils__ [ 'cloud.fire_event' ] ( 'event' , 'requesting instance' , 'salt/cloud/{0}/requesting' . format ( vm_ [ 'name' ] ) , args = { 'kwargs' : __utils__ [ 'cloud.filter_event' ] ( 'requesting' , params , list ( params ) ) , } , sock_dir = __opts__ [ 'sock_dir' ] , transport = __opts__ [ 'transport' ] ) result = query ( params ) new_instance_id = result [ 'instances' ] [ 0 ] try : data = salt . utils . cloud . wait_for_ip ( _query_node_data , update_args = ( new_instance_id , ) , timeout = config . get_cloud_config_value ( 'wait_for_ip_timeout' , vm_ , __opts__ , default = 10 * 60 ) , interval = config . get_cloud_config_value ( 'wait_for_ip_interval' , vm_ , __opts__ , default = 10 ) , ) except ( SaltCloudExecutionTimeout , SaltCloudExecutionFailure ) as exc : try : destroy ( vm_ [ 'name' ] ) except SaltCloudSystemExit : pass finally : raise SaltCloudSystemExit ( six . text_type ( exc ) ) private_ip = data [ 'private_ips' ] [ 0 ] log . debug ( 'VM %s is now running' , private_ip ) vm_ [ 'ssh_host' ] = private_ip __utils__ [ 'cloud.bootstrap' ] ( vm_ , __opts__ ) log . info ( 'Created Cloud VM \'%s\'' , vm_ [ 'name' ] ) log . debug ( '\'%s\' VM creation details:\n%s' , vm_ [ 'name' ] , pprint . pformat ( data ) ) __utils__ [ 'cloud.fire_event' ] ( 'event' , 'created instance' , 'salt/cloud/{0}/created' . format ( vm_ [ 'name' ] ) , args = __utils__ [ 'cloud.filter_event' ] ( 'created' , vm_ , [ 'name' , 'profile' , 'provider' , 'driver' ] ) , sock_dir = __opts__ [ 'sock_dir' ] , transport = __opts__ [ 'transport' ] ) return data
Create a single instance from a data dict.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -p qingcloud-ubuntu-c1m1 hostname1
        salt-cloud -m /path/to/mymap.sls -P