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

Changes for VolumeTemplates, VolumeAttachments #11

Merged
merged 4 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/.ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
matrix:
python_version:
- 3.6
- 3.7
ansible:
- stable-2.10
- devel
Expand Down
132 changes: 132 additions & 0 deletions plugins/modules/oneview_storage_volume_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

ANSIBLE_METADATA = {'status': ['stableinterface'],
'supported_by': 'community',
'metadata_version': '1.1'}

DOCUMENTATION = '''
---
module: oneview_storage_volume_attachment
short_description: Provides an interface to remove extra presentations from a specified server profile.
description:
- "Provides an interface to remove extra presentations from a specified server profile."
version_added: "2.3.0"
requirements:
- "python >= 2.7.9"
- "hpeOneView >= 5.0.0"
author: "Camila Balestrin (@balestrinc)"
options:
state:
description:
- Indicates the desired state for the Storage Volume Attachment
C(extra_presentations_removed) will remove extra presentations from a specified server profile.
required: true
type: str
server_profile:
description:
- Server Profile name or Server Profile URI
required: true
type: str
extends_documentation_fragment:
- hpe.oneview.oneview
- hpe.oneview.oneview.params
'''

EXAMPLES = '''
- name: Removes extra presentations from a specified server profile URI
oneview_storage_volume_attachment:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: extra_presentations_removed
server_profile: "/rest/server-profiles/e6516410-c873-4644-ab93-d26dba6ccf0d"
delegate_to: localhost

- debug: var=server_profile


- name: Removes extra presentations from a specified server profile name
oneview_storage_volume_attachment:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: extra_presentations_removed
server_profile: "SV-1001"
delegate_to: localhost

- debug: var=server_profile
'''

RETURN = '''
server_profile:
description: Has all the OneView facts about the repaired Server Profile.
returned: Always.
type: dict
'''

from ansible_collections.hpe.oneview.plugins.module_utils.oneview import OneViewModule, OneViewModuleResourceNotFound


class StorageVolumeAttachmentModule(OneViewModule):
PROFILE_NOT_FOUND = "Server Profile not found."
PRESENTATIONS_REMOVED = "Extra presentations removed"

def __init__(self):
argument_spec = {
"state": {"required": True, "type": 'str'},
"server_profile": {"required": True, "type": 'str'},
}

super().__init__(additional_arg_spec=argument_spec)
self.set_resource_object(self.oneview_client.storage_volume_attachments)

def execute_module(self):

data = {
"type": "ExtraUnmanagedStorageVolumes",
"resourceUri": self.__get_server_profile_uri(self.module.params['server_profile'])
}

attachment = self.resource_client.remove_extra_presentations(data)
return dict(changed=True, msg=self.PRESENTATIONS_REMOVED,
ansible_facts=dict(server_profile=attachment))

def __get_server_profile_uri(self, server_profile):
if "/" in server_profile:
return server_profile
else:
profile = self.oneview_client.server_profiles.get_by_name(server_profile)

if profile:
return profile.data['uri']
else:
raise OneViewModuleResourceNotFound(self.PROFILE_NOT_FOUND)


def main():
StorageVolumeAttachmentModule().run()


if __name__ == '__main__':
main()
Loading