Esempio n. 1
0
int run_discs_detection(GList **config)
{
	GList *drives=NULL;
	int i;
	int found = 0;
	char *ptr;

	umount_if_needed(SOURCEDIR);
    makepath(SOURCEDIR);

	drives = grep_drives("/proc/sys/dev/cdrom/info");
	for (i = 0; i < g_list_length(drives); i++) {
		ptr = get_blkid((char*)g_list_nth_data(drives, i));
		if(ptr && !strcmp(ptr, "Frugalware Install")) {
			LOG("install medium found in %s", (char*)g_list_nth_data(drives, i));
			free(ptr);
			ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s",
				(char*)g_list_nth_data(drives, i),
				SOURCEDIR);
			fw_system(ptr);
			free(ptr);

			if(!is_netinstall(SOURCEDIR)) {
				data_put(config, "srcdev", (char*)g_list_nth_data(drives, i));
				found = 1;
				break;
			}
		} else {
			LOG("skipping non-install medium in %s", (char*)g_list_nth_data(drives, i));
        }
	}

	return found;
}
Esempio n. 2
0
// Encodes instance metadata (contained in ncInstance struct) in XML
// and writes it to file instance->xmlFilePath (/path/to/instance/instance.xml)
// That file gets processed through tools/libvirt.xsl (/etc/eucalyptus/libvirt.xsl)
// to produce /path/to/instance/libvirt.xml file that is passed to libvirt create.
int gen_instance_xml (const ncInstance * instance)
{
    INIT();

    int ret = 1;
    pthread_mutex_lock (&xml_mutex);
    xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
    xmlNodePtr instanceNode = xmlNewNode (NULL, BAD_CAST "instance");
    xmlDocSetRootElement (doc, instanceNode);

    { // hypervisor-related specs
        xmlNodePtr hypervisor = xmlNewChild (instanceNode, NULL, BAD_CAST "hypervisor", NULL);
        _ATTRIBUTE(hypervisor, "type", instance->hypervisorType);
        _ATTRIBUTE(hypervisor, "capability", hypervsorCapabilityTypeNames[instance->hypervisorCapability]);
        char bitness[4];
        snprintf(bitness, 4,"%d", instance->hypervisorBitness);
        _ATTRIBUTE(hypervisor, "bitness", bitness);
    }

    { // backing specification (TODO: maybe expand this with device maps or whatnot?)
        xmlNodePtr backing = xmlNewChild (instanceNode, NULL, BAD_CAST "backing", NULL);
        xmlNodePtr root = xmlNewChild (backing, NULL, BAD_CAST "root", NULL);
        assert (instance->params.root);
        _ATTRIBUTE(root, "type", ncResourceTypeName[instance->params.root->type]);
    }

    _ELEMENT(instanceNode, "name", instance->instanceId);
    _ELEMENT(instanceNode, "uuid", instance->uuid);
    _ELEMENT(instanceNode, "reservation", instance->reservationId);
    _ELEMENT(instanceNode, "user", instance->userId);
    _ELEMENT(instanceNode, "dnsName", instance->dnsName);
    _ELEMENT(instanceNode, "privateDnsName", instance->privateDnsName);
    _ELEMENT(instanceNode, "instancePath", instance->instancePath);
    if (instance->params.kernel) {
        char * path = instance->params.kernel->backingPath;
        if (path_check (path, "kernel")) goto free; // sanity check 
        _ELEMENT(instanceNode, "kernel", path);
    }
    if (instance->params.ramdisk) {
        char * path = instance->params.ramdisk->backingPath;
        if (path_check (path, "ramdisk")) goto free; // sanity check
        _ELEMENT(instanceNode, "ramdisk", path);
    }
    _ELEMENT(instanceNode, "consoleLogPath", instance->consoleFilePath);
    _ELEMENT(instanceNode, "userData", instance->userData);
    _ELEMENT(instanceNode, "launchIndex", instance->launchIndex);
    
    char cores_s  [10]; snprintf (cores_s,  sizeof (cores_s),  "%d", instance->params.cores);  _ELEMENT(instanceNode, "cores", cores_s);
    char memory_s [10]; snprintf (memory_s, sizeof (memory_s), "%d", instance->params.mem * 1024); _ELEMENT(instanceNode, "memoryKB", memory_s);

    { // SSH-key related
        xmlNodePtr key = _NODE(instanceNode, "key");
        _ATTRIBUTE(key, "isKeyInjected", _BOOL(instance->do_inject_key));
        _ATTRIBUTE(key, "sshKey", instance->keyName);
    }

    { // OS-related specs
        xmlNodePtr os = _NODE(instanceNode, "os");
        _ATTRIBUTE(os, "platform", instance->platform);
        _ATTRIBUTE(os, "virtioRoot", _BOOL(config_use_virtio_root));
        _ATTRIBUTE(os, "virtioDisk", _BOOL(config_use_virtio_disk));
        _ATTRIBUTE(os, "virtioNetwork", _BOOL(config_use_virtio_net));
    }

    { // disks specification
        xmlNodePtr disks = _NODE(instanceNode, "disks");

        // the first disk should be the root disk (at least for Windows)
        for (int root=1; root>=0; root--){ 
           for (int i=0; i<EUCA_MAX_VBRS && i<instance->params.virtualBootRecordLen; i++) {
               const virtualBootRecord * vbr = &(instance->params.virtualBootRecord[i]); 
               // skip empty entries, if any
               if (vbr==NULL)
                   continue;
               // do EMI on the first iteration of the outer loop
               if (root && vbr->type != NC_RESOURCE_IMAGE) 
                   continue;
               // ignore EMI on the second iteration of the outer loop
               if (!root && vbr->type == NC_RESOURCE_IMAGE)
                   continue;
               // skip anything without a device on the guest, e.g., kernel and ramdisk
               if (!strcmp ("none", vbr->guestDeviceName)) 
                   continue;
               // for Linux instances on Xen, partitions can be used directly, so disks can be skipped unless booting from EBS
               if (strstr (instance->platform, "linux") && strstr (instance->hypervisorType, "xen")) {
                   if (vbr->partitionNumber == 0 && vbr->type == NC_RESOURCE_IMAGE) {
                       continue;
                   }
               } else { // on all other os + hypervisor combinations, disks are used, so partitions must be skipped
                   if (vbr->partitionNumber > 0) {
                       continue;
                   }
               }
            
               xmlNodePtr disk = _ELEMENT(disks, "diskPath", vbr->backingPath);
               _ATTRIBUTE(disk, "targetDeviceType", libvirtDevTypeNames[vbr->guestDeviceType]);
               _ATTRIBUTE(disk, "targetDeviceName", vbr->guestDeviceName);
               char devstr[SMALL_CHAR_BUFFER_SIZE];
               snprintf(devstr, SMALL_CHAR_BUFFER_SIZE, "%s", vbr->guestDeviceName);             
               if (config_use_virtio_root) {
                   devstr[0] = 'v';
                   _ATTRIBUTE(disk, "targetDeviceNameVirtio", devstr);
                   _ATTRIBUTE(disk, "targetDeviceBusVirtio", "virtio");     
               }
               _ATTRIBUTE(disk, "targetDeviceBus", libvirtBusTypeNames[vbr->guestDeviceBus]);
               _ATTRIBUTE(disk, "sourceType", libvirtSourceTypeNames[vbr->backingType]);

               if (root) {
                   xmlNodePtr rootNode = _ELEMENT(disks, "root", NULL);
                   _ATTRIBUTE(rootNode, "device", devstr);
                   char root_uuid[64] = "";
                   if (get_blkid (vbr->backingPath, root_uuid, sizeof(root_uuid)) == 0) {
                       assert (strlen (root_uuid));
                       _ATTRIBUTE(rootNode, "uuid", root_uuid);
                   }
               }
           }
           if (strlen (instance->floppyFilePath)) {
               _ELEMENT(disks, "floppyPath", instance->floppyFilePath);
           }
       }
    }

    if (instance->params.nicType!=NIC_TYPE_NONE) { // NIC specification
        xmlNodePtr nics = _NODE(instanceNode, "nics");
        xmlNodePtr nic =  _NODE(nics, "nic");
        _ATTRIBUTE(nic, "bridgeDeviceName", instance->params.guestNicDeviceName);
        _ATTRIBUTE(nic, "mac", instance->ncnet.privateMac);
    }

    ret = write_xml_file (doc, instance->instanceId, instance->xmlFilePath, "instance");
 free:
    xmlFreeDoc(doc);
    pthread_mutex_unlock (&xml_mutex);

    return ret;
}
Esempio n. 3
0
int run(GList **config)
{
	GList *drives=NULL;
	int i;
	int found = 0;
	char *ptr;

	umount_if_needed(SOURCEDIR);

	dialog_vars.backtitle=gen_backtitle(_("Selecting source media"));
	dlg_put_backtitle();
	dlg_clear();
	dialog_msgbox(_("Scanning"), _("Scanning for a CD/DVD drive containing "
		"a Frugalware install disc..."), 0, 0, 0);
	
	drives = grep_drives("/proc/sys/dev/cdrom/info");
	for (i=0; i<g_list_length(drives); i++)
	{
		ptr = get_blkid((char*)g_list_nth_data(drives, i));
		if(ptr && !strcmp(ptr, "Frugalware Install"))
		{
			LOG("install medium found in %s", (char*)g_list_nth_data(drives, i));
			FREE(ptr);
			ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s", (char*)g_list_nth_data(drives, i),
					SOURCEDIR);
			fw_system(ptr);
			data_put(config, "srcdev", (char*)g_list_nth_data(drives, i));
			dlg_put_backtitle();
			dialog_msgbox(_("CD/DVD drive found"), g_strdup_printf(_("A Frugalware install disc was found in device /dev/%s."), (char*)g_list_nth_data(drives, i)), 0, 0, 0);
			if(is_netinstall(SOURCEDIR))
			{
				data_put(config, "netinstall", "");
				LOG("install medium contains no packages, performing a network installation");
			}
			else
				LOG("install medium contains packages, performing an offline installation");
			found = 1;
			break;
		}
		else
			LOG("skipping non-install medium in %s", (char*)g_list_nth_data(drives, i));
		FREE(ptr);
	}
	if(!found)
	{
		LOG("no package database found, performing a network installation");
		data_put(config, "netinstall", "");
	}
	// disable caching for cds
	if((char*)data_get(*config, "netinstall")==NULL)
	{
		char *pacbindir = g_strdup_printf("%s/frugalware-%s", SOURCEDIR, ARCH);
		disable_cache(pacbindir);
		FREE(pacbindir);
	}
	if(data_get(*config, "srcdev")==NULL)
	{
		LOG("no cd/dvd drive found, this is normal if you are running setup from a pendrive or in an emulator");
	}
	return(0);
}