Skip to content

Commit

Permalink
Merge pull request HewlettPackard#685 from HewlettPackard/refactor_sht
Browse files Browse the repository at this point in the history
refactored SHT resource
  • Loading branch information
VenkateshRavula authored May 10, 2021
2 parents 36aa0b9 + fe7f4b3 commit d56e7b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
56 changes: 29 additions & 27 deletions examples/oneview_server_hardware_type.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright (2016-2020) Hewlett Packard Enterprise Development LP
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,12 +28,12 @@
config: "{{ config }}"
state: present
data:
hostname : '{{ contents.server_hardware_hostname }}'
username : '{{ contents.server_hardware_username }}'
password : '{{ contents.server_hardware_password }}'
force : false
licensingIntent: "OneView"
configurationState: "Managed"
hostname : '{{ contents.server_hardware_hostname }}'
username : '{{ contents.server_hardware_username }}'
password : '{{ contents.server_hardware_password }}'
force : false
licensingIntent: "OneView"
configurationState: "Managed"
delegate_to: localhost
when: variant == 'C7000'

Expand All @@ -42,14 +42,13 @@
config: "{{ config }}"
delegate_to: localhost


- name: Update the Server Hardware Type description
oneview_server_hardware_type:
config: "{{ config }}"
state: present
data:
name: "{{ server_hardware_types[0]['name'] }}"
description: "New Description"
name: "{{ server_hardware_types[0]['name'] }}"
description: "New Description"
delegate_to: localhost

- name: Rename the Server Hardware Type
Expand All @@ -66,23 +65,26 @@
config: "{{ config }}"
state: present
data:
name: '{{ server_hardware_type_name_renamed }}'
newName: "{{ server_hardware_types[0]['name'] }}"
name: '{{ server_hardware_type_name_renamed }}'
newName: "{{ server_hardware_types[0]['name'] }}"
delegate_to: localhost

# This is only supported on appliances which support rack mounted servers.
- name: Remove the Server Hardware to be able to delete the Server Hardware Type (Prerequisite)
oneview_server_hardware:
config: "{{ config }}"
state: absent
data:
name: '{{ contents.server_hardware_hostname }}'
delegate_to: localhost
when: variant == 'C7000'

# - name: Remove the Server Hardware to be able to delete the Server Hardware Type (Prerequisite)
# oneview_server_hardware:
# config: "{{ config }}"
# state: absent
# data:
# name : '{{ server_hardware_hostname }}'
# delegate_to: localhost
#
# - name: Delete the Server Hardware Type
# oneview_server_hardware_type:
# config: "{{ config }}"
# state: absent
# data:
# name: '{{ server_hardware_type_name_renamed }}'
# delegate_to: localhost
# This is only supported on appliances which support rack mounted servers.
- name: Delete the Server Hardware Type
oneview_server_hardware_type:
config: "{{ config }}"
state: absent
data:
name: "{{ server_hardware_types[0]['name'] }}"
delegate_to: localhost
when: variant == 'C7000'
17 changes: 10 additions & 7 deletions library/oneview_server_hardware_type_facts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2020) Hewlett Packard Enterprise Development LP
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,11 @@
- Server Hardware Type name.
required: false
uri:
description:
- Server Hardware Type uri.
required: false
extends_documentation_fragment:
- oneview
- oneview.factsparams
Expand Down Expand Up @@ -91,18 +96,16 @@ class ServerHardwareTypeFactsModule(OneViewModule):
def __init__(self):
argument_spec = dict(
name=dict(required=False, type='str'),
uri=dict(required=False, type='str'),
params=dict(required=False, type='dict')
)
super(ServerHardwareTypeFactsModule, self).__init__(additional_arg_spec=argument_spec)

self.resource_client = self.oneview_client.server_hardware_types
self.set_resource_object(self.oneview_client.server_hardware_types)

def execute_module(self):

name = self.module.params.get('name')

if name:
server_hardware_types = self.resource_client.get_by('name', name)
if self.current_resource:
server_hardware_types = [self.current_resource.data]
else:
server_hardware_types = self.resource_client.get_all(**self.facts_params)

Expand Down
5 changes: 3 additions & 2 deletions test/test_oneview_server_hardware_type_facts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2019) Hewlett Packard Enterprise Development LP
# Copyright (2016-2021) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,8 @@ def test_should_get_all(self):
)

def test_should_get_server_hardware_type_by_name(self):
self.resource.get_by.return_value = [{"name": "Server Hardware Type Name"}]
self.resource.data = {"name": "Server Hardware Type Name"}
self.resource.get_by_name.return_value = self.resource
self.mock_ansible_module.params = PARAMS_GET_BY_NAME

ServerHardwareTypeFactsModule().run()
Expand Down

0 comments on commit d56e7b0

Please sign in to comment.