VMware vSphere Integrated Containers provider (#206)
* 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
This commit is contained in:
1
vendor/github.com/vmware/govmomi/vcsim/.gitignore
generated
vendored
Normal file
1
vendor/github.com/vmware/govmomi/vcsim/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
vcsim
|
||||
127
vendor/github.com/vmware/govmomi/vcsim/README.md
generated
vendored
Normal file
127
vendor/github.com/vmware/govmomi/vcsim/README.md
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
# vcsim - A vCenter and ESXi API based simulator
|
||||
|
||||
This package implements a vSphere Web Services (SOAP) SDK endpoint intended for testing consumers of the API.
|
||||
While the mock framework is written in the Go language, it can be used by any language that can talk to the vSphere
|
||||
API.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
% export GOPATH=$HOME/gopath
|
||||
% go get -u github.com/vmware/govmomi/vcsim
|
||||
% $GOPATH/bin/vcsim -h
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The **vcsim** program by default creates a *vCenter* model with a datacenter, hosts, cluster, resource pools, networks
|
||||
and a datastore. The naming is similar to that of the original *vcsim* mode that was included with vCenter. The number
|
||||
of resources can be increased or decreased using the various resource type flags. Resources can also be created and
|
||||
removed using the API.
|
||||
|
||||
Example using the default settings:
|
||||
|
||||
```
|
||||
% export GOVC_URL=https://user:pass@127.0.0.1:8989
|
||||
% $GOPATH/bin/vcsim
|
||||
% govc find
|
||||
/
|
||||
/DC0
|
||||
/DC0/vm
|
||||
/DC0/vm/DC0_H0_VM0
|
||||
/DC0/vm/DC0_H0_VM1
|
||||
/DC0/vm/DC0_C0_RP0_VM0
|
||||
/DC0/vm/DC0_C0_RP0_VM1
|
||||
/DC0/host
|
||||
/DC0/host/DC0_H0
|
||||
/DC0/host/DC0_H0/DC0_H0
|
||||
/DC0/host/DC0_H0/Resources
|
||||
/DC0/host/DC0_C0
|
||||
/DC0/host/DC0_C0/DC0_C0_H0
|
||||
/DC0/host/DC0_C0/DC0_C0_H1
|
||||
/DC0/host/DC0_C0/DC0_C0_H2
|
||||
/DC0/host/DC0_C0/Resources
|
||||
/DC0/datastore
|
||||
/DC0/datastore/LocalDS_0
|
||||
/DC0/network
|
||||
/DC0/network/VM Network
|
||||
/DC0/network/DVS0
|
||||
/DC0/network/DC0_DVPG0
|
||||
```
|
||||
|
||||
Example using ESX mode:
|
||||
|
||||
```
|
||||
% $GOPATH/vcsim -esx
|
||||
% govc find
|
||||
/
|
||||
/ha-datacenter
|
||||
/ha-datacenter/vm
|
||||
/ha-datacenter/vm/ha-host_VM0
|
||||
/ha-datacenter/vm/ha-host_VM1
|
||||
/ha-datacenter/host
|
||||
/ha-datacenter/host/localhost.localdomain
|
||||
/ha-datacenter/host/localhost.localdomain/localhost.localdomain
|
||||
/ha-datacenter/host/localhost.localdomain/Resources
|
||||
/ha-datacenter/datastore
|
||||
/ha-datacenter/datastore/LocalDS_0
|
||||
/ha-datacenter/network
|
||||
/ha-datacenter/network/VM Network
|
||||
|
||||
```
|
||||
|
||||
## Supported methods
|
||||
|
||||
The simulator supports a subset of API methods. However, the generated [govmomi](https://github.com/vmware/govmomi)
|
||||
code includes all types and methods defined in the vmodl, which can be used to implement any method documented in the
|
||||
[VMware vSphere API Reference](http://pubs.vmware.com/vsphere-6-5/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html).
|
||||
|
||||
To see the list of supported methods:
|
||||
|
||||
```
|
||||
curl -sk https://user:pass@127.0.0.1:8989/about
|
||||
```
|
||||
|
||||
## Listen address
|
||||
|
||||
The default vcsim listen address is `127.0.0.1:8989`. Use the `-httptest.serve` flag to listen on another address:
|
||||
|
||||
|
||||
``` shell
|
||||
vcsim -httptest.serve=10.118.69.224:8989 # specific address
|
||||
|
||||
vcsim -httptest.serve=:8989 # any address
|
||||
```
|
||||
|
||||
When given a port value of '0', an unused port will be chosen. You can then source the GOVC_URL from another
|
||||
process, for example:
|
||||
|
||||
```sh
|
||||
govc_sim_env=$TMPDIR/vcsim-$(uuidgen)
|
||||
|
||||
mkfifo $govc_sim_env
|
||||
|
||||
vcsim -httptest.serve=127.0.0.1:0 -E $govc_sim_env &
|
||||
|
||||
eval "$(cat $govc_sim_env)"
|
||||
|
||||
# ... run tests ...
|
||||
|
||||
kill $GOVC_SIM_PID
|
||||
rm -f $govc_sim_env
|
||||
```
|
||||
|
||||
Tests written in Go can also use the [simulator package](https://godoc.org/github.com/vmware/govmomi/simulator)
|
||||
directly, rather than the vcsim binary.
|
||||
|
||||
## Project using vcsim
|
||||
|
||||
* [VMware VIC Engine](https://github.com/vmware/vic)
|
||||
|
||||
* [Kubernetes](https://github.com/kubernetes/kubernetes/tree/master/pkg/cloudprovider/providers/vsphere)
|
||||
|
||||
* [Ansible](https://github.com/ansible/ansible/tree/devel/test/utils/docker/vcenter-simulator)
|
||||
|
||||
## Related projects
|
||||
|
||||
[LocalStack](https://github.com/localstack/localstack/blob/master/README.md#why-localstack)
|
||||
142
vendor/github.com/vmware/govmomi/vcsim/main.go
generated
vendored
Normal file
142
vendor/github.com/vmware/govmomi/vcsim/main.go
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
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 main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"expvar"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/vmware/govmomi/simulator"
|
||||
"github.com/vmware/govmomi/simulator/esx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
model := simulator.VPX()
|
||||
|
||||
flag.IntVar(&model.Datacenter, "dc", model.Datacenter, "Number of datacenters")
|
||||
flag.IntVar(&model.Cluster, "cluster", model.Cluster, "Number of clusters")
|
||||
flag.IntVar(&model.ClusterHost, "host", model.ClusterHost, "Number of hosts per cluster")
|
||||
flag.IntVar(&model.Host, "standalone-host", model.Host, "Number of standalone hosts")
|
||||
flag.IntVar(&model.Datastore, "ds", model.Datastore, "Number of local datastores")
|
||||
flag.IntVar(&model.Machine, "vm", model.Machine, "Number of virtual machines per resource pool")
|
||||
flag.IntVar(&model.Pool, "pool", model.Pool, "Number of resource pools per compute resource")
|
||||
flag.IntVar(&model.App, "app", model.App, "Number of virtual apps per compute resource")
|
||||
flag.IntVar(&model.Pod, "pod", model.Pod, "Number of storage pods per datacenter")
|
||||
flag.IntVar(&model.Portgroup, "pg", model.Portgroup, "Number of port groups")
|
||||
flag.IntVar(&model.Folder, "folder", model.Folder, "Number of folders")
|
||||
flag.BoolVar(&model.Autostart, "autostart", model.Autostart, "Autostart model created VMs")
|
||||
|
||||
isESX := flag.Bool("esx", false, "Simulate standalone ESX")
|
||||
isTLS := flag.Bool("tls", true, "Enable TLS")
|
||||
cert := flag.String("tlscert", "", "Path to TLS certificate file")
|
||||
key := flag.String("tlskey", "", "Path to TLS key file")
|
||||
env := flag.String("E", "-", "Output vcsim variables to the given fifo or stdout")
|
||||
flag.BoolVar(&simulator.Trace, "trace", simulator.Trace, "Trace SOAP to stderr")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
switch flag.Arg(0) {
|
||||
case "uuidgen": // util-linux not installed on Travis CI
|
||||
fmt.Println(uuid.New().String())
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
out := os.Stdout
|
||||
|
||||
if *env != "-" {
|
||||
out, err = os.OpenFile(*env, os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
f := flag.Lookup("httptest.serve")
|
||||
if f.Value.String() == "" {
|
||||
// #nosec: Errors unhandled
|
||||
_ = f.Value.Set("127.0.0.1:8989")
|
||||
}
|
||||
|
||||
if *isESX {
|
||||
opts := model
|
||||
model = simulator.ESX()
|
||||
// Preserve options that also apply to ESX
|
||||
model.Datastore = opts.Datastore
|
||||
model.Machine = opts.Machine
|
||||
model.Autostart = opts.Autostart
|
||||
}
|
||||
|
||||
tag := " (govmomi simulator)"
|
||||
model.ServiceContent.About.Name += tag
|
||||
model.ServiceContent.About.OsType = runtime.GOOS + "-" + runtime.GOARCH
|
||||
|
||||
esx.HostSystem.Summary.Hardware.Vendor += tag
|
||||
|
||||
err = model.Create()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if *isTLS {
|
||||
model.Service.TLS = new(tls.Config)
|
||||
if *cert != "" {
|
||||
c, err := tls.LoadX509KeyPair(*cert, *key)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
model.Service.TLS.Certificates = []tls.Certificate{c}
|
||||
}
|
||||
}
|
||||
|
||||
expvar.Publish("vcsim", expvar.Func(func() interface{} {
|
||||
count := model.Count()
|
||||
|
||||
return struct {
|
||||
Registry *simulator.Registry
|
||||
Model *simulator.Model
|
||||
}{
|
||||
simulator.Map,
|
||||
&count,
|
||||
}
|
||||
}))
|
||||
|
||||
model.Service.ServeMux = http.DefaultServeMux // expvar.init registers "/debug/vars" with the DefaultServeMux
|
||||
|
||||
s := model.Service.NewServer()
|
||||
|
||||
fmt.Fprintf(out, "export GOVC_URL=%s GOVC_SIM_PID=%d\n", s.URL, os.Getpid())
|
||||
if out != os.Stdout {
|
||||
_ = out.Close()
|
||||
}
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
<-sig
|
||||
|
||||
model.Remove()
|
||||
}
|
||||
Reference in New Issue
Block a user