Beispiel #1
0
static int
mymain(void)
{
    int id = 0;
    int ro = 0;
    virConnectPtr conn;
    virDomainPtr dom;
    int status;
    virCommandPtr cmd;
    struct utsname ut;

    /* Skip test if xend is not running.  Calling xend on a non-xen
       kernel causes some versions of xend to issue a crash report, so
       we first probe uname results.  */
    uname(&ut);
    if (strstr(ut.release, "xen") == NULL)
        return EXIT_AM_SKIP;
    cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
    if (virCommandRun(cmd, &status) != 0 || status != 0) {
        virCommandFree(cmd);
        return EXIT_AM_SKIP;
    }
    virCommandFree(cmd);

    virSetErrorFunc(NULL, errorHandler);

    conn = virConnectOpen(NULL);
    if (conn == NULL) {
        ro = 1;
        conn = virConnectOpenReadOnly(NULL);
    }
    if (conn == NULL) {
        fprintf(stderr, "First virConnectOpen() failed\n");
        return EXIT_FAILURE;
    }
    dom = virDomainLookupByID(conn, id);
    if (dom == NULL) {
        fprintf(stderr, "First lookup for domain %d failed\n", id);
        return EXIT_FAILURE;
    }
    virDomainFree(dom);
    virConnectClose(conn);
    if (ro == 1)
        conn = virConnectOpenReadOnly(NULL);
    else
        conn = virConnectOpen(NULL);
    if (conn == NULL) {
        fprintf(stderr, "Second virConnectOpen() failed\n");
        return EXIT_FAILURE;
    }
    dom = virDomainLookupByID(conn, id);
    if (dom == NULL) {
        fprintf(stderr, "Second lookup for domain %d failed\n", id);
        return EXIT_FAILURE;
    }
    virDomainFree(dom);
    virConnectClose(conn);

    return EXIT_SUCCESS;
}
Beispiel #2
0
void main(int argc, char *argv[]) {
	char *myIP;
	if (argc<2)
		printf("arg1=myip\n"),exit(-128);
	myIP = argv[1];

	if (fork() == 0) {
		// Child
		virConnectPtr localhost = virConnectOpen("qemu:///system");
		while(1) {
			int alive = virConnectIsAlive(localhost);
			if (alive == 0) {
				printf("Connection lost, reopening.\n");
				virConnectClose(localhost);
				localhost = virConnectOpen("qemu:///system");
			} else if (alive == -1) {
				printf("Connection dead.\n");
				virConnectClose(localhost);
				localhost = virConnectOpen("qemu:///system");
				sleep(3);
				continue;
			}
			printf("*** connected\n");
			run(myIP, localhost);
			sleep(1);
		}
		virConnectClose(localhost);
	}
	exit(0);
}
Beispiel #3
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;
}
Beispiel #4
0
int libvirt_connect(int driver)
{
    if (g_conn != NULL) {
        logwarn(_("conneted already.\n"));
        return -1;
    }

    virSetErrorFunc(NULL, __customErrorFunc);

    const char * URI;
    if (driver == HYPERVISOR_IS_KVM)
        URI = HYPERVISOR_URI_KVM;
    else if (driver == HYPERVISOR_IS_XEN)
        URI = HYPERVISOR_URI_XEN;
    else {
        logerror(_("unrecognized hypervisor driver(%d).\n"), driver);
        return -1;
    }

    __this_lock();
    g_conn = virConnectOpen(URI);
    __this_unlock();
    if (g_conn == NULL) {
        logerror(_("Connet to %s error.\n"), URI);
        return -1;
    } 
    else {
        loginfo(_("Connect to %s success!\n"), URI);
    }

    return 0;
}
Beispiel #5
0
int libvirt_check(int driver)
{
    virSetErrorFunc(NULL, __customErrorFunc);

    const char * URI;
    if (driver == HYPERVISOR_IS_KVM)
        URI = HYPERVISOR_URI_KVM;
    else if (driver == HYPERVISOR_IS_XEN)
        URI = HYPERVISOR_URI_XEN;
    else {
        logerror(_("unrecognized hypervisor driver(%d).\n"), driver);
        return -1;
    }

    virConnectPtr conn = virConnectOpen(URI);
    if (conn == NULL) {
        logerror(_("Connect to %s error.\n"), URI);
        return -1;
    }

    int numDomains = virConnectNumOfDomains(conn);
    if (numDomains < 0) {
        logerror(_("Connect to %s error.\n"), URI);
        return -1;
    }

    virConnectClose(conn);

    return 0;
}
Beispiel #6
0
/**
 * virNWFilterReload:
 *
 * Function to restart the nwfilter driver, it will recheck the configuration
 * files and update its state
 */
