Skip to content

Commit

Permalink
Merge 30ff84f into 2e595d5
Browse files Browse the repository at this point in the history
  • Loading branch information
sijeesh committed May 28, 2019
2 parents 2e595d5 + 30ff84f commit bc29707
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 15 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Ansible Modules for HPE OneView Change Log

## v5.3.1

This release is to support resource name instead of resource URIs in server profile and profile template.

#### Major changes
1. Updated ReplaceServerProfileNamebyUris class to support the schema changes in latest API version.
2. Added an end-to-end example playbook for server profile template with the below resources
- enclosure group
- server hardware type
- server profile name
- ethernet network
- fc network
- volume storage system
- os deployment plan
- storage pool
- volme template
- firmware baseline

#### Example playbook added
- oneview_server_profile_template_with_resource_name

## v5.3.0

This release extends the planned support of the modules to OneView REST API version 800 (OneView v4.1).
Expand Down
184 changes: 184 additions & 0 deletions examples/oneview_server_profile_template_with_resource_name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
###
# Copyright (2016-2019) 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.
###
---
- hosts: localhost
vars:
config: "{{ playbook_dir }}/oneview_config.json"
server_profile_template_name: "SPT TEST - WITH RESOURCE NAMES"
server_hardware_type_name: "SY 480 Gen9 2"
enclosure_group_name: "SYN03_EC"
server_profile_name: "RHEl76"
deployment_network_name: "VLAN512"
fc_network_1: "FC01"
fc_network_2: "FC02"
volume_storage_system: "ECOSTORE01"
os_deployment_plan_name: "RHEL"
storage_pool_name: "SSD_r5"
volume_template_name: "SVT-1"
firmware_baseline_name: "HPE Synergy Custom SPP 2018110 2019 02 15"
tasks:
- name: Create a server profile template
oneview_server_profile_template:
config: "{{ config }}"
state: present
data:
name: "{{ server_profile_template_name }}"
serverHardwareTypeName: "{{ server_hardware_type_name }}"
enclosureGroupName: "{{ enclosure_group_name }}"
initialScopeNames:
- Renamed
- test
bios:
manageBios: false
boot:
manageBoot: true
order:
- "HardDisk"
bootMode:
manageMode: true
mode: "UEFIOptimized"
pxeBootPolicy: "Auto"
connectionSettings:
manageConnections: true
connections:
- id: 1
portId: "Auto"
name: "Deployment Network A"
functionType: "Ethernet"
networkName: "{{ deployment_network_name }}"
requestedMbps: 2500
requestedVFs: "Auto"
boot:
priority: "Primary"
bootVolumeSource: "UserDefined"
ethernetBootType: "iSCSI"
iscsi:
initiatorNameSource: "ProfileInitiatorName"
chapLevel: None
bootVlanId: null
ipv4:
ipAddressSource: "DHCP"
- id: 2
portId: "Auto"
name: "Deployment Network B"
functionType: "Ethernet"
networkName: "{{ deployment_network_name }}"
requestedMbps: 2500
requestedVFs: "Auto"
boot:
priority: "Secondary"
bootVolumeSource: "UserDefined"
ethernetBootType: "iSCSI"
iscsi:
initiatorNameSource: "ProfileInitiatorName"
chapLevel: None
bootVlanId: null
ipv4:
ipAddressSource: "DHCP"
- id: 3
portId: "Auto"
name: "FC Network A"
functionType: "FibreChannel"
networkName: "{{ fc_network_1 }}"
requestedMbps: 2500
- id: 4
portId: "Auto"
name: "FC Network B"
functionType: "FibreChannel"
networkName: "{{ fc_network_2 }}"
requestedMbps: 2500
sanStorage:
hostOSType: "RHE Linux (5.x, 6.x, 7.x)"
manageSanStorage: true
volumeAttachments:
- id: 1
lunType: "Manual"
lun: "10"
volumeStorageSystemName: "{{ volume_storage_system }}"
volume:
properties:
name: "new volume"
storagePoolName: "{{ storage_pool_name }}"
provisioningType: "Thin"
size: 268435456
isShareable: false
isPermanent: true
templateName: "{{ volume_template_name }}"
storagePaths:
- connectionId: 3
isEnabled: true
targetSelector: "Auto"
- connectionId: 4
isEnabled: true
targetSelector: "Auto"
firmware:
manageFirmware: true
comlianceControl: "checked"
firmwareBaselineName: "{{ firmware_baseline_name }}"
firmwareInstallType: "FirmwareAndOSDrivers"
forceInstallFirmware: false
osDeploymentSettings:
osDeploymentPlanName: "{{os_deployment_plan_name}}"
osCustomAttributes:
- name: "LogicalVolumeName"
value: "new_vol"
- name: "SSH"
value: "Enabled"
- name: "NewUser"
value: "demo"
- name: "FirstPartitionSize"
value: 10
- name: "LogicalVolumeGroupName"
value: "new_vol_group"
- name: "TotalMgmtNICs"
value: 1
- name: "SecondPartitionSize"
value: 10
- name: "DiskName"
value: "/dev/sda"
- name: "DomainName"
value: "eco.core.local"
- name: "LogicalVolumeSize"
value: 15
- name: "NewRootPassword"
value: "root"
- name: "NewUserPassword"
value: "demo"
- name: "HostName"
value: "demo"
- name: "ManagementNIC1.vlanid"
value: 0
- name: "ManagementNIC1.dhcp"
value: true
- name: "ManagementNIC1.connectionid"
value: 3
- name: "ManagementNIC1.ipv4disable"
value: false
- name: "ManagementNIC1.constraint"
value: "dhcp"
params:
force: true
delegate_to: localhost
register: result
- debug: msg= "{{ result.msg }}"

