chef / knife-vsphere

Chef knife plug-in for VMware vSphere
Apache License 2.0
202 stars 125 forks source link

vm list recursive - bug! #490

Open ghost opened 4 years ago

ghost commented 4 years ago

Version:

Chef Workstation version: 0.12.20 knife-vsphere (4.0.7)

Environment:

ubuntu server 18.04 lts

Scenario:

trying to list the vms in vcenter using the recursive option

Steps to Reproduce:

knife vsphere vm list -r

ERROR: RbVmomi::Fault: InvalidLogin: Cannot complete login due to an incorrect user name or password.

knife vsphere vm list --recursive

(works correctly)

Expected Result:

I expected the '-r' option to work as in the documentation

"-r, --recursive - Recurse down through sub-folders to the specified folder"

Actual Result:

the error message is shown instead of vm listing

"ERROR: RbVmomi::Fault: InvalidLogin: Cannot complete login due to an incorrect user name or password."

the exact same command works with "--recursive" instead or "-r"

ghost commented 4 years ago

also, the documentation mentions

"... Only name is currently displayed."

This is incorrect. from the code you can see there are also IP,RAM,State

https://github.com/chef/knife-vsphere/blob/857e23a3d90e74974703dbbf96a8443da884bc31/lib/chef/knife/vsphere_vm_list.rb#L54-L57

eg.

Capture222

swalberg commented 4 years ago

Hey Scott, thanks for the bug report. Is that the exact command you're running or do you also log in on the command line? What version of the chef gem do you have installed?

Can you give a stack trace (-VV) for the -r case?

Just tried it here, with knife-vsphere 2.0.1 both -r and --recursive work fine. With what we have in master, --recursive works but -r gives me OptionParser::MissingArgument: missing argument: -r. If I do -r foo it works though.

It might be that -r gets used somewhere else in Chef because if I switch it to -a it works as expected.

Let me know what you see, please.

Thanks/

ghost commented 4 years ago

chef gem -v 3.0.3

WARNING: No knife configuration file found. See https://docs.chef.io/config_rb_knife.html for details. ERROR: RbVmomi::Fault: InvalidLogin: Cannot complete login due to an incorrect user name or password. root@SVR-AUSYD-SWD-HAWEB:~# knife vsphere vm list -r --vsuser administrator@vsphere.local --vspass QW@#23qw --vsdc Sydney --vshost 10.4.22.53 --vsinsecure true -VV WARNING: No knife configuration file found. See https://docs.chef.io/config_rb_knife.html for details. DEBUG: value for config item vsphere_host: 10.4.22.53 DEBUG: value for config item vsphere_path: /sdk DEBUG: value for config item vsphere_port: 443 DEBUG: value for config item vsphere_nossl: DEBUG: value for config item vsphere_user: DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_insecure: true DEBUG: value for config item proxy_host: DEBUG: value for config item proxy_port: Traceback (most recent call last): 16: from /usr/bin/knife:359:in <main>' 15: from /usr/bin/knife:359:inload' 14: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/bin/knife:24:in <top (required)>' 13: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/lib/chef/application/knife.rb:163:inrun' 12: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/lib/chef/knife.rb:229:in run' 11: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/lib/chef/knife.rb:485:inrun_with_pretty_exceptions' 10: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/lib/chef/local_mode.rb:42:in with_server_connectivity' 9: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.5.16/lib/chef/knife.rb:486:inblock in run_with_pretty_exceptions' 8: from /root/.chefdk/gem/ruby/2.6.0/gems/knife-vsphere-4.0.7/lib/chef/knife/vsphere_vm_list.rb:65:in run' 7: from /root/.chefdk/gem/ruby/2.6.0/gems/knife-vsphere-4.0.7/lib/chef/knife/base_vsphere_command.rb:121:invim_connection' 6: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/vim.rb:45:in connect' 5: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/vim.rb:45:intap' 4: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/vim.rb:62:in block in connect' 3: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/basic_types.rb:76:inblock (2 levels) in init' 2: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/basic_types.rb:213:in _call' 1: from /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/connection.rb:92:incall' /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/rbvmomi-2.2.0/lib/rbvmomi/connection.rb:63:in `parse_response': InvalidLogin: Cannot complete login due to an incorrect user name or password. (RbVmomi::Fault)

And this is the -VV for the working (--recursive) command

WARNING: No knife configuration file found. See https://docs.chef.io/config_rb_knife.html for details. DEBUG: value for config item vsphere_host: 10.4.22.53 DEBUG: value for config item vsphere_path: /sdk DEBUG: value for config item vsphere_port: 443 DEBUG: value for config item vsphere_nossl: DEBUG: value for config item vsphere_user: administrator@vsphere.local DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_pass: xxx DEBUG: value for config item vsphere_insecure: true DEBUG: value for config item proxy_host: DEBUG: value for config item proxy_port: DEBUG: value for config item folder: DEBUG: value for config item vsphere_dc: Sydney DEBUG: value for config item onlyfolders: DEBUG: value for config item recursive: true

