func createDirectorRepo(reqs ...gogobosh.TestRequest) (ts *httptest.Server, handler *gogobosh.TestHandler, repo gogobosh.DirectorRepository) {
	ts, handler = gogobosh.NewTLSServer(reqs)
	config := &gogobosh.Director{
		TargetURL: ts.URL,
		Username:  "******",
		Password:  "******",
	}
	gateway := gogobosh.NewDirectorGateway()
	repo = gogobosh.NewBoshDirectorRepository(config, gateway)
	return
}
func main() {
	gogobosh.Logger = gogobosh.NewLogger()

	target := flag.String("target", "https://192.168.50.4:25555", "BOSH director host")
	username := flag.String("username", "admin", "Login with username")
	password := flag.String("password", "admin", "Login with password")
	flag.Parse()

	director := gogobosh.NewDirector(*target, *username, *password)
	repo := gogobosh.NewBoshDirectorRepository(&director, gogobosh.NewDirectorGateway())

	info, apiResponse := repo.GetInfo()
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch BOSH info")
		return
	}

	fmt.Println("Director")
	fmt.Printf("  Name       %s\n", info.Name)
	fmt.Printf("  URL        %s\n", info.URL)
	fmt.Printf("  Version    %s\n", info.Version)
	fmt.Printf("  User       %s\n", info.User)
	fmt.Printf("  UUID       %s\n", info.UUID)
	fmt.Printf("  CPI        %s\n", info.CPI)
	if info.DNSEnabled {
		fmt.Printf("  dns        %#v (%s)\n", info.DNSEnabled, info.DNSDomainName)
	} else {
		fmt.Printf("  dns        %#v\n", info.DNSEnabled)
	}
	if info.CompiledPackageCacheEnabled {
		fmt.Printf("  compiled_package_cache %#v (provider: %s)\n", info.CompiledPackageCacheEnabled, info.CompiledPackageCacheProvider)
	} else {
		fmt.Printf("  compiled_package_cache %#v\n", info.CompiledPackageCacheEnabled)
	}
	fmt.Printf("  snapshots  %#v\n", info.SnapshotsEnabled)
	fmt.Println("")
	fmt.Printf("%#v\n", info)
	fmt.Println("")

	stemcells, apiResponse := repo.GetStemcells()
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch BOSH stemcells")
		return
	} else {
		for _, stemcell := range stemcells {
			fmt.Printf("%#v\n", stemcell)
		}
		fmt.Println("")
	}

	releases, apiResponse := repo.GetReleases()
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch BOSH releases")
		return
	} else {
		for _, release := range releases {
			fmt.Printf("%#v\n", release)
		}
		fmt.Println("")
	}

	deployments, apiResponse := repo.GetDeployments()
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch BOSH deployments")
		return
	} else {
		for _, deployment := range deployments {
			fmt.Printf("%#v\n", deployment)
		}
		fmt.Println("")
	}

	task, apiResponse := repo.GetTaskStatus(1)
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch BOSH task 1")
		return
	} else {
		fmt.Printf("%#v\n", task)
	}

	fmt.Println("")
	fmt.Println("VMs in cf-warden deployment:")
	vms, apiResponse := repo.ListDeploymentVMs("cf-warden")
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not get list of VM for cf-warden")
		return
	} else {
		for _, vm := range vms {
			fmt.Printf("%#v\n", vm)
		}
	}

	fmt.Println("")
	fmt.Println("VMs status in cf-warden deployment:")
	vmsStatuses, apiResponse := repo.FetchVMsStatus("cf-warden")
	if apiResponse.IsNotSuccessful() {
		fmt.Println("Could not fetch VMs status for cf-warden")
		return
	} else {
		for _, vmStatus := range vmsStatuses {
			fmt.Printf("%s/%d is %s, IPs %#v\n", vmStatus.JobName, vmStatus.Index, vmStatus.JobState, vmStatus.IPs)
		}
	}
}
Exemple #3
0
package gogobosh_test

import (
	gogobosh "github.com/cloudfoundry-community/gogobosh"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"runtime"
)

var _ = Describe("Gateway", func() {
	It("NewRequest successfully", func() {
		gateway := gogobosh.NewDirectorGateway()

		request, apiResponse := gateway.NewRequest("GET", "https://example.com/v2/apps", "admin", "admin", nil)

		Expect(apiResponse.IsSuccessful()).To(Equal(true))
		Expect(request.HttpReq.Header.Get("Authorization")).To(Equal("Basic YWRtaW46YWRtaW4="))
		Expect(request.HttpReq.Header.Get("accept")).To(Equal("application/json"))
		Expect(request.HttpReq.Header.Get("User-Agent")).To(Equal("gogobosh " + gogobosh.Version + " / " + runtime.GOOS))
	})
})