func NewFromConfigs(kernel, initrd string, configs []FactoryConfig) Factory { bases := make([]base.Factory, len(configs)) for i, c := range configs { var b base.Factory b = direct.New(c.Cpu, c.Memory, kernel, initrd) bases[i] = cache.New(c.Cache, b) } if len(bases) == 0 { // skip GetVm from the base factory return single.New(direct.New(1000000, 1000000, kernel, initrd)) } else if len(bases) == 1 { return single.New(bases[0]) } else { return multi.New(bases) } }
func New(templateRoot string, cpu, mem int, kernel, initrd string) base.Factory { var vmName string for { vmName = fmt.Sprintf("template-vm-%s", pod.RandStr(10, "alpha")) if _, err := os.Stat(templateRoot + "/" + vmName); os.IsNotExist(err) { break } } s, err := template.CreateTemplateVM(templateRoot+"/"+vmName, vmName, cpu, mem, kernel, initrd) if err != nil { glog.Infof("failed to create template factory: %v", err) glog.Infof("use direct factory instead") return direct.New(cpu, mem, kernel, initrd) } return &templateFactory{s: s} }