int main (int argc, char ** argv) { if (argc!=2) { logprintfl (EUCAERROR, "ERROR: required parameters are <XSLT stylesheet path>\n"); return 1; } strncpy (xslt_path, argv[1], sizeof (xslt_path)); char * in_path = tempnam (NULL, "xml-"); char * out_path = tempnam (NULL, "xml-"); create_dummy_instance (in_path); logprintfl (EUCAINFO, "parsing stylesheet %s\n", xslt_path); int err = apply_xslt_stylesheet (xslt_path, in_path, out_path, NULL, 0); if (err!=OK) goto out; logprintfl (EUCAINFO, "parsing stylesheet %s again\n", xslt_path); char xml_buf [2048]; err = apply_xslt_stylesheet (xslt_path, in_path, out_path, xml_buf, sizeof (xml_buf)); if (err!=OK) goto out; logprintfl (EUCAINFO, "wrote XML to %s\n", out_path); if (strlen (xml_buf) < 1) { err = ERROR; logprintfl (EUCAERROR, "failed to see XML in buffer\n"); goto out; } cat (out_path); out: remove (out_path); remove (in_path); free (in_path); free (out_path); return err; }
int gen_libvirt_attach_xml (const char *volumeId, const ncInstance *instance, const char * localDevReal, const char * remoteDev, char * xml, unsigned int xml_size) { INIT(); int ret = 1; pthread_mutex_lock (&xml_mutex); xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); xmlNodePtr volumeNode = xmlNewNode (NULL, BAD_CAST "volume"); xmlDocSetRootElement (doc, volumeNode); { // hypervisor-related specs xmlNodePtr hypervisor = xmlNewChild (volumeNode, 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); } _ELEMENT(volumeNode, "id", volumeId); _ELEMENT(volumeNode, "user", instance->userId); _ELEMENT(volumeNode, "instancePath", instance->instancePath); { // OS-related specs xmlNodePtr os = _NODE(volumeNode, "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)); } { // backing specification (TODO: maybe expand this with device maps or whatnot?) xmlNodePtr backing = xmlNewChild (volumeNode, 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]); } { // volume information xmlNodePtr disk = _ELEMENT(volumeNode, "diskPath", remoteDev); _ATTRIBUTE(disk, "targetDeviceType", "disk"); _ATTRIBUTE(disk, "targetDeviceName", localDevReal); _ATTRIBUTE(disk, "targetDeviceBus", "scsi"); _ATTRIBUTE(disk, "sourceType", "block"); } char path [MAX_PATH]; snprintf (path, sizeof (path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volumeId); ret = write_xml_file (doc, instance->instanceId, path, "volume") || apply_xslt_stylesheet (xslt_path, path, NULL, xml, xml_size); logprintfl (EUCATRACE, "XML={%s}\n", xml); xmlFreeDoc(doc); pthread_mutex_unlock (&xml_mutex); return ret; }
// Given a file with instance metadata in XML (instance->xmlFilePath) // and an XSL-T stylesheet, produces XML document suitable for libvirt int gen_libvirt_instance_xml (const ncInstance * instance) { INIT(); pthread_mutex_lock (&xml_mutex); int ret = apply_xslt_stylesheet (xslt_path, instance->xmlFilePath, instance->libvirtFilePath, NULL, 0); pthread_mutex_unlock (&xml_mutex); return ret; }
//! //! Main entry point of the application //! //! @param[in] argc the number of parameter passed on the command line //! @param[in] argv the list of arguments //! //! @return EUCA_OK on success or EUCA_ERROR on failure. //! int main(int argc, char **argv) { int err = EUCA_ERROR; char *in_path = NULL; char *out_path = NULL; char xml_buf[2048] = ""; if (argc != 2) { LOGERROR("required parameters are <XSLT stylesheet path>\n"); return (EUCA_ERROR); } euca_strncpy(xslt_path, argv[1], sizeof(xslt_path)); in_path = tempnam(NULL, "xml-"); out_path = tempnam(NULL, "xml-"); create_dummy_instance(in_path); LOGINFO("parsing stylesheet %s\n", xslt_path); if ((err = apply_xslt_stylesheet(xslt_path, in_path, out_path, NULL, 0)) != EUCA_OK) goto out; LOGINFO("parsing stylesheet %s again\n", xslt_path); if ((err = apply_xslt_stylesheet(xslt_path, in_path, out_path, xml_buf, sizeof(xml_buf))) != EUCA_OK) goto out; LOGINFO("wrote XML to %s\n", out_path); if (strlen(xml_buf) < 1) { err = EUCA_ERROR; LOGERROR("failed to see XML in buffer\n"); goto out; } cat(out_path); out: remove(out_path); remove(in_path); EUCA_FREE(in_path); EUCA_FREE(out_path); return (err); }
//! //! Generate volume XML content for LIBVIRT //! //! @param[in] volumeId the volume identifier string (vol-XXXXXXXX) //! @param[in] instance a pointer to our instance structure. //! //! @return The results of calling apply_xslt_stylesheet() //! //! @see apply_xslt_stylesheet() //! int gen_libvirt_volume_xml(const char *volumeId, const ncInstance * instance) { int ret = EUCA_OK; char path[MAX_PATH] = ""; char lpath[MAX_PATH] = ""; INIT(); snprintf(path, sizeof(path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volumeId); // vol-XXX.xml snprintf(lpath, sizeof(lpath), EUCALYPTUS_VOLUME_LIBVIRT_XML_PATH_FORMAT, instance->instancePath, volumeId); // vol-XXX-libvirt.xml pthread_mutex_lock(&xml_mutex); { ret = apply_xslt_stylesheet(xslt_path, path, lpath, NULL, 0); } pthread_mutex_unlock(&xml_mutex); return (ret); }