Skip to content

Commit

Permalink
Merge pull request #477 from HewlettPackard/1200_pools
Browse files Browse the repository at this point in the history
API 800,1000 & 1200 - storage pools
  • Loading branch information
sijeesh authored Feb 3, 2020
2 parents ac52e93 + e717015 commit f4f0706
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 105 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ This release extends the planned support of the modules to OneView REST API vers
- oneview_server_profile_facts
- oneview_server_profile_template
- oneview_server_profile_template_facts
- oneview_storage_pool
- oneview_storage_pool_facts
- oneview_storage_system
- oneview_storage_system_facts
- oneview_storage_volume
Expand Down
12 changes: 6 additions & 6 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@
|<sub>/rest/server-profiles/{id}/messages</sub> | GET | :white_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
|<sub>/rest/server-profiles/{id}/transformation</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Storage Pools** |
|<sub>/rest/storage-pools</sub> | GET | :white_check_mark: | :white_check_mark:
|<sub>/rest/storage-pools</sub> | POST | :heavy_minus_sign: | :heavy_minus_sign:
|<sub>/rest/storage-pools/reachable-storage-pools</sub> | GET | :white_check_mark: | :white_check_mark:
|<sub>/rest/storage-pools/{id}</sub> | GET | :white_check_mark: | :white_check_mark:
|<sub>/rest/storage-pools/{id}</sub> | PUT | :white_check_mark: | :white_check_mark:
|<sub>/rest/storage-pools/{id}</sub> | DELETE | :heavy_minus_sign: | :heavy_minus_sign:
|<sub>/rest/storage-pools</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-pools</sub> | POST | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
|<sub>/rest/storage-pools/reachable-storage-pools</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-pools/{id}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-pools/{id}</sub> | PUT | :white_check_mark: | :white_check_mark:| :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-pools/{id}</sub> | DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
| **Storage Systems** |
|<sub>/rest/storage-systems</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-systems</sub> | POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
61 changes: 27 additions & 34 deletions library/oneview_storage_pool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2017) Hewlett Packard Enterprise Development LP
# Copyright (2016-2020) 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 @@ -29,7 +29,7 @@
version_added: "2.3"
requirements:
- "python >= 2.7.9"
- "hpOneView >= 4.0.0"
- "hpOneView >= 5.0.0"
author: "Gustavo Hennig (@GustavoHennig)"
options:
state:
Expand Down Expand Up @@ -61,7 +61,6 @@
storageSystemUri: "/rest/storage-systems/TXQ1010307"
poolName: "FST_CPG2"
delegate_to: localhost
- name: Delete the Storage Pool (prior to API500)
oneview_storage_pool:
hostname: 172.16.101.48
Expand All @@ -72,26 +71,24 @@
data:
poolName: "FST_CPG2"
delegate_to: localhost
- name: Ensure the storage pool 'FST_CPG2' is managed by the appliance (API500 onwards)
oneview_storage_pool:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
state: present
data:
storageSystemUri: "/rest/storage-systems/TXQ1010307"
poolName: FST_CPG2
isManaged: True
delegate_to: localhost
- name: Ensure the storage pool 'FST_CPG2' is unmanaged (API500 onwards)
oneview_storage_pool:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
state: present
data:
storageSystemUri: "/rest/storage-systems/TXQ1010307"
Expand All @@ -108,10 +105,10 @@
'''


from ansible.module_utils.oneview import OneViewModuleBase, OneViewModuleValueError, OneViewModuleResourceNotFound, compare
from ansible.module_utils.oneview import OneViewModule, OneViewModuleValueError, OneViewModuleResourceNotFound, compare


class StoragePoolModule(OneViewModuleBase):
class StoragePoolModule(OneViewModule):
MSG_CREATED = 'Storage Pool added successfully.'
MSG_ALREADY_PRESENT = 'Storage Pool is already present.'
MSG_UPDATED = 'Storage Pool was updated.'
Expand All @@ -134,58 +131,54 @@ def __init__(self):
)

super(StoragePoolModule, self).__init__(additional_arg_spec=argument_spec)
self.resource_client = self.oneview_client.storage_pools
self.set_resource_object(self.oneview_client.storage_pools)

def execute_module(self):
resource = self.__get_by('name') if self.oneview_client.api_version >= 500 else self.__get_by('poolName')

if not self.data.get("poolName") and not self.data.get("name"):
raise OneViewModuleValueError(self.MSG_MANDATORY_FIELD_MISSING)

if self.data.get("poolName"):
self.current_resource = self.resource_client.get_by_name(self.data.get("poolName"))

if self.state == 'present':
return self.__present(self.data, resource)
return self.__present()
elif self.state == 'absent':
return self.__absent(self.data, resource)

def __get_by(self, attribute):
if not self.data.get(attribute):
raise OneViewModuleValueError(self.MSG_MANDATORY_FIELD_MISSING)
else:
return self.get_by_name(self.data[attribute])
return self.__absent()

def __present(self, data, resource):
def __present(self):
changed = False
msg = self.MSG_ALREADY_PRESENT

if not resource:
if not self.current_resource:
if self.oneview_client.api_version >= 500:
raise OneViewModuleResourceNotFound(self.MSG_RESOURCE_NOT_FOUND)
else:
resource = self.oneview_client.storage_pools.add(data)
self.current_resource = self.resource_client.add(self.data)
changed = True
msg = self.MSG_CREATED
else:
merged_data = resource.copy()
merged_data = self.current_resource.data.copy()
merged_data.update(self.data)

if compare(resource, merged_data):
if compare(self.current_resource.data, merged_data):
changed = False
msg = self.MSG_ALREADY_PRESENT
else:
resource = self.resource_client.update(merged_data)
self.current_resource.update(merged_data)
changed = True
msg = self.MSG_UPDATED

return dict(changed=changed,
msg=msg,
ansible_facts=dict(storage_pool=resource))
return dict(changed=changed, msg=msg, ansible_facts=dict(storage_pool=self.current_resource.data))

def __absent(self, data, resource):
def __absent(self):
if self.oneview_client.api_version >= 500:
if resource:
if self.current_resource:
raise OneViewModuleResourceNotFound(self.MSG_RESOURCE_FOUND)
else:
return dict(changed=False,
msg=self.MSG_ALREADY_ABSENT,
ansible_facts=dict(storage_pool=None))
return dict(changed=False, msg=self.MSG_ALREADY_ABSENT, ansible_facts=dict(storage_pool=None))
else:
return self.resource_absent(resource, 'remove')
return self.resource_absent('remove')


def main():
Expand Down
35 changes: 14 additions & 21 deletions library/oneview_storage_pool_facts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2017) Hewlett Packard Enterprise Development LP
# Copyright (2016-2020) 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 @@ -30,7 +30,7 @@
version_added: "2.3"
requirements:
- "python >= 2.7.9"
- "hpOneView >= 4.0.0"
- "hpOneView >= 5.0.0"
author: "Gustavo Hennig (@GustavoHennig)"
options:
name:
Expand All @@ -55,42 +55,36 @@
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
delegate_to: localhost
- debug: var=storage_pools
- name: Gather paginated, filtered and sorted facts about Storage Pools
oneview_storage_pool_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
params:
start: 0
count: 3
sort: 'name:descending'
filter: status='OK'
- debug: var=storage_pools
- name: Gather facts about a Storage Pool by name
oneview_storage_pool_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
name: "CPG_FC-AO"
delegate_to: localhost
- debug: var=storage_pools
- name: Gather facts about the reachable Storage Pools
oneview_storage_pool_facts:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 600
api_version: 1200
options:
- reachableStoragePools
params:
Expand All @@ -103,7 +97,6 @@
- /rest/storage-pools/5F9CA89B-C632-4F09-BC55-A8AA00DA5C4A
scope_uris: '/rest/scopes/754e0dce-3cbd-4188-8923-edf86f068bf7'
delegate_to: localhost
- debug: var=storage_pools_reachable_storage_pools
'''

