Package com.cloud.agent.api.storage

Examples of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer


                    primary = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
                                      cmd.getPool().getType());
                } else {
                    return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
                }
            }

            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            String tmpltPath = secondaryStorage.getLocalPath() + File.separator
                    + templateInstallFolder;
            _storage.mkdirs(tmpltPath);

            if (primary.getType() != StoragePoolType.RBD) {
                Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
                command.add("-f", disk.getPath());
                command.add("-t", tmpltPath);
                command.add("-n", cmd.getUniqueName() + ".qcow2");

                String result = command.execute();

                if (result != null) {
                    s_logger.debug("failed to create template: " + result);
                    return new CreatePrivateTemplateAnswer(cmd, false, result);
                }
            } else {
                s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + cmd.getUniqueName());

                QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),
                                primary.getSourcePort(),
                                primary.getAuthUserName(),
                                primary.getAuthSecret(),
                                disk.getPath()));
                srcFile.setFormat(PhysicalDiskFormat.RAW);

                QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + cmd.getUniqueName() + ".qcow2");
                destFile.setFormat(PhysicalDiskFormat.QCOW2);

                QemuImg q = new QemuImg(0);
                try {
                    q.convert(srcFile, destFile);
                } catch (QemuImgException e) {
                    s_logger.error("Failed to create new template while converting "
                                    + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage());
                }

                File templateProp = new File(tmpltPath + "/template.properties");
                if (!templateProp.exists()) {
                    templateProp.createNewFile();
                }

                String templateContent = "filename=" + cmd.getUniqueName() + ".qcow2" + System.getProperty("line.separator");

                DateFormat dateFormat = new SimpleDateFormat("MM_dd_yyyy");
                Date date = new Date();
                templateContent += "snapshot.name=" + dateFormat.format(date) + System.getProperty("line.separator");

                FileOutputStream templFo = new FileOutputStream(templateProp);
                templFo.write(templateContent.getBytes());
                templFo.flush();
                templFo.close();
            }

            Map<String, Object> params = new HashMap<String, Object>();
            params.put(StorageLayer.InstanceConfigKey, _storage);
            Processor qcow2Processor = new QCOW2Processor();

            qcow2Processor.configure("QCOW2 Processor", params);

            FormatInfo info = qcow2Processor.process(tmpltPath, null,
                    cmd.getUniqueName());

            TemplateLocation loc = new TemplateLocation(_storage, tmpltPath);
            loc.create(1, true, cmd.getUniqueName());
            loc.addFormat(info);
            loc.save();

            return new CreatePrivateTemplateAnswer(cmd, true, null,
                    templateInstallFolder + cmd.getUniqueName() + ".qcow2",
                    info.virtualSize, info.size, cmd.getUniqueName(),
                    ImageFormat.QCOW2);
        } catch (InternalErrorException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
        } catch (IOException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
        } catch (ConfigurationException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
        } catch (CloudRuntimeException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
        } finally {
            if (secondaryStorage != null) {
                _storagePoolMgr.deleteStoragePool(secondaryStorage.getType(), secondaryStorage.getUuid());
            }
        }
View Full Code Here


            Ternary<String, Long, Long> result = createTemplateFromVolume(vmMo,
                    accountId, templateId, cmd.getUniqueName(),
                    secondaryStoragePoolURL, volumePath,
                    hostService.getWorkerName(context, cmd, 0));

            return new CreatePrivateTemplateAnswer(cmd, true, null,
                    result.first(), result.third(), result.second(),
                    cmd.getUniqueName(), ImageFormat.OVA);

        } catch (Throwable e) {
            if (e instanceof RemoteException) {
                hostService.invalidateServiceContext(context);
            }

            s_logger.error("Unexpecpted exception ", e);

            details = "CreatePrivateTemplateFromVolumeCommand exception: " + StringUtils.getExceptionStackInfo(e);
            return new CreatePrivateTemplateAnswer(cmd, false, details);
        }
    }
View Full Code Here

            Ternary<String, Long, Long> result = createTemplateFromSnapshot(accountId,
                    newTemplateId, uniqeName,
                    secondaryStorageUrl, volumeId,
                    backedUpSnapshotUuid);

            return new CreatePrivateTemplateAnswer(cmd, true, null,
                    result.first(), result.third(), result.second(),
                    uniqeName, ImageFormat.OVA);
        } catch (Throwable e) {
            if (e instanceof RemoteException) {
                hostService.invalidateServiceContext(context);
            }

            s_logger.error("Unexpecpted exception ", e);

            details = "CreatePrivateTemplateFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
            return new CreatePrivateTemplateAnswer(cmd, false, details);
        }
    }
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.