Ejemplo n.º 1
0
static int network_op(char * name, int op)
{
	virNetworkPtr net;
	virConnectPtr conn;
	int ret;
	
	conn = virConnectOpen("qemu:///system");
	if (conn == NULL) 
	{
		fprintf(stderr, "Failed to open connection to qemu:///system\n");
		return -1;
	}
	
	net = virNetworkLookupByName(conn, name);
	if (net == NULL) 
	{
		printf("network is not found\n");
		virConnectClose(conn);
		return -1;
	}

	if (op == NETWORK_DESTROY)
		ret = virNetworkDestroy(net);
	else if (op == NETWORK_SET_AUTOSTART)
		ret = virNetworkSetAutostart(net, 1);
	else if (op == NETWORK_UNSET_AUTOSTART)
		ret = virNetworkSetAutostart(net, 0);
	else
		ret = -1;
		
	virNetworkFree(net);
	virConnectClose(conn);
	
	return ret;
}
Ejemplo n.º 2
0
static bool
cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
{
    virNetworkPtr network;
    const char *name;
    int autostart;

    if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
        return false;

    autostart = !vshCommandOptBool(cmd, "disable");

    if (virNetworkSetAutostart(network, autostart) < 0) {
        if (autostart)
            vshError(ctl, _("failed to mark network %s as autostarted"), name);
        else
            vshError(ctl, _("failed to unmark network %s as autostarted"), name);
        virNetworkFree(network);
        return false;
    }

    if (autostart)
        vshPrint(ctl, _("Network %s marked as autostarted\n"), name);
    else
        vshPrint(ctl, _("Network %s unmarked as autostarted\n"), name);

    virNetworkFree(network);
    return true;
}
Result NetControlThread::changeAutoStartNetwork()
{
    Result result;
    QString name = task.object;
    result.name = name;
    int autostart = task.args.sign;
    bool set = false;
    if ( task.srcConnPtr==nullptr ) {
        result.result = false;
        result.err = "Connection pointer is NULL.";
        return result;
    };
    virNetworkPtr network = virNetworkLookupByName(
                *task.srcConnPtr, name.toUtf8().data());
    if ( network!=nullptr ) {
        set = (virNetworkSetAutostart(network, autostart)+1) ? true : false;
        if (!set)
            result.err = sendConnErrors();
        virNetworkFree(network);
    } else
        result.err = sendConnErrors();
    result.result = set;
    result.msg.append(QString("'<b>%1</b>' Network autostart %2 Set.")
                      .arg(name).arg((set)?"":"don't"));
    return result;
}