Expand All @@ -112,34 +105,34 @@
description: Has all the OneView facts about the Storage Pools.
returned: Always, but can be null.
type: dict
storage_pools_reachable_storage_pools:
description: Has all the OneView facts about the Reachable Storage Pools.
returned: Always, but can be null.
type: dict
'''

from ansible.module_utils.oneview import OneViewModuleBase
from ansible.module_utils.oneview import OneViewModule


class StoragePoolFactsModule(OneViewModuleBase):
class StoragePoolFactsModule(OneViewModule):
def __init__(self):
argument_spec = dict(
name=dict(required=False, type='str'),
params=dict(required=False, type='dict'),
options=dict(required=False, type='list')
)
super(StoragePoolFactsModule, self).__init__(additional_arg_spec=argument_spec)
self.resource_client = self.oneview_client.storage_pools
self.set_resource_object(self.oneview_client.storage_pools)

def execute_module(self):
facts = {}
if self.module.params.get('name'):
storage_pool = self.oneview_client.storage_pools.get_by('name', self.module.params['name'])
pools = []
if self.module.params['name']:
pools = self.resource_client.get_by('name', self.module.params['name'])
else:
storage_pool = self.oneview_client.storage_pools.get_all(**self.facts_params)
pools = self.resource_client.get_all(**self.facts_params)

facts['storage_pools'] = storage_pool
facts['storage_pools'] = pools
self.__get_options(facts)
return dict(changed=False, ansible_facts=facts)

Expand Down
Loading

0 comments on commit f4f0706

Please sign in to comment.