示例#1
0
def allocate_floating_task(floating=None):
    rc = create_rc_by_floating(floating)
    LOG.info("Begin to allocate floating, [%s]" % floating.id);
    pools = network.floating_ip_pools_list(rc)
    ext_net = filter(lambda n: n.name.lower() == \
                    floating.user_data_center.data_center.ext_net, pools)
    ext_net_id = None
    if ext_net and len(ext_net) > 0:
        ext_net_id = ext_net[0].id
    if ext_net_id: 
        try:
            fip = network.tenant_floating_ip_allocate(rc, pool=ext_net_id)
            floating.ip = fip.ip
            floating.status = FLOATING_AVAILABLE
            floating.uuid = fip.id
            floating.save()
            billing_task.charge_resource(floating.id, Floating)
            LOG.info("End to allocate floating, [%s][%s]" % (floating.id, fip.ip));
        except Exception as e:
            floating.status = FLOATING_ERROR
            floating.save()
            LOG.exception(e)
            LOG.info("End to allocate floating, [%s][exception]" % floating.id);
    else:
        floating.status = FLOATING_ERROR
        floating.save()
        LOG.info("End to allocate floating, [%s][---]" % floating.id);
def instance_create_task(instance, **kwargs):
    password = kwargs.get("password", None)
    assert instance
    assert password

    begin = datetime.datetime.now()
    LOG.info(u"Instance create start, [%s][pwd:%s].",
                        instance, password)
     
    rc = create_rc_by_instance(instance)
    try: 
        flavor = flavor_create(instance)
        instance.flavor_id = flavor.id 
    except Exception:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instance create failed by flavor exception, [%s].",
                        instance)
        return False

    neutron_enabled = neutron.is_neutron_enabled(rc)
    
    if neutron_enabled:
        network = make_sure_default_private_network(instance)
        instance.network_id = network.id
        instance.save() 
        LOG.info(u"Instance create set network passed, [%s][%s].",
                    instance, network)

    if not instance.firewall_group:
        instance.set_default_firewall()
 
    try:
        server = instance_create(instance, password)
    except Exception as ex:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instace create api call raise an exception, [%s][%s].",
                        instance, ex.message)
        return False
    else:
        status = server.status.upper() if server else u"None"
        instance.uuid = server.id
        if status == u"ERROR":
            instance.status = INSTANCE_STATE_ERROR
            instance.save()
            end = datetime.datetime.now()
            LOG.info(u"Instance create api call failed, [%s][%s], "
                     "apply [%s] seconds.",
                    instance, status, (end-begin).seconds)
        else:
            instance.status = INSTANCE_STATE_BOOTING
            instance.save()
            end = datetime.datetime.now()
            LOG.info(u"Instance create api call passed, [%s][%s], "
                    "apply [%s] seconds.",
                    instance, status, (end-begin).seconds)
            time.sleep(settings.INSTANCE_SYNC_INTERVAL_SECOND)
            instance_create_sync_status_task.delay(
                instance, neutron_enabled, retry_count=1)
            billing_task.charge_resource(instance.id, Instance)

    return instance
def instance_create_task(instance, **kwargs):
    password = kwargs.get("password", None)
    assert instance
    assert password

    begin = datetime.datetime.now()
    LOG.info(u"Instance create start, [%s][pwd:%s].", instance, password)

    rc = create_rc_by_instance(instance)
    try:
        flavor = flavor_create(instance)
        instance.flavor_id = flavor.id
    except Exception:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instance create failed by flavor exception, [%s].",
                      instance)
        return False

    neutron_enabled = neutron.is_neutron_enabled(rc)

    if neutron_enabled:
        network = make_sure_default_private_network(instance)
        instance.network_id = network.id
        instance.save()
        LOG.info(u"Instance create set network passed, [%s][%s].", instance,
                 network)

    if not instance.firewall_group:
        instance.set_default_firewall()

    try:
        server = instance_create(instance, password)
    except Exception as ex:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instace create api call raise an exception, [%s][%s].",
                      instance, ex.message)
        return False
    else:
        status = server.status.upper() if server else u"None"
        instance.uuid = server.id
        if status == u"ERROR":
            instance.status = INSTANCE_STATE_ERROR
            instance.save()
            end = datetime.datetime.now()
            LOG.info(
                u"Instance create api call failed, [%s][%s], "
                "apply [%s] seconds.", instance, status, (end - begin).seconds)
        else:
            instance.status = INSTANCE_STATE_BOOTING
            instance.save()
            end = datetime.datetime.now()
            LOG.info(
                u"Instance create api call passed, [%s][%s], "
                "apply [%s] seconds.", instance, status, (end - begin).seconds)
            time.sleep(settings.INSTANCE_SYNC_INTERVAL_SECOND)
            instance_create_sync_status_task.delay(instance,
                                                   neutron_enabled,
                                                   retry_count=1)
            billing_task.charge_resource(instance.id, Instance)

    return instance
