@@ -104,16 +104,21 @@ func GetVmIp(machine Machine) string {
104
104
nodes := loadAllEsxiNodes ()
105
105
node := nodes [machine .NodeName ]
106
106
107
- buf , err := ioutil .ReadFile (node .IdentityFile )
108
- if err != nil {
109
- log .Println ("Fail to load identity file: " , err .Error ())
110
- return ""
111
- }
112
- key , err := ssh .ParsePrivateKey (buf )
113
- if err != nil {
114
- log .Println ("Fail to parse the private key: " , err .Error ())
115
- return ""
107
+ var key ssh.Signer
108
+ // Found identity file
109
+ if node .IdentityFile != "" {
110
+ buf , err := ioutil .ReadFile (node .IdentityFile )
111
+ if err != nil {
112
+ log .Println ("Fail to load identity file: " , err .Error ())
113
+ return ""
114
+ }
115
+ key , err = ssh .ParsePrivateKey (buf )
116
+ if err != nil {
117
+ log .Println ("Fail to parse the private key: " , err .Error ())
118
+ return ""
119
+ }
116
120
}
121
+
117
122
config := & ssh.ClientConfig {
118
123
User : node .User ,
119
124
HostKeyCallback : ssh .InsecureIgnoreHostKey (),
@@ -151,14 +156,20 @@ func GetVmIp(machine Machine) string {
151
156
func GetAllVmIdName () Machines {
152
157
allVm := Machines {}
153
158
for nodeName , nodeInfo := range loadAllEsxiNodes () {
154
- buf , err := ioutil .ReadFile (nodeInfo .IdentityFile )
155
- if err != nil {
156
- log .Fatalln ("Fail to load identity file: " , err )
157
- }
158
- key , err := ssh .ParsePrivateKey (buf )
159
- if err != nil {
160
- log .Fatalln ("Fail to parse the private key: " , err )
159
+
160
+ var key ssh.Signer
161
+ // Found identity file
162
+ if nodeInfo .IdentityFile != "" {
163
+ buf , err := ioutil .ReadFile (nodeInfo .IdentityFile )
164
+ if err != nil {
165
+ log .Fatalln ("Fail to load identity file: " , err )
166
+ }
167
+ key , err = ssh .ParsePrivateKey (buf )
168
+ if err != nil {
169
+ log .Fatalln ("Fail to parse the private key: " , err )
170
+ }
161
171
}
172
+ println (nodeInfo .User , nodeInfo .Port , nodeInfo .Address , nodeInfo .Password , key )
162
173
163
174
// ssh connect
164
175
nodeAddr := nodeInfo .Address
@@ -168,9 +179,8 @@ func GetAllVmIdName() Machines {
168
179
HostKeyCallback : ssh .InsecureIgnoreHostKey (),
169
180
Auth : []ssh.AuthMethod {
170
181
ssh .Password (nodeInfo .Password ),
171
- ssh .PublicKeys (key ),
182
+ // ssh.PublicKeys(key),
172
183
},
173
- Timeout : 3 ,
174
184
}
175
185
b , err := execCommandSsh (nodeAddr , nodePort , config , "vim-cmd vmsvc/getallvms" )
176
186
if err != nil {
0 commit comments