Пример #1
0
func main() {
	cfgPath := "lobster.cfg"
	if len(os.Args) >= 2 {
		cfgPath = os.Args[1]
	}
	lobster.Setup(cfgPath)
	url := "mysql://" + lobster.GetDatabaseString()
	pipe := pipep.New()
	go migrate.Up(pipe, url, "./db/migrations")
	hadError := false
	done := false
	for !done {
		select {
		case item, more := <-pipe:
			if !more {
				done = true
			} else {
				switch item.(type) {
				case string:
					fmt.Println(item.(string))
				case error:
					fmt.Printf("ERROR: %v\n", item)
					hadError = true
				case file.File:
					f := item.(file.File)
					if f.Direction == direction.Up {
						fmt.Print("> ")
					} else if f.Direction == direction.Down {
						fmt.Print("< ")
					}
					fmt.Println(f.FileName)
				default:
					fmt.Printf("%v", item)
				}
			}
		}
	}
	if !hadError {
		fmt.Println("database up to date")
	}
}
Пример #2
0
func main() {
	cfgPath := "lobster.cfg"
	if len(os.Args) >= 2 {
		cfgPath = os.Args[1]
	}
	lobster.Setup(cfgPath)

	// associate core
	support.Setup()

	// load json configuration
	jsonPath := cfgPath + ".json"
	jsonConfigBytes, err := ioutil.ReadFile(jsonPath)
	if err != nil {
		log.Fatalf("Error: failed to read json configuration file %s: %s", jsonPath, err.Error())
	}
	var jsonConfig JSONConfig
	err = json.Unmarshal(jsonConfigBytes, &jsonConfig)
	if err != nil {
		log.Fatalf("Error: failed to parse json configuration: %s", err.Error())
	}

	for i, vm := range jsonConfig.Vm {
		log.Printf("Initializing VM interface %s (type=%s)", vm.Name, vm.Type)
		var vmi lobster.VmInterface
		if vm.Type == "openstack" {
			vmi = openstack.MakeOpenStack(vm.Url, vm.Username, vm.Password, vm.Tenant, vm.NetworkId)
		} else if vm.Type == "solusvm" {
			vmi = &solusvm.SolusVM{
				VirtType:  vm.VirtType,
				NodeGroup: vm.NodeGroup,
				Api: &solusvm.API{
					Url:      vm.Url,
					ApiId:    vm.ApiId,
					ApiKey:   vm.ApiKey,
					Insecure: vm.Insecure,
				},
			}
		} else if vm.Type == "lobster" {
			vmi = vmlobster.MakeLobster(vm.Region, vm.Url, vm.ApiId, vm.ApiKey)
		} else if vm.Type == "cloudstack" {
			vmi = cloudstack.MakeCloudStack(vm.Url, vm.ZoneID, vm.NetworkId, vm.ApiKey, vm.SecretKey)
		} else if vm.Type == "lndynamic" {
			vmi = lunanode.MakeLunaNode(vm.Region, vm.ApiId, vm.ApiKey)
		} else if vm.Type == "fake" {
			vmi = new(vmfake.Fake)
		} else if vm.Type == "digitalocean" {
			vmi = digitalocean.MakeDigitalOcean(vm.Region, vm.ApiId)
		} else if vm.Type == "vultr" {
			regionId, err := strconv.Atoi(vm.Region)
			if err != nil {
				log.Fatalf("Error: invalid region ID for vultr interface: %s", vm.Region)
			}
			vmi = vultr.MakeVultr(vm.ApiKey, regionId)
		} else if vm.Type == "linode" {
			datacenterId, err := strconv.Atoi(vm.Region)
			if err != nil {
				log.Fatalf("Error: invalid datacenter ID for linode interface: %s", vm.Region)
			}
			vmi = linode.MakeLinode(vm.ApiKey, datacenterId)
		} else if vm.Type == "cloug" {
			// need to get the JSON data for this interface
			// to do this, we will unmarshal the configuration into HelperConfig, and then
			//   re-marshal the corresponding index
			var helperConfig HelperConfig
			if err := json.Unmarshal(jsonConfigBytes, &helperConfig); err != nil {
				log.Fatalf("Error unmarshaling into helper for cloug interface: %v", err)
			}
			jsonData, err := json.Marshal(helperConfig.Vm[i])
			if err != nil {
				log.Fatalf("Error marshaling from helper for cloug interface: %v", err)
			}
			vmi, err = cloug.MakeCloug(jsonData, vm.Region)
			if err != nil {
				log.Fatalf("Cloug error: %v", err)
			}
		} else {
			log.Fatalf("Encountered unrecognized VM interface type %s", vm.Type)
		}
		log.Println("... initialized successfully")
		lobster.RegisterVmInterface(vm.Name, vmi)
	}

	for _, payment := range jsonConfig.Payment {
		var pi lobster.PaymentInterface
		if payment.Type == "paypal" {
			pi = paypal.MakePaypalPayment(payment.Business, payment.ReturnUrl)
		} else if payment.Type == "coinbase" {
			pi = coinbase.MakeCoinbasePayment(payment.CallbackSecret, payment.ApiKey, payment.ApiSecret)
		} else if payment.Type == "fake" {
			pi = new(payfake.FakePayment)
		} else {
			log.Fatalf("Encountered unrecognized payment interface type %s", payment.Type)
		}
		lobster.RegisterPaymentInterface(payment.Name, pi)
	}

	for _, module := range jsonConfig.Module {
		t := module["type"]
		if t == "whmcs" {
			whmcs.MakeWHMCS(module["ip"], module["secret"])
		} else {
			log.Fatalf("Encountered unrecognized module type %s", t)
		}
	}

	for path, template := range jsonConfig.SplashRoutes {
		lobster.RegisterSplashRoute(path, template)
	}

	lobster.Run()
}