static int
nwfilterDriverReload(void) {
    virConnectPtr conn;

    if (!driverState) {
        return -1;
    }

    conn = virConnectOpen("qemu:///system");

    if (conn) {
        /* shut down all threads -- they will be restarted if necessary */
        virNWFilterLearnThreadsTerminate(true);

        nwfilterDriverLock(driverState);
        virNWFilterCallbackDriversLock();

        virNWFilterLoadAllConfigs(conn,
                                  &driverState->nwfilters,
                                  driverState->configDir);

        virNWFilterCallbackDriversUnlock();
        nwfilterDriverUnlock(driverState);

        virConnectClose(conn);
    }

    return 0;
}
Beispiel #7
0
int main(int argc, char *argv[])
{
virConnectPtr conn;
int i;
int numDomains;
int *activeDomains;
virDomainPtr dom;
conn = virConnectOpen("qemu:///system");
if (conn == NULL) {
fprintf(stderr, "Failed to open connection to qemu:///system\n");
}
numDomains = virConnectNumOfDomains(conn);
activeDomains = malloc(sizeof(int) * numDomains);
numDomains = virConnectListDomains(conn, activeDomains, numDomains);
printf("Active domain IDs:\n");
for (i = 0 ; i < numDomains ; i++) {
printf(" %d\n", activeDomains[i]);
}
printf("Terminating Domain\n");
free(activeDomains);
int domainName = "sudip";
dom = virDomainLookupByName(conn,domainName);
virDomainDestroy(dom);
virDomainFree(dom);
printf("Domain sudip terminated successfully\n");

if (conn != NULL)
virConnectClose(conn);
return 0;
}
Beispiel #8
0
Datei: virt.cpp Projekt: kohn/rsi
VM_Controller::VM_Controller(){
    _conn = virConnectOpen("qemu:///system");
    if(_conn == NULL){
        LOG_ERROR("could not open libvirt connection");
        exit(-1);
    }
}
Beispiel #9
0
static int
mymain(void)
{
    struct metadataTest test;
    int ret = EXIT_SUCCESS;

    if (!(test.conn = virConnectOpen("test:///default")))
        return EXIT_FAILURE;

    if (!(test.dom = virDomainLookupByName(test.conn, "test"))) {
        virConnectClose(test.conn);
        return EXIT_FAILURE;
    }

    virtTestQuiesceLibvirtErrors(false);

    if (virtTestRun("Assign metadata ", testAssignMetadata, &test) < 0)
        ret = EXIT_FAILURE;
    if (virtTestRun("Rewrite Metadata ", testRewriteMetadata, &test) < 0)
        ret = EXIT_FAILURE;
    if (virtTestRun("Erase metadata ", testEraseMetadata, &test) < 0)
        ret = EXIT_FAILURE;

    virDomainFree(test.dom);
    virConnectClose(test.conn);

    return ret;
}
Beispiel #10
0
static int dominfo_from_dom(const char *uri,
                            const char *domain,
                            struct domain **d)
{
        virConnectPtr conn = NULL;
        virDomainPtr dom = NULL;
        int ret = 0;

        conn = virConnectOpen(uri);
        if (conn == NULL) {
                printf("Unable to connect to libvirt\n");
                goto out;
        }

        dom = virDomainLookupByName(conn, domain);
        if (dom == NULL) {
                printf("Unable to find domain `%s'\n", domain);
                goto out;
        }

        ret = get_dominfo(dom, d);

 out:
        virDomainFree(dom);
        virConnectClose(conn);

