// initialize sets up an openstack scheduler. func (s *opst) initialize(config interface{}) (err error) { s.config = config.(*ConfigOpenStack) if s.config.OSRAM == 0 { s.config.OSRAM = 2048 } // create a cloud provider for openstack, that we'll use to interact with // openstack provider, err := cloud.New("openstack", s.config.ResourceName, s.config.SavePath) if err != nil { return } s.provider = provider err = provider.Deploy(s.config.ServerPorts) if err != nil { return } // query our quota maximums for cpu and memory and total number of // instances; 0 will mean unlimited quota, err := provider.GetQuota() if err != nil { return } s.quotaMaxCores = quota.MaxCores s.quotaMaxRAM = quota.MaxRAM s.quotaMaxInstances = quota.MaxInstances if s.config.MaxInstances > 0 && s.config.MaxInstances < s.quotaMaxInstances { s.quotaMaxInstances = s.config.MaxInstances } // initialize our job queue and other trackers s.queue = queue.New(localPlace) s.running = make(map[string]int) // initialise our servers with details of ourself s.servers = make(map[string]*cloud.Server) maxRAM, err := s.procMeminfoMBs() if err != nil { return } usage := du.NewDiskUsage(".") s.servers["localhost"] = &cloud.Server{ IP: "127.0.0.1", Flavor: cloud.Flavor{ RAM: maxRAM, Cores: runtime.NumCPU(), Disk: int(usage.Size() / gb), }, } // set our functions for use in schedule() and processQueue() s.reqCheckFunc = s.reqCheck s.canCountFunc = s.canCount s.runCmdFunc = s.runCmd // pass through our shell config to our local embed s.local.config = &ConfigLocal{Shell: s.config.Shell} s.standins = make(map[string]*standin) s.stopWaitingToSpawn = make(chan bool) return }
// $PATH exe, err := osext.Executable() if err != nil { die("could not get the path to wr: %s", err) } // get all necessary cloud resources in place mp, err := strconv.Atoi(config.ManagerPort) if err != nil { die("bad manager_port [%s]: %s", config.ManagerPort, err) } wp, err := strconv.Atoi(config.ManagerWeb) if err != nil { die("bad manager_web [%s]: %s", config.ManagerWeb, err) } provider, err := cloud.New(providerName, "wr-"+config.Deployment, filepath.Join(config.ManagerDir, "cloud_resources."+providerName)) if err != nil { die("failed to connect to %s: %s", providerName, err) } serverPort := "22" info("please wait while %s resources are created...", providerName) err = provider.Deploy([]int{22, mp, wp}) if err != nil { die("failed to create resources in %s: %s", providerName, err) } // get/spawn a "head node" server var server *cloud.Server usingExistingServer := false servers := provider.Servers() for _, thisServer := range servers {