src/indexOld.js
function addInstance(machineName, versionKey) {

        return co(function*() {
            debug("Adding a new instance to the " + versionKey + " of the '" + machineName + "' machine");
            let manifest = getManifest();

            let machine = manifest.machines[machineName];
            if (!machine) {
                throw new Error("Machine does not exists");
            }

            let version = machine.versions[versionKey];
            if (!version) {
                throw new Error("Version does not exists");
            }

            let versionInfo = getVersionInfo(machineName,  versionKey);
            if(!versionInfo.isSealed) {
                throw new Error("The version is not sealed yet");
            }

            let newInstanceKey = "instance" + (Object.keys(version.instances).length + 1);
            let instanceDirPath = version.route + "/instances/" + newInstanceKey;
            let instanceSnapshotsDirPath = instanceDirPath + "/snapshots";
            version.instances[newInstanceKey] = {
                "route": instanceDirPath,
                "snapshots": {}
            };

            let infoFile = instanceDirPath + "/info.json";

            debug("Creating the directories");
            fs.mkdirSync(repositoryPath + "/" + instanceDirPath);
            fs.mkdirSync(repositoryPath + "/" + instanceSnapshotsDirPath);

            debug("Creating the instance info.json file");
            let info = {
                "hasStarted": false,
                "hasEnded": false
            };
            jsonfile.writeFileSync(repositoryPath + "/" + infoFile, info);

            debug("Setting the manifest");
            setManifest(manifest);
            yield _commit(null, ["manifest.json", infoFile],
                "Created the "+newInstanceKey+" for the "+versionKey+" of the '" + machineName + "' machine");

            return newInstanceKey;
        });
    }
function addInstance(machineName, versionKey) {

        return co(function*() {
            debug("Adding a new instance to the " + versionKey + " of the '" + machineName + "' machine");
            let manifest = getManifest();

            let machine = manifest.machines[machineName];
            if (!machine) {
                throw new Error("Machine does not exists");
            }

            let version = machine.versions[versionKey];
            if (!version) {
                throw new Error("Version does not exists");
            }

            let versionInfo = getVersionInfo(machineName,  versionKey);
            if(!versionInfo.isSealed) {
                throw new Error("The version is not sealed yet");
            }

            let newInstanceKey = "instance" + (Object.keys(version.instances).length + 1);
            let instanceDirPath = version.route + "/instances/" + newInstanceKey;
            let instanceSnapshotsDirPath = instanceDirPath + "/snapshots";
            version.instances[newInstanceKey] = {
                "route": instanceDirPath,
                "snapshots": {}
            };

            let infoFile = instanceDirPath + "/info.json";

            debug("Creating the directories");
            fs.mkdirSync(repositoryPath + "/" + instanceDirPath);
            fs.mkdirSync(repositoryPath + "/" + instanceSnapshotsDirPath);

            debug("Creating the instance info.json file");
            let info = {
                "hasStarted": false,
                "hasEnded": false
            };
            jsonfile.writeFileSync(repositoryPath + "/" + infoFile, info);

            debug("Setting the manifest");
            setManifest(manifest);
            yield _commit(null, ["manifest.json", infoFile],
                "Created the "+newInstanceKey+" for the "+versionKey+" of the '" + machineName + "' machine");

            return newInstanceKey;
        });
    }
function addInstance ( machineName , versionKey ) { return co ( function * ( ) { debug ( "Adding a new instance to the " + versionKey + " of the '" + machineName + "' machine" ) ; let manifest = getManifest ( ) ; let machine = manifest . machines [ machineName ] ; if ( ! machine ) { throw new Error ( "Machine does not exists" ) ; } let version = machine . versions [ versionKey ] ; if ( ! version ) { throw new Error ( "Version does not exists" ) ; } let versionInfo = getVersionInfo ( machineName , versionKey ) ; if ( ! versionInfo . isSealed ) { throw new Error ( "The version is not sealed yet" ) ; } let newInstanceKey = "instance" + ( Object . keys ( version . instances ) . length + 1 ) ; let instanceDirPath = version . route + "/instances/" + newInstanceKey ; let instanceSnapshotsDirPath = instanceDirPath + "/snapshots" ; version . instances [ newInstanceKey ] = { "route" : instanceDirPath , "snapshots" : { } } ; let infoFile = instanceDirPath + "/info.json" ; debug ( "Creating the directories" ) ; fs . mkdirSync ( repositoryPath + "/" + instanceDirPath ) ; fs . mkdirSync ( repositoryPath + "/" + instanceSnapshotsDirPath ) ; debug ( "Creating the instance info.json file" ) ; let info = { "hasStarted" : false , "hasEnded" : false } ; jsonfile . writeFileSync ( repositoryPath + "/" + infoFile , info ) ; debug ( "Setting the manifest" ) ; setManifest ( manifest ) ; yield _commit ( null , [ "manifest.json" , infoFile ] , "Created the " + newInstanceKey + " for the " + versionKey + " of the '" + machineName + "' machine" ) ; return newInstanceKey ; } ) ; }
Add a new instance to a version of a machine
@method addInstance
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@returns {Promise} The instance key
Add a new instance to a version of a machine