        return ret;
}
void libvirt_connect() {
    int i;
    int *activeDomainIDs;

    // connect to xend
    conn = virConnectOpen("xen:///");
    if (conn == NULL) {
        printf("Failed to open connection to xen");
        exit(0);
    }

    // get the Domain ID list
    numDomains = virConnectNumOfDomains(conn);
    activeDomainIDs = (int*) malloc(sizeof(int) * numDomains);
    activeDomains = (virDomainPtr*) malloc(sizeof(virDomainPtr) * numDomains);
    numDomains = virConnectListDomains(conn, activeDomainIDs, numDomains);

    // associate the Domain ID list to Domain name list
    printf("Active domain IDs:\n");
    for (i = 0; i < numDomains; i++) {
        activeDomains[i] = virDomainLookupByID(conn, activeDomainIDs[i]);
        printf("  [%s - %d]\n", virDomainGetName(activeDomains[i]), activeDomainIDs[i]);
    }

    // Domain ID list is useless
    free(activeDomainIDs);
}
Beispiel #12
0
GetVirtInfo::GetVirtInfo()
{
    conn = virConnectOpen("qemu:///system");
    if(conn == NULL) {
        qDebug() << "error connecting qemu driver\n";
        exit(1);
    }
}
Beispiel #13
0
void main(int argc, char *argv[]) {
	if(argc <= 1)
		printf("usage: deletedom domname\n"),exit(-1);

	char **hosts = gethosts();
	char **hostsptr = hosts;
	virConnectPtr *dests = (virConnectPtr*)malloc(sizeof(virConnectPtr)*1024);
	virConnectPtr *destsptr = dests;
	while(*hostsptr != NULL) {
		printf("Adding vmhost %s\n", *hostsptr);
		char URL[512];
		sprintf(URL, "qemu+ssh://%s/system", *hostsptr);
		virConnectPtr dest = virConnectOpen(URL);
		*(destsptr++) = dest;
		*destsptr = NULL;
		hostsptr++;
	}

	char *searched_name = argv[1];

        virConnectPtr src = virConnectOpen("qemu:///system");

	virDomainPtr *domains, *domainsptr;
        virConnectListAllDomains(src, &domains, VIR_CONNECT_LIST_DOMAINS_ACTIVE|VIR_CONNECT_LIST_DOMAINS_INACTIVE|VIR_CONNECT_LIST_DOMAINS_RUNNING|VIR_CONNECT_LIST_DOMAINS_SHUTOFF|VIR_CONNECT_LIST_DOMAINS_PERSISTENT|VIR_CONNECT_LIST_DOMAINS_OTHER|VIR_CONNECT_LIST_DOMAINS_TRANSIENT|VIR_CONNECT_LIST_DOMAINS_PAUSED);
        domainsptr = domains;

	while(*domainsptr != NULL) {
		virDomainPtr d = *domainsptr;
		const char *name = virDomainGetName(d);
		
		if (!strcmp(name, searched_name)) {
			printf("Found it!\n");
			destsptr = dests;
			char uuid[VIR_UUID_BUFLEN];
			virDomainGetUUID(*domainsptr, uuid);
			while(*destsptr != NULL) {
				virDomainPtr target=virDomainLookupByUUID(*destsptr, uuid);
				virDomainSetMetadata(target, VIR_DOMAIN_METADATA_ELEMENT, "<value>1</value>", "do_delete", "/do_delete", VIR_DOMAIN_AFFECT_CURRENT);
				destsptr++;
			}
			virDomainSetMetadata(d, VIR_DOMAIN_METADATA_ELEMENT, "<value>1</value>", "do_delete", "/do_delete", VIR_DOMAIN_AFFECT_CURRENT);
			
		}
		domainsptr++;
	}
}
Beispiel #14
0
bool
XenType::killVMFast(const char* vmname)
{
	vmprintf(D_FULLDEBUG, "Inside XenType::killVMFast\n");
	priv_state priv = set_root_priv();
	virConnectPtr libvirt_connection = virConnectOpen("xen:///");
	set_priv(priv);
	return VirshType::killVMFast(vmname, libvirt_connection);
}
Beispiel #15
0
static void
cpg_virt_init_libvirt(struct cpg_info *info) {
	config_object_t *config = info->config;
	int i = 0;

	if (info->vp) {
		dbg_printf(2, "Lost libvirtd connection. Reinitializing.\n");
		for (i = 0 ; i < info->vp_count ; i++)
			virConnectClose(info->vp[i]);
		free(info->vp);
		info->vp = NULL;
	}
	info->vp_count = 0;

	do {
		virConnectPtr vp;
		virConnectPtr *vpl = NULL;
		char conf_attr[256];
		char value[1024];
		char *uri;

		if (i != 0) {
			snprintf(conf_attr, sizeof(conf_attr),
				"backends/cpg/@uri%d", i);
		} else
			snprintf(conf_attr, sizeof(conf_attr), "backends/cpg/@uri");
		++i;

		if (sc_get(config, conf_attr, value, sizeof(value)) != 0)
			break;

		uri = value;
		vp = virConnectOpen(uri);
		if (!vp) {
			dbg_printf(1, "[cpg-virt:INIT] Failed to connect to URI: %s\n", uri);
			continue;
		}

		vpl = realloc(info->vp, sizeof(*info->vp) * (info->vp_count + 1));
		if (!vpl) {
			dbg_printf(1, "[cpg-virt:INIT] Out of memory allocating URI: %s\n",
				uri);
			virConnectClose(vp);
			continue;
		}

		info->vp = vpl;
		info->vp[info->vp_count++] = vp;

		if (i > 1)
			dbg_printf(1, "[cpg-virt:INIT] Added URI%d %s\n", i - 1, uri);
		else
			dbg_printf(1, "[cpg_virt:INIT] Added URI %s\n", uri);
	} while (1);
}
Beispiel #16
0
int main(int argc, char *argv[])
{
	virConnectPtr conn;
	int i;
	int numDomains;
	int *activeDomains;
	char **inactiveDomains;
	
	conn = virConnectOpen("qemu:///system");
	if (conn == NULL) 
	{
		fprintf(stderr, "Failed to open connection to qemu:///system\n");
		return -1;
	}

	numDomains = virConnectNumOfDomains(conn);
	if (numDomains == -1) 
	{
		fprintf(stderr, "Failed to get domian num of qemu\n");
		return -1;
	}
	
	activeDomains = malloc(sizeof(int) * numDomains);
	numDomains = virConnectListDomains(conn, activeDomains, numDomains);
	
	printf("%d Active domain list:\n", numDomains);
	for (i = 0 ; i < numDomains ; i++) 
	{
		printf("ID = %d, Name = %s\n", activeDomains[i], virDomainGetName(virDomainLookupByID(conn, activeDomains[i])));
	}
	free(activeDomains);
	
	printf("----------------------------\n");
	numDomains = virConnectNumOfDefinedDomains(conn);
	
	if (numDomains == -1) 
	{
		fprintf(stderr, "Failed to get defined domian num of qemu\n");
		return -1;
	}
	
	inactiveDomains = malloc(sizeof(char *) * numDomains);
	numDomains = virConnectListDefinedDomains(conn, inactiveDomains, numDomains);
	printf("%d Inactive domain list:\n", numDomains);
	for (i = 0 ; i < numDomains ; i++) 
	{
		/*All inactive domains's id should be 0*/
		printf("ID = %d, Name = %s\n", virDomainGetID(virDomainLookupByName(conn, inactiveDomains[i])), inactiveDomains[i]);
		free(inactiveDomains[i]);
	}
	free(inactiveDomains);
	
	virConnectClose(conn);
	return 0;
}
int main(int argc, char **argv)
{
	if(argc < 4)
	{
		exit(1); 	//error
	}
	
	user_id=atoi(argv[1]);
	clust_id=atoi(argv[2]);
	node_id=atoi(argv[3]);
	
	clusterCfgRead();
	
	
	//virSetErrorFunc(NULL, customGlobalErrorFunc);
	
	virConnectPtr conn;
	
	if (virInitialize() < 0) {
         fprintf(stderr, "Failed to initialize libvirt");
         return 12;
     }

	//virEventRegisterDefaultImpl();
	
    conn = virConnectOpen("qemu:///system"); //xen+unix:///
    if (!conn) {
        printf("error opening\n");
        return 13;
    }

			
	/* coming here we have to  restore the snapshot of the vm  */
	
	// Build the path to restore the  saved snapshot snap$.img [$=node_id]
	char path[512];
	memset(path,0,512);
	sprintf(path,"%s/%d/%d/snap%d.img",clusterHomeDir,user_id,clust_id,node_id);
	
	if( virDomainRestore(conn,path)!=0)
	{
		exit(21);
	}
	
	
	
	/*----------------------------------------------------------	*/
	if (conn && virConnectClose(conn) < 0){
        printf("error closing\n");
        return 16;
    }
    return 0;
}
Beispiel #18
0
virConnectPtr Openvirt_connect(void)
{
    virConnectPtr conn;
    conn = virConnectOpen("qemu:///system");
    if (conn == NULL) {
        fprintf(stderr, "Failed to open connection to qemu:///system\n");
        perror("virConnectOpen");
        exit -1;
    }
//    virConnectClose(conn);
    return conn;
}
Beispiel #19
0
virConnectPtr *
check_hypervisor_conn()
{
	if (nc_state.conn == NULL || virConnectGetURI(nc_state.conn) == NULL) {
		nc_state.conn = virConnectOpen (nc_state.uri);
		if (nc_state.conn == NULL) {
			logprintfl (EUCAFATAL, "Failed to connect to %s\n", nc_state.uri);
			return NULL;
		}
	}

	return &(nc_state.conn);
}
Beispiel #20
0
int main(int argc, char *argv[])
{
    int start, stop;
	printf("Number for first machine to be created:");
	scanf("%d", &start);
	printf("Number for last machine to be created:");
	scanf("%d", &stop);

	virConnectPtr conn;

	conn = virConnectOpen("qemu:///system");
	if (conn == NULL) {
		fprintf(stderr, "Failed to open connection to qemu:///system\n");
		return 1;
	}

	int i;

	for (i=start;i<=stop;i++) {
		char xml[1024];
		sprintf(xml,
"<domain type='qemu'> \
 <name>microMachine-%d</name> \
 <memory>16384</memory> \
 <vcpu>1</vcpu> \
 <os> \
  <type arch='i686' machine='pc-1.0'>hvm</type> \
  <boot dev='hd'/> \
 </os> \
 <devices> \
  <emulator>/usr/bin/kvm</emulator> \
  <disk type='file' device='disk'> \
   <driver name='qemu' type='raw'/> \
   <source file='/home/jon/serial_print.hda'/> \
   <target dev='hda' bus='ide'/> \
   <address type='drive' controller='0' bus='0' unit='0'/> \
  </disk> \
  <serial type='file'> \
   <source path='/home/jon/logs/output%d.log'/> \
   <target port='1'/> \
  </serial> \
 </devices> \
</domain>", i, i);

		virDomainCreateXML(conn,xml,VIR_DOMAIN_NONE);
	}
	virConnectClose(conn);
	return 0;
}
int main(int argc, char *argv[])
{
    virConnectPtr conn;
    char *host;
    conn = virConnectOpen("xen:///");
    if (conn == NULL) {
        fprintf(stderr, "Failed to open connection to xen:///\n");
        return 1;
    }
    host = virConnectGetHostname(conn);
    fprintf(stdout, "Hostname:%s\n", host);
    free(host);
    virConnectClose(conn);
    return 0;
}
Beispiel #22
0
int main(int argc, char** argv)
{
	if(argc<2) {
		printf("usage: %s uri\n", argv[0]);
		return 1;
	}
	virConnectPtr conn=virConnectOpen(argv[1]);
	int l=virConnectNumOfDefinedDomains(conn);
	char* arr[l];
	l=virConnectListDefinedDomains(conn, arr, l);
	for(int i=0;i<l;i++) {
		printf("%s\n", arr[i]);
	}
	virConnectClose(conn);
}
Beispiel #23
0
int main(int argc,char *argv[]){
    virConnectPtr conn;
    int vcpus;
    
    conn = virConnectOpen("xen:///");
    if(conn==NULL){
        fprintf(stderr,"Failed to open connection to qeme:///system\n");
        return 1;
    }

    vcpus = virConnectGetMaxVcpus(conn,NULL);
    fprintf(stdout,"Maxium support virtual CPUs:%d\n",vcpus);

    virConnectClose(conn);
    return 0;
}
Beispiel #24
0
static void
bhyveAutostartDomains(bhyveConnPtr driver)
{
    /* XXX: Figure out a better way todo this. The domain
     * startup code needs a connection handle in order
     * to lookup the bridge associated with a virtual
     * network
     */
    virConnectPtr conn = virConnectOpen("bhyve:///system");
    /* Ignoring NULL conn which is mostly harmless here */

    struct bhyveAutostartData data = { driver, conn };

    virDomainObjListForEach(driver->domains, bhyveAutostartDomain, &data);

    virObjectUnref(conn);
}
Beispiel #25
0
virConnectPtr libvirtConnect(char *uri)
{
	virConnectPtr cp;

	virSetErrorFunc("vmrunner", errHandler);
	domainIsOff = 0;
	lastErrorCode = 0;
	DPRINTF("Opening connection to hypervisor, uri %s\n", uri ? uri : "probed");
	cp = virConnectOpen(uri);
	if (cp == NULL) {
		DPRINTF("virConnectOpen call failed\n");
		return NULL;
	}

	DPRINTF("Connected to %s\n", virConnectGetURI(cp));
	return cp;
}
Beispiel #26
0
static int
libvirt_init(backend_context_t *c, config_object_t *config)
{
	virConnectPtr vp;
	char value[256];
	struct libvirt_info *info = NULL;
	char *uri = NULL;

	info = malloc(sizeof(*info));
	if (!info)
		return -1;

	dbg_printf(5, "[%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__);
	memset(info, 0, sizeof(*info));

#ifdef _MODULE
	if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0)
		dset(atoi(value));
#endif

	if (sc_get(config, "backends/libvirt/@uri",
		   value, sizeof(value)) == 0) {
		uri = strdup(value);
		if (!uri) {
			free(info);
			return -1;
		}
		dbg_printf(1, "Using %s\n", uri);
	}

	/* We don't need to store the URI; we only use it once */
	vp = virConnectOpen(uri);
	if (!vp) {
		free(uri);
		free(info);
		return -1;
	}
	free(uri);

	info->magic = MAGIC;
	info->vp = vp;

	*c = (void *)info;
	return 0;
}
Beispiel #27
0
int main(int argc, char *argv[])
{
	virConnectPtr conn;
	char *caps;

	conn = virConnectOpen("lxc+unix://");
	if (conn == NULL) {
		fprintf(stderr, "Failed to open connection to lxc+unix://\n");
		return 1;
	}

	caps = virConnectGetCapabilities(conn);
	fprintf(stdout, "Capabilities:\n%s\n", caps);
	free(caps);

	virConnectClose(conn);
	return 0;
}
Beispiel #28
0
void VirshType::Connect()
{
	priv_state priv = set_root_priv();

	if ( m_libvirt_connection )
	{
		virConnectClose( m_libvirt_connection );
	}

    m_libvirt_connection = virConnectOpen( m_sessionID.c_str() );
    set_priv(priv);

  	if( m_libvirt_connection == NULL )
    {
		virErrorPtr err = virGetLastError();
		EXCEPT("Failed to create libvirt connection: %s", (err ? err->message : "No reason found"));
    }
}
Beispiel #29
0
int main(int argc, char *argv[])
{
	virConnectPtr conn;
	virDomainPtr dom;
	char *xmlconfig = NULL;

	if(argc != 2)
	{	
		printf("usage: ./define_domain domain.xml\n");
		return -1;
	}	

	if ((xmlconfig = GetXml(argv[1])) == NULL)
	{
		fprintf(stderr, "Failed to get xml\n");
		return -1;
	}
	
	conn = virConnectOpen("qemu:///system");
	if (conn == NULL) 
	{
		fprintf(stderr, "Failed to open connection to qemu:///system\n");
		free(xmlconfig);
		return -1;
	}
	
	
	dom = virDomainDefineXML(conn, xmlconfig);
	if (!dom) 
	{
		printf("Domain is not found\n");
		free(xmlconfig);
		virConnectClose(conn);
		return -1;
	}

	fprintf(stderr, "Guest %s is defined\n", virDomainGetName(dom));

	free(xmlconfig);
	virDomainFree(dom);
	virConnectClose(conn);
	
	return 0;
}
Beispiel #30
0
static int
mymain(void)
{
    struct metadataTest test;
    int ret = EXIT_SUCCESS;

    if (!(test.conn = virConnectOpen("test:///default")))
        return EXIT_FAILURE;

    if (!(test.dom = virDomainLookupByName(test.conn, "test"))) {
        virConnectClose(test.conn);
        return EXIT_FAILURE;
    }

    virtTestQuiesceLibvirtErrors(false);

    if (virtTestRun("Assign metadata ", testAssignMetadata, &test) < 0)
        ret = EXIT_FAILURE;
    if (virtTestRun("Rewrite Metadata ", testRewriteMetadata, &test) < 0)
        ret = EXIT_FAILURE;
    if (virtTestRun("Erase metadata ", testEraseMetadata, &test) < 0)
        ret = EXIT_FAILURE;

    TEST_TITLE("1", "qwert");
    TEST_TITLE("2", NULL);
    TEST_TITLE("3", "blah");
    TEST_TITLE_FAIL("4", "qwe\nrt");
    TEST_TITLE("5", "");
    TEST_TITLE_FAIL("6", "qwert\n");
    TEST_TITLE_FAIL("7", "\n");

    TEST_DESCR("1", "qwert\nqwert");
    TEST_DESCR("2", NULL);
    TEST_DESCR("3", "qwert");
    TEST_DESCR("4", "\n");
    TEST_DESCR("5", "");

    virDomainFree(test.dom);
    virConnectClose(test.conn);

    return ret;
}