- name: Gather facts about the Server Profile Template by name
oneview_server_profile_template_facts:
config: "{{ config }}"
name: "{{ server_profile_template_name }}"
delegate_to: localhost

- debug: var=server_profile_templates
47 changes: 41 additions & 6 deletions library/module_utils/oneview.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,13 +978,15 @@ def _merge_dict(self, merged_data, resource, data, key):


class ServerProfileReplaceNamesByUris(object):
SCOPE_NOT_FOUND = 'Scope not found: '
SERVER_PROFILE_OS_DEPLOYMENT_NOT_FOUND = 'OS Deployment Plan not found: '
SERVER_PROFILE_ENCLOSURE_GROUP_NOT_FOUND = 'Enclosure Group not found: '
SERVER_PROFILE_NETWORK_NOT_FOUND = 'Network not found: '
SERVER_HARDWARE_TYPE_NOT_FOUND = 'Server Hardware Type not found: '
VOLUME_NOT_FOUND = 'Volume not found: '
STORAGE_POOL_NOT_FOUND = 'Storage Pool not found: '
STORAGE_SYSTEM_NOT_FOUND = 'Storage System not found: '
STORAGE_VOLUME_TEMPLATE_NOT_FOUND = 'Storage volume template not found: '
INTERCONNECT_NOT_FOUND = 'Interconnect not found: '
FIRMWARE_DRIVER_NOT_FOUND = 'Firmware Driver not found: '
SAS_LOGICAL_JBOD_NOT_FOUND = 'SAS logical JBOD not found: '
Expand All @@ -1001,15 +1003,33 @@ def replace(self, oneview_client, data):
self._replace_interconnect_name_by_uri(data)
self._replace_firmware_baseline_name_by_uri(data)
self._replace_sas_logical_jbod_name_by_uri(data)
self._replace_initial_scope_name_by_uri(data)

def _replace_name_by_uri(self, data, attr_name, message, resource_client):
attr_uri = attr_name.replace("Name", "Uri")
def _get_resource_uri_from_name(self, name, message, resource_client):
resource_by_name = resource_client.get_by('name', name)
if resource_by_name:
return resource_by_name[0]['uri']
else:
raise OneViewModuleResourceNotFound(message + name)

