mirror of https://github.com/k3s-io/k3s
Rename VSphereConnection.GoVmomiClient -> Client
parent
64601373f1
commit
e7f74d83c6
|
@ -360,7 +360,7 @@ func (nm *NodeManager) renewNodeInfo(nodeInfo *NodeInfo, reconnect bool) (*NodeI
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vm := nodeInfo.vm.RenewVM(vsphereInstance.conn.GoVmomiClient)
|
vm := nodeInfo.vm.RenewVM(vsphereInstance.conn.Client)
|
||||||
return &NodeInfo{vm: &vm, dataCenter: vm.Datacenter, vcServer: nodeInfo.vcServer}, nil
|
return &NodeInfo{vm: &vm, dataCenter: vm.Datacenter, vcServer: nodeInfo.vcServer}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
// VSphereConnection contains information for connecting to vCenter
|
// VSphereConnection contains information for connecting to vCenter
|
||||||
type VSphereConnection struct {
|
type VSphereConnection struct {
|
||||||
GoVmomiClient *vim25.Client
|
Client *vim25.Client
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Hostname string
|
Hostname string
|
||||||
|
@ -43,23 +43,23 @@ var (
|
||||||
clientLock sync.Mutex
|
clientLock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// Connect makes connection to vCenter and sets VSphereConnection.GoVmomiClient.
|
// Connect makes connection to vCenter and sets VSphereConnection.Client.
|
||||||
// If connection.GoVmomiClient is already set, it obtains the existing user session.
|
// If connection.Client is already set, it obtains the existing user session.
|
||||||
// if user session is not valid, connection.GoVmomiClient will be set to the new client.
|
// if user session is not valid, connection.Client will be set to the new client.
|
||||||
func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
clientLock.Lock()
|
clientLock.Lock()
|
||||||
defer clientLock.Unlock()
|
defer clientLock.Unlock()
|
||||||
|
|
||||||
if connection.GoVmomiClient == nil {
|
if connection.Client == nil {
|
||||||
connection.GoVmomiClient, err = connection.NewClient(ctx)
|
connection.Client, err = connection.NewClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create govmomi client. err: %+v", err)
|
glog.Errorf("Failed to create govmomi client. err: %+v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m := session.NewManager(connection.GoVmomiClient)
|
m := session.NewManager(connection.Client)
|
||||||
userSession, err := m.UserSession(ctx)
|
userSession, err := m.UserSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error while obtaining user session. err: %+v", err)
|
glog.Errorf("Error while obtaining user session. err: %+v", err)
|
||||||
|
@ -70,7 +70,7 @@ func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
glog.Warningf("Creating new client session since the existing session is not valid or not authenticated")
|
glog.Warningf("Creating new client session since the existing session is not valid or not authenticated")
|
||||||
|
|
||||||
connection.GoVmomiClient, err = connection.NewClient(ctx)
|
connection.Client, err = connection.NewClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create govmomi client. err: %+v", err)
|
glog.Errorf("Failed to create govmomi client. err: %+v", err)
|
||||||
return err
|
return err
|
||||||
|
@ -80,7 +80,7 @@ func (connection *VSphereConnection) Connect(ctx context.Context) error {
|
||||||
|
|
||||||
// Logout calls SessionManager.Logout for the given connection.
|
// Logout calls SessionManager.Logout for the given connection.
|
||||||
func (connection *VSphereConnection) Logout(ctx context.Context) {
|
func (connection *VSphereConnection) Logout(ctx context.Context) {
|
||||||
m := session.NewManager(connection.GoVmomiClient)
|
m := session.NewManager(connection.Client)
|
||||||
if err := m.Logout(ctx); err != nil {
|
if err := m.Logout(ctx); err != nil {
|
||||||
glog.Errorf("Logout failed: %s", err)
|
glog.Errorf("Logout failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ type Datacenter struct {
|
||||||
// GetDatacenter returns the DataCenter Object for the given datacenterPath
|
// GetDatacenter returns the DataCenter Object for the given datacenterPath
|
||||||
// If datacenter is located in a folder, include full path to datacenter else just provide the datacenter name
|
// If datacenter is located in a folder, include full path to datacenter else just provide the datacenter name
|
||||||
func GetDatacenter(ctx context.Context, connection *VSphereConnection, datacenterPath string) (*Datacenter, error) {
|
func GetDatacenter(ctx context.Context, connection *VSphereConnection, datacenterPath string) (*Datacenter, error) {
|
||||||
finder := find.NewFinder(connection.GoVmomiClient, false)
|
finder := find.NewFinder(connection.Client, false)
|
||||||
datacenter, err := finder.Datacenter(ctx, datacenterPath)
|
datacenter, err := finder.Datacenter(ctx, datacenterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to find the datacenter: %s. err: %+v", datacenterPath, err)
|
glog.Errorf("Failed to find the datacenter: %s. err: %+v", datacenterPath, err)
|
||||||
|
@ -52,7 +52,7 @@ func GetDatacenter(ctx context.Context, connection *VSphereConnection, datacente
|
||||||
// GetAllDatacenter returns all the DataCenter Objects
|
// GetAllDatacenter returns all the DataCenter Objects
|
||||||
func GetAllDatacenter(ctx context.Context, connection *VSphereConnection) ([]*Datacenter, error) {
|
func GetAllDatacenter(ctx context.Context, connection *VSphereConnection) ([]*Datacenter, error) {
|
||||||
var dc []*Datacenter
|
var dc []*Datacenter
|
||||||
finder := find.NewFinder(connection.GoVmomiClient, false)
|
finder := find.NewFinder(connection.Client, false)
|
||||||
datacenters, err := finder.DatacenterList(ctx, "*")
|
datacenters, err := finder.DatacenterList(ctx, "*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to find the datacenter. err: %+v", err)
|
glog.Errorf("Failed to find the datacenter. err: %+v", err)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestDatacenter(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vc := &VSphereConnection{GoVmomiClient: c.Client}
|
vc := &VSphereConnection{Client: c.Client}
|
||||||
|
|
||||||
_, err = GetDatacenter(ctx, vc, testNameNotFound)
|
_, err = GetDatacenter(ctx, vc, testNameNotFound)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestDatastore(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vc := &VSphereConnection{GoVmomiClient: c.Client}
|
vc := &VSphereConnection{Client: c.Client}
|
||||||
|
|
||||||
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestFolder(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vc := &VSphereConnection{GoVmomiClient: c.Client}
|
vc := &VSphereConnection{Client: c.Client}
|
||||||
|
|
||||||
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestUtils(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vc := &VSphereConnection{GoVmomiClient: c.Client}
|
vc := &VSphereConnection{Client: c.Client}
|
||||||
|
|
||||||
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TestVirtualMachine(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vc := &VSphereConnection{GoVmomiClient: c.Client}
|
vc := &VSphereConnection{Client: c.Client}
|
||||||
|
|
||||||
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -410,7 +410,7 @@ func newControllerNode(cfg VSphereConfig) (*VSphere, error) {
|
||||||
|
|
||||||
func logout(vs *VSphere) {
|
func logout(vs *VSphere) {
|
||||||
for _, vsphereIns := range vs.vsphereInstanceMap {
|
for _, vsphereIns := range vs.vsphereInstanceMap {
|
||||||
if vsphereIns.conn.GoVmomiClient != nil {
|
if vsphereIns.conn.Client != nil {
|
||||||
vsphereIns.conn.Logout(context.TODO())
|
vsphereIns.conn.Logout(context.TODO())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue