Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added local accounts workflow sample code for Vcenter Appliance #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kumahesh
Copy link

No description provided.

@vmwclabot
Copy link
Member

@kumahesh, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Copy link
Contributor

@pgbidkar pgbidkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please run PEP8 to fix formatting issue?

samples/vsphere/appliances/local_accounts.py Outdated Show resolved Hide resolved
samples/vsphere/appliances/local_accounts.py Outdated Show resolved Hide resolved
@vmwclabot
Copy link
Member

@kumahesh, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@kumahesh
Copy link
Author

@tianhao64 , Could you please review this.

Comment on lines +112 to +118
def main():
try:
local_accounts = LocalAccounts()
local_accounts.run()
except Exception:
import traceback
traceback.print_exc()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try except doesn't add any value. Remove it.

parser = sample_cli.build_arg_parser()
args = sample_util.process_cli_args(parser.parse_args())
session = get_unverified_session() if args.skipverification else None
self.client = create_vsphere_client(server=args.server,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either use self.client.appliance.LocalAccounts directly in sample body, or make self.client a method scope variable.

Deletes the created local account at the end.
"""

print("Listing available accounts")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add /n at the beginning of each print? So it will look nicer.

username = input("username ::")
pprint(self.local_accounts.get(username))
except NotFound as e:
print("Local Account mentioned is not found")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can raise an ValueError here, instead of just print.

print("Local Account mentioned is not found")

def list_accounts(self):
pprint(self.local_accounts.list())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is not needed.

self.list_accounts()
account_created = True
except AlreadyExists as e:
print("local account is already present")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-raise exceptions instead of print, so the issues are more obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants