// Send an API request to make server start a discovery process on current k8s.
func (handler *KubernetesServerMessageHandler) DiscoverTarget() {
	vmtUrl := handler.wsComm.VmtServerAddress

	extCongfix := make(map[string]string)
	extCongfix["Username"] = handler.meta.OpsManagerUsername
	extCongfix["Password"] = handler.meta.OpsManagerPassword
	vmturboApi := vmtapi.NewVmtApi(vmtUrl, extCongfix)

	// Discover Kubernetes target.
	vmturboApi.DiscoverTarget(handler.meta.NameOrAddress)
}
Esempio n. 2
0
// Code is very similar to those in serverMsgHandler.
func (vmtcomm *VMTCommunicator) DiscoverTarget() {
	vmtUrl := vmtcomm.wsComm.VmtServerAddress

	extCongfix := make(map[string]string)
	extCongfix["Username"] = "******"
	extCongfix["Password"] = "******"
	vmturboApi := vmtapi.NewVmtApi(vmtUrl, extCongfix)

	// Discover Kubernetes target.
	vmturboApi.DiscoverTarget(vmtcomm.meta.NameOrAddress)
}
// Use the vmt restAPI to add a Kubernetes target.
func (handler *KubernetesServerMessageHandler) AddTarget() {
	vmtUrl := handler.wsComm.VmtServerAddress

	extCongfix := make(map[string]string)
	extCongfix["Username"] = handler.meta.OpsManagerUsername
	extCongfix["Password"] = handler.meta.OpsManagerPassword
	vmturboApi := vmtapi.NewVmtApi(vmtUrl, extCongfix)

	// Add Kubernetes target.
	// targetType, nameOrAddress, targetIdentifier, password
	vmturboApi.AddK8sTarget(handler.meta.TargetType, handler.meta.NameOrAddress, handler.meta.Username, handler.meta.TargetIdentifier, handler.meta.Password)
}
Esempio n. 4
0
// Create the reservation specification and
// return map which has pod name as key and node name as value
func (this *Reservation) RequestPlacement(podName string, requestSpec, filterProperties map[string]string) (map[string]string, error) {
	extCongfix := make(map[string]string)
	extCongfix["Username"] = this.Meta.OpsManagerUsername
	extCongfix["Password"] = this.Meta.OpsManagerPassword
	vmturboApi := vmtapi.NewVmtApi(this.Meta.ServerAddress, extCongfix)

	glog.V(4).Info("Inside RequestPlacement")

	parameterString, err := buildReservationParameterString(requestSpec)
	if err != nil {
		return nil, err
	}

	reservationUUID, err := vmturboApi.Post("/reservations", parameterString)
	if err != nil {
		return nil, fmt.Errorf("Error posting reservations: %s", err)
	}
	reservationUUID = strings.Replace(reservationUUID, "\n", "", -1)
	glog.Infof("Reservation UUID is %s", string(reservationUUID))

	// TODO, do we want to wait for a predefined time or send send API requests multiple times.
	time.Sleep(2 * time.Second)
	getResponse, err := vmturboApi.Get("/reservations/" + reservationUUID)
	if err != nil {
		return nil, fmt.Errorf("Error getting reservations destinations: %s", err)
	}
	pod2nodeMap, err := parseGetReservationResponse(podName, getResponse)
	if err != nil {
		return nil, fmt.Errorf("Error parsing reservation destination returned from VMTurbo server: %s", err)
	}

	// After getting the destination, delete the reservation.
	deleteResponse, err := vmturboApi.Delete("/reservations/" + reservationUUID)
	if err != nil {
		// TODO, Should we return without placement?
		return nil, fmt.Errorf("Error deleting reservations destinations: %s", err)
	}
	glog.Infof("delete response of reservation %s is %s", reservationUUID, deleteResponse)

	return pod2nodeMap, nil
}