Пример #1
0
func main() {
	cfgPath := "lobster.cfg"
	if len(os.Args) >= 2 {
		cfgPath = os.Args[1]
	}
	app := lobster.MakeLobster(cfgPath)
	app.Init()

	// virtual machine interfaces
	lndToronto := lndynamic.MakeLNDynamic("toronto", "apiId", "apiKey")
	app.RegisterVmInterface("Toronto", lndToronto)

	solusKVM := &solusvm.SolusVM{
		VirtType:  "kvm",
		NodeGroup: "1",
		Api: &solusvm.API{
			Url:      "https://167.114.196.224:5656/api/admin/command.php",
			ApiId:    "RZGxoFGpgpGiudvIatxsg0a4tEaH1mnQTM5nhjux",
			ApiKey:   "PCSTZqTiObpOci9GN9cCkqi43chamBx36gLUwu3b",
			Insecure: true,
		},
	}
	app.RegisterVmInterface("KVM", soluskvm)

	solusVZ := &solusvm.SolusVM{
		VirtType:  "openvz",
		NodeGroup: "1",
		Lobster:   app,
		Api: &solusvm.API{
			Url:      "https://167.114.196.224:5656/api/admin/command.php",
			ApiId:    "RZGxoFGpgpGiudvIatxsg0a4tEaH1mnQTM5nhjux",
			ApiKey:   "PCSTZqTiObpOci9GN9cCkqi43chamBx36gLUwu3b",
			Insecure: true,
		},
	}
	app.RegisterVmInterface("OpenVZ", solusVZ)

	openstack := lobopenstack.MakeOpenStack("http://*****:*****@example.com", "https://example.com/")
	app.RegisterPaymentInterface("Paypal", paypal)
	coinbase := lobster.MakeCoinbasePayment(app, "callback secret", "apiId", "apiKey")
	app.RegisterPaymentInterface("Bitcoin", coinbase)

	app.Run()
}
Пример #2
0
func main() {
	cfgPath := "lobster.cfg"
	if len(os.Args) >= 2 {
		cfgPath = os.Args[1]
	}
	app := lobster.MakeLobster(cfgPath)
	app.Init()

	// load interface configuration
	interfacePath := cfgPath + ".json"
	interfaceConfigBytes, err := ioutil.ReadFile(interfacePath)
	if err != nil {
		log.Fatalf("Error: failed to read interface configuration file %s: %s", interfacePath, err.Error())
	}
	var interfaceConfig InterfaceConfig
	err = json.Unmarshal(interfaceConfigBytes, &interfaceConfig)
	if err != nil {
		log.Fatalf("Error: failed to parse interface configuration: %s", err.Error())
	}

	for _, vm := range interfaceConfig.Vm {
		log.Printf("Initializing VM interface %s (type=%s)", vm.Name, vm.Type)
		var vmi lobster.VmInterface
		if vm.Type == "openstack" {
			vmi = lobopenstack.MakeOpenStack(vm.Url, vm.Username, vm.Password, vm.Tenant, vm.NetworkId)
		} else if vm.Type == "solusvm" {
			vmi = &solusvm.SolusVM{
				Lobster:   app,
				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 == "lndynamic" {
			vmi = lndynamic.MakeLNDynamic(vm.Region, vm.ApiId, vm.ApiKey)
		} else if vm.Type == "fake" {
			vmi = new(vmfake.Fake)
		} else if vm.Type == "digitalocean" {
			vmi = vmdigitalocean.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: %d", vm.Region)
			}
			vmi = vmvultr.MakeVultr(vm.ApiKey, regionId)
		} else {
			log.Fatalf("Encountered unrecognized VM interface type %s", vm.Type)
		}
		log.Println("... initialized successfully")
		app.RegisterVmInterface(vm.Name, vmi)
	}

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

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

	app.Run()
}