* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
117 lines
2.6 KiB
Go
117 lines
2.6 KiB
Go
/*
|
|
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package examples
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/vmware/govmomi"
|
|
"github.com/vmware/govmomi/vim25/soap"
|
|
)
|
|
|
|
// getEnvString returns string from environment variable.
|
|
func getEnvString(v string, def string) string {
|
|
r := os.Getenv(v)
|
|
if r == "" {
|
|
return def
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
// getEnvBool returns boolean from environment variable.
|
|
func getEnvBool(v string, def bool) bool {
|
|
r := os.Getenv(v)
|
|
if r == "" {
|
|
return def
|
|
}
|
|
|
|
switch strings.ToLower(r[0:1]) {
|
|
case "t", "y", "1":
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
const (
|
|
envURL = "GOVMOMI_URL"
|
|
envUserName = "GOVMOMI_USERNAME"
|
|
envPassword = "GOVMOMI_PASSWORD"
|
|
envInsecure = "GOVMOMI_INSECURE"
|
|
)
|
|
|
|
var urlDescription = fmt.Sprintf("ESX or vCenter URL [%s]", envURL)
|
|
var urlFlag = flag.String("url", getEnvString(envURL, "https://username:password@host/sdk"), urlDescription)
|
|
|
|
var insecureDescription = fmt.Sprintf("Don't verify the server's certificate chain [%s]", envInsecure)
|
|
var insecureFlag = flag.Bool("insecure", getEnvBool(envInsecure, false), insecureDescription)
|
|
|
|
func processOverride(u *url.URL) {
|
|
envUsername := os.Getenv(envUserName)
|
|
envPassword := os.Getenv(envPassword)
|
|
|
|
// Override username if provided
|
|
if envUsername != "" {
|
|
var password string
|
|
var ok bool
|
|
|
|
if u.User != nil {
|
|
password, ok = u.User.Password()
|
|
}
|
|
|
|
if ok {
|
|
u.User = url.UserPassword(envUsername, password)
|
|
} else {
|
|
u.User = url.User(envUsername)
|
|
}
|
|
}
|
|
|
|
// Override password if provided
|
|
if envPassword != "" {
|
|
var username string
|
|
|
|
if u.User != nil {
|
|
username = u.User.Username()
|
|
}
|
|
|
|
u.User = url.UserPassword(username, envPassword)
|
|
}
|
|
}
|
|
|
|
// NewClient creates a govmomi.Client for use in the examples
|
|
func NewClient(ctx context.Context) (*govmomi.Client, error) {
|
|
flag.Parse()
|
|
|
|
// Parse URL from string
|
|
u, err := soap.ParseURL(*urlFlag)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Override username and/or password as required
|
|
processOverride(u)
|
|
|
|
// Connect and log in to ESX or vCenter
|
|
return govmomi.NewClient(ctx, u, *insecureFlag)
|
|
}
|