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

[WIP] VMware: Add new module VMware vSAN health infos #58636

Open
wants to merge 5 commits into
base: devel
from

Conversation

Projects
None yet
3 participants
@equelin
Copy link
Contributor

commented Jul 2, 2019

SUMMARY

Add a new module for gathering facts about VMware vSAN health.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

vmware_vsan_health_facts

ADDITIONAL INFORMATION
  • VMware vSAN python SDK need to be available.
  • Some modifications on module_utils/vmware.py were mandatory to return service_instance informations from connect_to_api.
@ansibot

This comment has been minimized.

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jul 2, 2019

@equelin, just so you are aware we have a dedicated Working Group for vmware.
You can find other people interested in this in #ansible-vmware on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@Akasurde Akasurde changed the title [WIP] new module VMware vSAN health facts (#9) [WIP] VMware: Add new module VMware vSAN health facts Jul 3, 2019

@@ -0,0 +1,173 @@
#!/usr/bin/python

# (c) 2019, OVH SAS

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
# (c) 2019, OVH SAS
# Copyright: (c) 2019, OVH SAS

DOCUMENTATION = '''
---
module: vmware_vsan_health_facts

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member

All facts modules are converted into info, so I would recommend you to rename this to vmware_vsan_health_info. Other module rename is happening here

---
module: vmware_vsan_health_facts
short_description: Gather facts about a VMware vSAN cluster's health.

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
short_description: Gather facts about a VMware vSAN cluster's health.
short_description: Gather information about a VMware vSAN cluster's health
version_added: "2.9"
description:
- "Gather facts about a VMware vSAN cluster's health"

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
- "Gather facts about a VMware vSAN cluster's health"
- "Gather information about a VMware vSAN cluster's health"
options:
cluster_name:
description:
- Name of the vSAN cluster

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
- Name of the vSAN cluster
- Name of the vSAN cluster.
description:
- Name of the vSAN cluster
required: true
type: string

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
type: string
type: str
type: string
fetch_from_cache:
description:
- True to return the result from cache directly instead of running the full health check.

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
- True to return the result from cache directly instead of running the full health check.
- C(True) to return the result from cache directly instead of running the full health check.
'''

EXAMPLES = '''
- name: Gather health facts from a vSAN's cluster

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
- name: Gather health facts from a vSAN's cluster
- name: Gather health info from a vSAN's cluster
- name: Gather health facts from a vSAN's cluster
hosts: localhost
gather_facts: 'no'
vmware_vsan_health_facts:

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
vmware_vsan_health_facts:
vmware_vsan_health_info:
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster_name: 'vSAN01'
fetch_from_cache: 'False'

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
fetch_from_cache: 'False'
fetch_from_cache: False

@ansibot ansibot removed the needs_triage label Jul 3, 2019

'''

RETURN = '''
health:

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
health:
vsan_health_info:

RETURN = '''
health:
description: vSAN cluster health facts

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
description: vSAN cluster health facts
description: vSAN cluster health info

def run_module():
argument_spec = vmware_argument_spec()
argument_spec.update(dict(cluster_name=dict(required=True, type='str')))

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
argument_spec.update(dict(cluster_name=dict(required=True, type='str')))
argument_spec.update(
cluster_name=dict(required=True, type='str'),
fetch_from_cache=dict(required=False, type='bool'),
)
argument_spec.update(dict(cluster_name=dict(required=True, type='str')))
argument_spec.update(dict(fetch_from_cache=dict(required=False, type='bool')))

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member

All info modules supports check mode,

Suggested change
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
client_stub = si._GetStub()
ssl_context = client_stub.schemeArgs.get('context')

cluster = find_cluster_by_name(content, module.params['cluster_name'])

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
cluster = find_cluster_by_name(content, module.params['cluster_name'])
cluster = find_cluster_by_name(content, module.params['cluster_name'])
if not cluster:
self.module.fail_json(msg="Failed to find cluster %(cluster_name)" % module.params)

health = json.dumps(clusterHealth, cls=VmomiSupport.VmomiJSONEncoder, sort_keys=True, strip_dynamic=True)

module.exit_json(changed=False, health=health)

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
module.exit_json(changed=False, health=health)
module.exit_json(changed=False, vsan_health_info=health)
from ansible.module_utils.vmware import connect_to_api, vmware_argument_spec, find_cluster_by_name


def run_module():

This comment has been minimized.

Copy link
@Akasurde

Akasurde Jul 3, 2019

Member
Suggested change
def run_module():
def main():
@Akasurde
Copy link
Member

left a comment

Thanks for the PR. Could you please add integration test for this change ? You can find the example integration tests for VMware here.

@Akasurde Akasurde self-assigned this Jul 3, 2019

@ansibot ansibot added the needs_rebase label Jul 3, 2019

@equelin

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2019

Hello @Akasurde, thanks for your review.

I've fixed the issues you spotted. I'm not sure how to deal with vSAN's integration test. Do you have any documentation that may help me ?

Regards

@Akasurde

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

There is no integration test for vSAN yet. But you may want to take a look at vmware_guest test cases for help. We are planning to have integration tests which will work with both govcsim and real vSphere environment.

I am not sure if govcsim supports vSAN infra, but you can write a testcase which will work on real vCenter environment and submit with this PR. You can check this test case for such use case.

Documentation about writing VMware test cases can be found in this PR #56814

Let me know if you need any information, I would be more than happy to help you.

Thanks.

@ansibot ansibot added the stale_ci label Jul 13, 2019

equelin added some commits Jul 2, 2019

[WIP] new module VMware vSAN health facts (#9)
* First commit of new module vsan health fact

* Fix typo in licence

* Fix issues after review

* Fix import issue and typo

* Fix import issue

* Fix blank line issue

@equelin equelin force-pushed the ovh:new_vmware_vsan_health_facts_module branch from 7dbe105 to 89a95e5 Jul 15, 2019

equelin added some commits Jul 15, 2019

@equelin

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2019

Hello @Akasurde,

Thx for your feedback! You're right to say that there is no support of vSAN in govcsim. Therefore I wrote integration tests that may be run locally. I pushed the tests in this PR if you want to have a look. Additionally I wrote a file test/integration/cloud-config-vcenter.iniwith this content:

[DEFAULT]
vcenter_username: <<redacted>>
vcenter_password: <<redacted>>
vcenter_hostname: <<redacted>>
vcenter_validate_certs: false
vcenter_cluster_name: <<redacted>>

When I try to run the integration test, I've got this return:

$ VMWARE_TEST_PLATFORM=static ansible-test integration --python 3.7 vmware_vsan_health_info
WARNING: Excluding tests marked "cloud/vcenter" which require the "docker" command: vmware_vsan_health_info
WARNING: All targets skipped.

I understand that the tests are skipped for some reasons but I don't know why... Any idea that may help ?

Regards

@equelin equelin changed the title [WIP] VMware: Add new module VMware vSAN health facts [WIP] VMware: Add new module VMware vSAN health infos Jul 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.