def _replace_name_by_uri(self, data, attr_name, message, resource_client,
replace_name_with='Uri'):
attr_uri = attr_name.replace("Name", replace_name_with)
if attr_name in data:
name = data.pop(attr_name)
resource_by_name = resource_client.get_by('name', name)
if not resource_by_name:
raise OneViewModuleResourceNotFound(message + name)
data[attr_uri] = resource_by_name[0]['uri']
uri = self._get_resource_uri_from_name(name, message, resource_client)
data[attr_uri] = uri

def _replace_initial_scope_name_by_uri(self, data):
if data.get("initialScopeNames"):
scope_uris = []
resource_client = self.oneview_client.scopes
for name in data.pop("initialScopeNames", []):
scope = resource_client.get_by_name(name)
if not scope:
raise OneViewModuleResourceNotFound(self.SCOPE_NOT_FOUND + name)
scope_uris.append(scope["uri"])
data["initialScopeUris"] = scope_uris

def _replace_os_deployment_name_by_uri(self, data):
if SPKeys.OS_DEPLOYMENT in data and data[SPKeys.OS_DEPLOYMENT]:
Expand Down Expand Up @@ -1040,6 +1060,7 @@ def _replace_server_hardware_type_name_by_uri(self, data):

def _replace_volume_attachment_names_by_uri(self, data):
volume_attachments = (data.get('sanStorage') or {}).get('volumeAttachments') or []

if len(volume_attachments) > 0:
for volume in volume_attachments:
if not volume.get('volumeUri') and volume.get('volumeName'):
Expand All @@ -1052,11 +1073,25 @@ def _replace_volume_attachment_names_by_uri(self, data):
"that the volume does not exist, so it will be created along with the server "
"profile. Be warned that it will always trigger a new creation, so it will not "
" be idempotent.")

self._replace_name_by_uri(volume, 'volumeStoragePoolName', self.STORAGE_POOL_NOT_FOUND,
self.oneview_client.storage_pools)
self._replace_name_by_uri(volume, 'volumeStorageSystemName', self.STORAGE_SYSTEM_NOT_FOUND,
self.oneview_client.storage_systems)

# Support for API version 600 schema changes
if volume.get('volume'):
self._replace_name_by_uri(volume['volume'], 'templateName',
self.STORAGE_VOLUME_TEMPLATE_NOT_FOUND,
self.oneview_client.storage_volume_templates)

if volume['volume'].get('properties'):
self._replace_name_by_uri(volume['volume']['properties'],
'storagePoolName',
self.STORAGE_POOL_NOT_FOUND,
self.oneview_client.storage_pools,
replace_name_with='')

def _replace_enclosure_name_by_uri(self, data):
self._replace_name_by_uri(data, 'enclosureName', self.ENCLOSURE_NOT_FOUND, self.oneview_client.enclosures)

Expand Down
4 changes: 2 additions & 2 deletions library/oneview_server_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or
volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the
volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri,
firmwareBaselineName or firmwareBaselineUri (on the firmware), and sasLogicalJBODName or sasLogicalJBODUri (on
the sasLogicalJBODs list)"
firmwareBaselineName or firmwareBaselineUri (on the firmware), sasLogicalJBODName or sasLogicalJBODUri (on
the sasLogicalJBODs list) and initialScopeNames or initialScopeUris"
- "If you define the volumeUri as null in the volumeAttachments list, it will be understood that the volume
does not exist, so it will be created along with the server profile. Be warned that every time this option
is executed it will always be understood that a new volume needs to be created, so this will not be idempotent.
Expand Down
7 changes: 2 additions & 5 deletions library/oneview_server_profile_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or
volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the
volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri,
firmwareBaselineName or firmwareBaselineUri (on the firmware), and sasLogicalJBODName or sasLogicalJBODUri (on
the sasLogicalJBODs list)"
firmwareBaselineName or firmwareBaselineUri (on the firmware), sasLogicalJBODName or sasLogicalJBODUri (on
the sasLogicalJBODs list) and initialScopeNames or initialScopeUris"
- "If you define the volumeUri as null in the volumeAttachments list, it will be understood that the volume
does not exist, so it will be created along with the server profile. Be warned that every time this option
is executed it will always be understood that a new volume needs to be created, so this will not be idempotent.
Expand Down Expand Up @@ -139,15 +139,13 @@ class ServerProfileTemplateModule(OneViewModule):
)