示例#4
0
def instance_create_task(instance, **kwargs):
    LOG.info("*************** I am instance create in instance_create_task ****************")
    password = kwargs.get("password", None)
    assert instance
    assert password

    user_tenant_uuid = kwargs.get("user_tenant_uuid", None)
 
    LOG.info("**** user_tenant_uuid in instance_create_task is ****" + str(user_tenant_uuid))
    begin = datetime.datetime.now()
    LOG.info(u"Instance create start, [%s][pwd:%s].",
                        instance, password)
     
    rc = create_rc_by_instance(instance)
    try: 
        flavor = flavor_create(instance)
        instance.flavor_id = flavor.id 
    except Exception:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instance create failed by flavor exception, [%s].",
                        instance)
        return False


    # First check if network exists or not.
    neutron_enabled = neutron.is_neutron_enabled(rc)
    LOG.info("********** check neutron is enabled or not **************" + str(neutron_enabled))
    
    # If not exists, create a new one for that tenant.
    if neutron_enabled:
        LOG.info("********** neutron_enabled *************")
        LOG.info("********** start to make sure make_sure_default_private_network ***********")
        network = make_sure_default_private_network(instance, rc, user_tenant_uuid)
        #network = neutron.network_list_for_tenant(rc, tenant_id=user_tenant_uuid)
        #LOG.info("********** network is ******************" + str(network))
        #network_id = None
        #for net in network:
        #    LOG.info("***** net is *******" + str(net))
        #    network_id = net.id
        #LOG.info("********* network_id is *********" + str(network_id))
        LOG.info("**** network is ****" + str(network))
        instance.network_id = network.id
        instance.save() 
        LOG.info(u"Instance create set network passed, [%s][%s].",
                    instance, network)

    if not instance.firewall_group:
        LOG.info("********** start to set default firewall ************")
        instance.set_default_firewall()
 
    try:
        LOG.info("********** start to create instance *****************")
        server = instance_create(instance, password)
    except Exception as ex:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instace create api call raise an exception, [%s][%s].",
                        instance, ex.message)
        return False
    else:
        status = server.status.upper() if server else u"None"
        instance.uuid = server.id
        if status == u"ERROR":
            instance.status = INSTANCE_STATE_ERROR
            instance.save()
            end = datetime.datetime.now()
            LOG.info(u"Instance create api call failed, [%s][%s], "
                     "apply [%s] seconds.",
                    instance, status, (end-begin).seconds)
        else:
            instance.status = INSTANCE_STATE_BOOTING
            instance.save()
            end = datetime.datetime.now()
            LOG.info(u"Instance create api call passed, [%s][%s], "
                    "apply [%s] seconds.",
                    instance, status, (end-begin).seconds)
            time.sleep(settings.INSTANCE_SYNC_INTERVAL_SECOND)
            instance_create_sync_status_task.delay(
                instance, neutron_enabled, user_tenant_uuid, rc, retry_count=1)
            billing_task.charge_resource(instance.id, Instance)

    return instance
示例#5
0
def instance_create_task(instance, **kwargs):
    LOG.info(
        "*************** I am instance create in instance_create_task ****************"
    )
    password = kwargs.get("password", None)
    assert instance
    assert password

    user_tenant_uuid = kwargs.get("user_tenant_uuid", None)

    LOG.info("**** user_tenant_uuid in instance_create_task is ****" +
             str(user_tenant_uuid))
    begin = datetime.datetime.now()
    LOG.info(u"Instance create start, [%s][pwd:%s].", instance, password)

    rc = create_rc_by_instance(instance)
    try:
        flavor = flavor_create(instance)
        instance.flavor_id = flavor.id
    except Exception:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instance create failed by flavor exception, [%s].",
                      instance)
        return False

    # First check if network exists or not.
    neutron_enabled = neutron.is_neutron_enabled(rc)
    LOG.info("********** check neutron is enabled or not **************" +
             str(neutron_enabled))

    # If not exists, create a new one for that tenant.
    if neutron_enabled:
        LOG.info("********** neutron_enabled *************")
        LOG.info(
            "********** start to make sure make_sure_default_private_network ***********"
        )
        network = make_sure_default_private_network(instance, rc,
                                                    user_tenant_uuid)
        #network = neutron.network_list_for_tenant(rc, tenant_id=user_tenant_uuid)
        #LOG.info("********** network is ******************" + str(network))
        #network_id = None
        #for net in network:
        #    LOG.info("***** net is *******" + str(net))
        #    network_id = net.id
        #LOG.info("********* network_id is *********" + str(network_id))
        LOG.info("**** network is ****" + str(network))
        instance.network_id = network.id
        instance.save()
        LOG.info(u"Instance create set network passed, [%s][%s].", instance,
                 network)

    if not instance.firewall_group:
        LOG.info("********** start to set default firewall ************")
        instance.set_default_firewall()

    try:
        LOG.info("********** start to create instance *****************")
        server = instance_create(instance, password)
    except Exception as ex:
        instance.status = INSTANCE_STATE_ERROR
        instance.save()
        LOG.exception(u"Instace create api call raise an exception, [%s][%s].",
                      instance, ex.message)
        return False
    else:
        status = server.status.upper() if server else u"None"
        instance.uuid = server.id
        if status == u"ERROR":
            instance.status = INSTANCE_STATE_ERROR
            instance.save()
            end = datetime.datetime.now()
            LOG.info(
                u"Instance create api call failed, [%s][%s], "
                "apply [%s] seconds.", instance, status, (end - begin).seconds)
        else:
            instance.status = INSTANCE_STATE_BOOTING
            instance.save()
            end = datetime.datetime.now()
            LOG.info(
                u"Instance create api call passed, [%s][%s], "
                "apply [%s] seconds.", instance, status, (end - begin).seconds)
            time.sleep(settings.INSTANCE_SYNC_INTERVAL_SECOND)
            instance_create_sync_status_task.delay(instance,
                                                   neutron_enabled,
                                                   user_tenant_uuid,
                                                   rc,
                                                   retry_count=1)
            billing_task.charge_resource(instance.id, Instance)

    return instance