function convert_ec2(env) {
	var category = {"id": "instance",
		"provider":{"name":"aws", "account":"default", "flavor":env.flavor, "image":env.image, "groups":env.groups, "stack_template": env.stack_template}
	, "cm_tool":{"name": "chef"}};
	category.provider["vpc_id"] = "";
	category.provider["subnet"] = env.subnets[0];
	category.cm_tool["bootstrap_template"] = db.images.findOne({"_id": env.image}).bootstrap_template
	var new_env = {"id": env.identifier, "run_list": env.run_list, "expires": env.expires, "users":env.users, "categories":[category]};
	return new_env;
}
function convert_openstack(env) {
	return false;
}
function convert_static(env) {
	var category = {"id": "instance", "provider":{"name":"static", "account":"default"}, "cm_tool":{"name": "chef"}};
	var new_env = {"id": env.identifier, "run_list": env.run_list, "expires": env.expires, "users":env.users, "categories":[category]};
	return new_env;
}
db.projects.find().forEach(function(project) {
	var deploy_envs = project.deploy_envs;
	project.deploy_envs = [];
	while(deploy_envs.length != 0) {
		var env = deploy_envs.pop();
		var new_env;
		if (env.provider == "ec2") {
			new_env = convert_ec2(env);
		} else if (env.provider == "openstack") {
			new_env = convert_openstack(env);
		} else if (env.provider == "static") {
			new_env = convert_static(env);
		}
		if (new_env) {
			project.deploy_envs.push(new_env);
		}
	}
	db.projects.update({_id: project._id}, {
		'$set': {'environments': project.deploy_envs},
		'$unset': {'deploy_envs': 1}
	})
})