def __init__(self):

super(ServerProfileTemplateModule, self).__init__(additional_arg_spec=self.argument_spec,
validate_etag_support=True)

self.set_resource_object(self.oneview_client.server_profile_templates)
self.server_profiles = self.oneview_client.server_profiles

def execute_module(self):

params = self.module.params.get("params")
self.params = params if params else {}

Expand All @@ -159,7 +157,6 @@ def execute_module(self):
return result

def __present(self):

ServerProfileReplaceNamesByUris().replace(self.oneview_client, self.data)

data = self.__spt_from_sp() or self.data
Expand Down
4 changes: 2 additions & 2 deletions oneview-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -9460,7 +9460,7 @@ Manage OneView Server Profile resources

#### Notes

- For the following data, you can provide either a name or a URI: enclosureGroupName or enclosureGroupUri, osDeploymentPlanName or osDeploymentPlanUri (on the osDeploymentSettings), networkName or networkUri (on the connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri, firmwareBaselineName or firmwareBaselineUri (on the firmware), and sasLogicalJBODName or sasLogicalJBODUri (on the sasLogicalJBODs list)
- For the following data, you can provide either a name or a URI: enclosureGroupName or enclosureGroupUri, osDeploymentPlanName or osDeploymentPlanUri (on the osDeploymentSettings), networkName or networkUri (on the connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri, firmwareBaselineName or firmwareBaselineUri (on the firmware), sasLogicalJBODName or sasLogicalJBODUri (on the sasLogicalJBODs list) and initialScopeNames or initialScopeUris

- If you define the volumeUri as null in the volumeAttachments list, it will be understood that the volume does not exist, so it will be created along with the server profile. Be warned that every time this option is executed it will always be understood that a new volume needs to be created, so this will not be idempotent. It is strongly recommended to ensure volumes with Ansible and then assign them to the desired server profile. does not exists, so it will be created along with the server profile

Expand Down Expand Up @@ -9726,7 +9726,7 @@ Manage OneView Server Profile Template resources.

#### Notes

- For the following data, you can provide either a name or a URI: enclosureGroupName or enclosureGroupUri, osDeploymentPlanName or osDeploymentPlanUri (on the osDeploymentSettings), networkName or networkUri (on the connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri, firmwareBaselineName or firmwareBaselineUri (on the firmware), and sasLogicalJBODName or sasLogicalJBODUri (on the sasLogicalJBODs list)
- For the following data, you can provide either a name or a URI: enclosureGroupName or enclosureGroupUri, osDeploymentPlanName or osDeploymentPlanUri (on the osDeploymentSettings), networkName or networkUri (on the connections list), volumeName or volumeUri (on the volumeAttachments list), volumeStoragePoolName or volumeStoragePoolUri (on the volumeAttachments list), volumeStorageSystemName or volumeStorageSystemUri (on the volumeAttachments list), serverHardwareTypeName or serverHardwareTypeUri, enclosureName or enclosureUri, firmwareBaselineName or firmwareBaselineUri (on the firmware), sasLogicalJBODName or sasLogicalJBODUri (on the sasLogicalJBODs list) and initialScopeNames or initialScopeUris

- If you define the volumeUri as null in the volumeAttachments list, it will be understood that the volume does not exist, so it will be created along with the server profile. Be warned that every time this option is executed it will always be understood that a new volume needs to be created, so this will not be idempotent. It is strongly recommended to ensure volumes with Ansible and then assign them to the desired server profile template.

Expand Down

0 comments on commit bc29707

Please sign in to comment.