From: Sean Walberg notifications@github.com Sent: Tuesday, 17 December 2019 10:53 AM To: chef/knife-vsphere knife-vsphere@noreply.github.com Cc: Scott Williams SWilliams@timg.com; Author author@noreply.github.com Subject: Re: [chef/knife-vsphere] vm list recursive - bug! (#490)

Hey Scott, thanks for the bug report. Is that the exact command you're running or do you also log in on the command line? What version of the chef gem do you have installed?

Can you give a stack trace (-VV) for the -r case?

Just tried it here, with knife-vsphere 2.0.1 both -r and --recursive work fine. With what we have in master, --recursive works but -r gives me OptionParser::MissingArgument: missing argument: -r. If I do -r foo it works though.

It might be that -r gets used somewhere else in Chef because if I switch it to -a it works as expected.

Let me know what you see, please.

Thanks/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_chef_knife-2Dvsphere_issues_490-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAOB3EKWW42LC54N2O4LZMPTQZA5KPA5CNFSM4J3US6KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHA6VUQ-23issuecomment-2D566356690&d=DwMCaQ&c=mfsj4EqbbtbBjM01gds5HQ&r=vDsBiJrIPZNB_cmQTzwq-Q&m=zi4nYzekJXbVbPpunU4flkKxRePmEw8rBJXhkubAwIo&s=Oedl-xK2-oqdFvhw8ZbbCqxLcufYIplDfwQM4BhWJ4A&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AOB3EKRTXLBYXPNYANRN5ITQZA5KPANCNFSM4J3US6KA&d=DwMCaQ&c=mfsj4EqbbtbBjM01gds5HQ&r=vDsBiJrIPZNB_cmQTzwq-Q&m=zi4nYzekJXbVbPpunU4flkKxRePmEw8rBJXhkubAwIo&s=xqu4fraMfGy4vt_R2sfUJG-ulYZexf1C9Kb2rH50iSM&e=.

swalberg commented 4 years ago

Aha, thanks for the traces. See how you've got -r --vsuser administrator@vsphere.local and when it works you get

DEBUG: value for config item vsphere_user: administrator@vsphere.local

but when it doesn't,

DEBUG: value for config item vsphere_user:

"something changed" in the parsing of that -r option so it's not seeing the full --vsuser after that. If you put -r at the end of the command line you'd probably get the same "missing argument" error that I got.

I will do some more digging later but my guess is I'll have to get rid of the short -r.

ghost commented 4 years ago

No worries, I have stopped using the short -r argument now.

I think the vm state command has the same issue:

knife vsphere vm state VMNAME
Manage power state of a virtual machine, aka turn it off and on
-s STATE, --state STATE    - The power state to transition the VM into; one of on|off|suspend|reboot
-w PORT, --wait-port PORT  - Wait for VM to be accessible on a port
-g, --shutdown             - Guest OS shutdown (format: -s off -g)
-r, --recursive            - Recurse down through sub-folders to the specified folder to find the VM

From: Sean Walberg notifications@github.com Sent: Tuesday, 17 December 2019 8:47 PM To: chef/knife-vsphere knife-vsphere@noreply.github.com Cc: Scott Williams SWilliams@timg.com; Author author@noreply.github.com Subject: Re: [chef/knife-vsphere] vm list recursive - bug! (#490)

Aha, thanks for the traces. See how you've got -r --vsuser administrator@vsphere.localmailto:administrator@vsphere.local and when it works you get

DEBUG: value for config item vsphere_user: administrator@vsphere.localmailto:administrator@vsphere.local

but when it doesn't,

DEBUG: value for config item vsphere_user:

"something changed" in the parsing of that -r option so it's not seeing the full --vsuser after that. If you put -r at the end of the command line you'd probably get the same "missing argument" error that I got.

I will do some more digging later but my guess is I'll have to get rid of the short -r.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_chef_knife-2Dvsphere_issues_490-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAOB3EKSNMO237QL7K56T3JDQZDC35A5CNFSM4J3US6KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHCII4A-23issuecomment-2D566527088&d=DwMCaQ&c=mfsj4EqbbtbBjM01gds5HQ&r=vDsBiJrIPZNB_cmQTzwq-Q&m=GCLOEHRSFtedxIvrWRM6PtkKMfbn_jSBZFE5g2WmWyU&s=MTKPPjk5pXQVnEGHD1kXu4-kldo3Hain6qExbR9HnIM&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AOB3EKVKJIBWCSS3QV3KWBDQZDC35ANCNFSM4J3US6KA&d=DwMCaQ&c=mfsj4EqbbtbBjM01gds5HQ&r=vDsBiJrIPZNB_cmQTzwq-Q&m=GCLOEHRSFtedxIvrWRM6PtkKMfbn_jSBZFE5g2WmWyU&s=82OGh19ajLsWd98sXq9zcT0zcEf7snQ0j2Pcq0RuBSk&e=.

swalberg commented 4 years ago

Anything that applies to an individual VM will search recursively anyway at this point. I guess I need to remove those options!