-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from HewlettPackard/tests
Changes for VolumeTemplates, VolumeAttachments
- Loading branch information
Showing
42 changed files
with
2,348 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ jobs: | |
matrix: | ||
python_version: | ||
- 3.6 | ||
- 3.7 | ||
ansible: | ||
- stable-2.10 | ||
- devel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.