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:
83
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck.go
generated
vendored
Normal file
83
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck.go
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2016-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 vmcheck
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/vmware/vmw-guestinfo/bdoor"
|
||||
)
|
||||
|
||||
// From https://github.com/intel-go/cpuid/blob/master/cpuidlow_amd64.s
|
||||
// Get the CPU ID low level leaf values.
|
||||
func cpuid_low(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32)
|
||||
|
||||
// IsVirtualWorld returns true if running in a VM and the backdoor is available.
|
||||
func IsVirtualWorld() (bool, error) {
|
||||
// Test the HV bit is set
|
||||
if !IsVirtualCPU() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Test if backdoor port is available.
|
||||
if isVM, err := hypervisorPortCheck(); err != nil || !isVM {
|
||||
return isVM, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// hypervisorPortCheck tests the availability of the HV port.
|
||||
func hypervisorPortCheck() (bool, error) {
|
||||
// Privilege level 3 to access all ports above 0x3ff
|
||||
if err := openPortsAccess(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
p := &bdoor.BackdoorProto{}
|
||||
|
||||
p.CX.AsUInt32().SetWord(bdoor.CommandGetVersion)
|
||||
out := p.InOut()
|
||||
// if there is no device, we get back all 1s
|
||||
return (0xffffffff != out.AX.AsUInt32().Word()) && (0 != out.AX.AsUInt32().Word()), nil
|
||||
}
|
||||
|
||||
// IsVirtualCPU checks if the cpu is a virtual CPU running on ESX. It checks for
|
||||
// the HV bit in the ECX register of the CPUID leaf 0x1. Intel and AMD CPUs
|
||||
// reserve this bit to indicate if the CPU is running in a HV. See
|
||||
// https://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits
|
||||
// for details. If this bit is set, the reserved cpuid levels are used to pass
|
||||
// information from the HV to the guest. In ESX, this is the repeating string
|
||||
// "VMwareVMware".
|
||||
func IsVirtualCPU() bool {
|
||||
HV := uint32(1 << 31)
|
||||
_, _, c, _ := cpuid_low(0x1, 0)
|
||||
if (c & HV) != HV {
|
||||
return false
|
||||
}
|
||||
|
||||
_, b, c, d := cpuid_low(0x40000000, 0)
|
||||
|
||||
buf := make([]byte, 12)
|
||||
binary.LittleEndian.PutUint32(buf, b)
|
||||
binary.LittleEndian.PutUint32(buf[4:], c)
|
||||
binary.LittleEndian.PutUint32(buf[8:], d)
|
||||
|
||||
if string(buf) != "VMwareVMware" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
13
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_386.s
generated
vendored
Normal file
13
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_386.s
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "textflag.h"
|
||||
|
||||
// From https://github.com/intel-go/cpuid/blob/master/cpuidlow_amd64.s
|
||||
// func cpuid_low(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32)
|
||||
TEXT ·cpuid_low(SB), NOSPLIT, $0-24
|
||||
MOVL arg1+0(FP), AX
|
||||
MOVL arg2+4(FP), CX
|
||||
CPUID
|
||||
MOVL AX, eax+8(FP)
|
||||
MOVL BX, ebx+12(FP)
|
||||
MOVL CX, ecx+16(FP)
|
||||
MOVL DX, edx+20(FP)
|
||||
RET
|
||||
13
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_amd64.s
generated
vendored
Normal file
13
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_amd64.s
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "textflag.h"
|
||||
|
||||
// From https://github.com/intel-go/cpuid/blob/master/cpuidlow_amd64.s
|
||||
// func cpuid_low(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32)
|
||||
TEXT ·cpuid_low(SB), NOSPLIT, $0-24
|
||||
MOVL arg1+0(FP), AX
|
||||
MOVL arg2+4(FP), CX
|
||||
CPUID
|
||||
MOVL AX, eax+8(FP)
|
||||
MOVL BX, ebx+12(FP)
|
||||
MOVL CX, ecx+16(FP)
|
||||
MOVL DX, edx+20(FP)
|
||||
RET
|
||||
23
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_general.go
generated
vendored
Normal file
23
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_general.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2016-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.
|
||||
|
||||
// +build !linux
|
||||
|
||||
package vmcheck
|
||||
|
||||
// probably not gonna work. Instead, implement a platform-specific variant, and
|
||||
// add the platform to above build flags
|
||||
func openPortsAccess() error {
|
||||
return nil
|
||||
}
|
||||
22
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_linux.go
generated
vendored
Normal file
22
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_linux.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2016-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 vmcheck
|
||||
|
||||
import "syscall"
|
||||
|
||||
func openPortsAccess() error {
|
||||
// Privilege level 3 to access all ports above 0x3ff
|
||||
return syscall.Iopl(3)
|
||||
}
|
||||
37
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_test.go
generated
vendored
Normal file
37
vendor/github.com/vmware/vmw-guestinfo/vmcheck/vmcheck_test.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2016-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 vmcheck
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/vmware/vmw-guestinfo/util"
|
||||
)
|
||||
|
||||
func TestIsVirtualWorld(t *testing.T) {
|
||||
isBackdoor, err := hypervisorPortCheck()
|
||||
if !util.AssertNoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
t.Log("Backdoor available: ", isBackdoor)
|
||||
t.Log("CPU HV: ", IsVirtualCPU())
|
||||
|
||||
isVM, err := IsVirtualWorld()
|
||||
if !util.AssertNoError(t, err) {
|
||||
return
|
||||
}
|
||||
t.Log("Running in a VM: ", isVM)
|
||||
}
|
||||
Reference in New Issue
Block a user