def __delete_snapshot(self):
        if 'snapshotParameters' not in self.data:
            raise OneViewModuleResourceNotFound(self.MSG_NO_OPTIONS_PROVIDED)
        snapshot_parameters = self.data['snapshotParameters']

        snapshot = self.current_resource.get_snapshot_by_name(
            snapshot_parameters['name'])
        if not snapshot:
            raise OneViewModuleResourceNotFound(self.MSG_SNAPSHOT_NOT_FOUND)
        else:
            snapshot.delete()
            return dict(changed=True, msg=self.MSG_SNAPSHOT_DELETED)
    def execute_module(self):

        if self.state == 'present':
            return self.__present()
        elif self.state == 'multiple_servers_added':
            changed, msg, ansible_facts = self.__add_multiple_rack_mount_servers(
            )
        else:
            if not self.data.get('name'):
                raise OneViewModuleValueError(
                    self.MSG_MANDATORY_FIELD_MISSING.format("data.name"))

            if self.state == 'absent':
                return self.resource_absent(method='remove')
            else:
                if not self.current_resource:
                    raise OneViewModuleResourceNotFound(
                        self.MSG_SERVER_HARDWARE_NOT_FOUND)

                if self.state == 'power_state_set':
                    changed, msg, ansible_facts = self.__set_power_state()
                elif self.state == 'refresh_state_set':
                    changed, msg, ansible_facts = self.__set_refresh_state()
                elif self.state == 'ilo_firmware_version_updated':
                    changed, msg, ansible_facts = self.__update_mp_firmware_version(
                    )
                elif self.state == 'environmental_configuration_set':
                    changed, msg, ansible_facts = self.__set_environmental_configuration(
                    )
                else:
                    changed, msg, ansible_facts = self.__patch()

        return dict(changed=changed, msg=msg, ansible_facts=ansible_facts)
    def execute_module(self):
        if self.state == 'present':
            changed, msg, resource = self.__present()
        elif self.state == 'absent':
            return self.resource_absent('remove')
        else:
            if not self.current_resource:
                raise OneViewModuleResourceNotFound(
                    self.MSG_ENCLOSURE_NOT_FOUND)

            if self.state == 'reconfigured':
                changed, msg, resource = self.__reconfigure()
            elif self.state == 'refreshed':
                changed, msg, resource = self.__refresh()
            elif self.state == 'support_data_collection_set':
                changed, msg, resource = self.__support_data_collection_set()
            elif self.state == 'create_certificate_request':
                changed, msg, resource = self.__create_certificate_request()
            elif self.state == 'get_certificate_request':
                changed, msg, resource = self.__get_certificate_request()
            elif self.state == 'import_certificate_request':
                changed, msg, resource = self.__import_certificate_request()
            else:
                changed, msg, resource = self.__patch()

        return dict(changed=changed,
                    msg=msg,
                    ansible_facts=dict(enclosure=resource))
예제 #4
0
 def __get_interconnect_type_by_name(self, name):
     i_type = self.oneview_client.interconnect_types.get_by('name', name)
     if i_type:
         return i_type[0]
     else:
         raise OneViewModuleResourceNotFound(
             self.MSG_INTERCONNECT_TYPE_NOT_FOUND)
    def __get_current_property_value(self, state_name, state):
        property_name = state['path'].split('/')[1]
        sub_property_name = state['path'].split('/')[-1]

        if sub_property_name == property_name:
            sub_property_name = None

        if state_name == 'appliance_bays_powered_on':
            sub_property_name = 'poweredOn'

        filter_ = set(self.data.keys()) - set(["name"])
        if filter_:
            filter_ = filter_.pop()

        property_current_value = None

        if filter_:
            sub_resource = None
            if self.current_resource.data.get(property_name):
                sub_resource = next(
                    (item for item in self.current_resource.data[property_name]
                     if str(item[filter_]) == str(self.data[filter_])), None)

            if not sub_resource:
                # Resource doesn't have that property or subproperty
                raise OneViewModuleResourceNotFound(self.MSG_BAY_NOT_FOUND)

            property_current_value = sub_resource.get(sub_property_name)
            state['path'] = state['path'].format(**self.data)

        else:
            property_current_value = self.current_resource.data[property_name]

        return property_current_value
예제 #6
0
    def __present(self):
        changed = False
        msg = self.MSG_ALREADY_PRESENT

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

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

        return dict(
            changed=changed,
            msg=msg,
            ansible_facts=dict(storage_pool=self.current_resource.data))
예제 #7
0
    def __get_by_options(self, name):
        if not self.current_resource:
            raise OneViewModuleResourceNotFound(self.MSG_NOT_FOUND)

        facts = dict(logical_interconnects=self.current_resource.data)

        options = self.module.params["options"]

        if options:
            self.options = dict(
                qos_aggregated_configuration=self.current_resource.
                get_qos_aggregated_configuration,
                snmp_configuration=self.current_resource.
                get_snmp_configuration,
                igmp_settings=self.current_resource.get_igmp_settings,
                port_monitor=self.current_resource.get_port_monitor,
                internal_vlans=self.current_resource.get_internal_vlans,
                forwarding_information_base=self.current_resource.
                get_forwarding_information_base,
                firmware=self.current_resource.get_firmware,
                unassigned_uplink_ports=self.current_resource.
                get_unassigned_uplink_ports,
                unassigned_ports=self.current_resource.get_unassigned_ports,
                telemetry_configuration=self.current_resource.
                get_telemetry_configuration,
                ethernet_settings=self.current_resource.get_ethernet_settings,
            )

            options_facts = self.__get_options(options)
            facts.update(options_facts)

        return facts
예제 #8
0
    def __get_appliance_by_name(self, name):
        appliance = self.oneview_client.os_deployment_servers.get_appliance_by_name(
            name)

        if not appliance:
            raise OneViewModuleResourceNotFound(
                self.MSG_APPLIANCE_NOT_FOUND.format(name))

        return appliance['uri']
    def __download_archive(self):
        self.allbackups = self.resource_client.get_all_backups()
        if len(self.allbackups) == 0:
            raise OneViewModuleResourceNotFound(self.MSG_BACKUP_REQUIRED)

        self.current_resource = self.resource_client.get_backup(
            self.allbackups[0]['uri'])
        self.current_resource.download_archive(
            self.data['destinationFilePath'])
        return False, self.MSG_ARCHIVE_DOWNLOADED, {}
예제 #10
0
    def __replace_snmpv3_username_by_userid(self):
        if self.data and self.data.get('userName'):
            username = self.data.pop('userName', None)

            result = self.oneview_client.appliance_device_snmp_v3_users.get_by(
                'userName', username)
            if result:
                self.data['userId'] = result[0]['id']
            else:
                raise OneViewModuleResourceNotFound(self.MSG_USER_NOT_FOUND)
예제 #11
0
 def __absent(self):
     if self.oneview_client.api_version >= 500:
         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))
     else:
         return self.resource_absent('remove')
    def __extract_backup(self):
        self.allbackups = self.resource_client.get_all_backups()
        if len(self.allbackups) == 0:
            raise OneViewModuleResourceNotFound(self.MSG_BACKUP_REQUIRED)

        self.current_resource = self.resource_client.get_backup(
            self.allbackups[0]['uri'])
        resource = self.current_resource.extract_backup(self.data)
        return True, self.MSG_BACKUP_EXTRACTED, dict(
            artifact_bundle_deployment_group=resource)
예제 #13
0
    def __get_network_uri(self, name, network_type):
        if network_type == 'Ethernet':
            network_name = self.oneview_client.ethernet_networks.get_by_name(
                name)
        else:
            network_name = self.oneview_client.fc_networks.get_by_name(name)

        if network_name:
            return network_name.data['uri']
        else:
            raise OneViewModuleResourceNotFound(self.MSG_NETWORK_NOT_FOUND)
예제 #14
0
    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)
예제 #15
0
 def __replace_logical_interconnect_name_by_uri(self):
     if 'logicalInterconnectName' in self.data:
         name = self.data.pop('logicalInterconnectName')
         logical_interconnect = self.oneview_client.logical_interconnects.get_by_name(
             name)
         if logical_interconnect:
             self.data[
                 'logicalInterconnectUri'] = logical_interconnect.data[
                     'uri']
         else:
             raise OneViewModuleResourceNotFound(
                 self.MSG_LOGICAL_INTERCONNECT_NOT_FOUND)
예제 #16
0
    def __get_network_uri(self, network_name_or_uri):

        if network_name_or_uri and network_name_or_uri.startswith(
                '/rest/ethernet-networks'):
            return network_name_or_uri
        else:
            enet_network = self.__get_ethernet_network_by_name(
                network_name_or_uri)
            if enet_network:
                return enet_network['uri']
            else:
                raise OneViewModuleResourceNotFound(
                    self.MSG_ETHERNET_NETWORK_NOT_FOUND + network_name_or_uri)
예제 #17
0
    def __present(self):
        changed = False
        msg = ''

        if not self.current_resource:
            raise OneViewModuleResourceNotFound(self.MSG_NOT_FOUND)
        else:
            if 'newName' in self.data:
                self.data['name'] = self.data.pop('newName')

            changed, msg = self._update_resource()

        return changed, msg
예제 #18
0
    def __default_bandwidth_reset(self):

        if not self.current_resource:
            raise OneViewModuleResourceNotFound(
                self.MSG_ETHERNET_NETWORK_NOT_FOUND)

        default_connection_template = self.connection_templates.get_default()

        changed, connection_template_data = self.__update_connection_template(
            default_connection_template['bandwidth'])

        return changed, self.MSG_CONNECTION_TEMPLATE_RESET, dict(
            ethernet_network_connection_template=connection_template_data)
예제 #19
0
    def __find_interconnect(self):
        interconnect_ip = self.module.params['ip']
        if not interconnect_ip and not self.module.params["name"]:
            raise OneViewModuleValueError(self.MSG_MISSING_KEY)

        if not self.current_resource and interconnect_ip:
            interconnects = self.oneview_client.interconnects.get_by(
                'interconnectIP', interconnect_ip) or []
            if interconnects:
                self.current_resource = self.resource_client.get_by_uri(
                    interconnects[0]["uri"])

        if not self.current_resource:
            raise OneViewModuleResourceNotFound(
                self.MSG_INTERCONNECT_NOT_FOUND)
예제 #20
0
    def execute_module(self):

        if not self.current_resource:
            raise OneViewModuleResourceNotFound(self.MSG_NOT_FOUND)

        changed, msg, ansible_facts = False, '', dict()

        if self.state == 'compliant':
            changed, msg, ansible_facts = self.__compliance()
        elif self.state == 'ethernet_settings_updated':
            changed, msg, ansible_facts = self.__update_ethernet_settings()
        elif self.state == 'internal_networks_updated':
            changed, msg, ansible_facts = self.__update_internal_networks()
        elif self.state == 'settings_updated':
            changed, msg, ansible_facts = self.__update_settings()
        elif self.state == 'forwarding_information_base_generated':
            changed, msg, ansible_facts = self.__generate_forwarding_information_base(
            )
        elif self.state == 'qos_aggregated_configuration_updated':
            changed, msg, ansible_facts = self.__update_qos_configuration()
        elif self.state == 'snmp_configuration_updated':
            changed, msg, ansible_facts = self.__update_snmp_configuration()
        elif self.state == 'igmp_settings_updated':
            changed, msg, ansible_facts = self.__update_igmp_settings()
        elif self.state == 'port_monitor_updated':
            changed, msg, ansible_facts = self.__update_port_monitor()
        elif self.state == 'port_flap_settings_updated':
            changed, msg, ansible_facts = self.__update_port_flap_settings()
        elif self.state == 'configuration_updated':
            changed, msg, ansible_facts = self.__update_configuration()
        elif self.state == 'firmware_installed':
            changed, msg, ansible_facts = self.__install_firmware()
        elif self.state == 'bulk_inconsistency_validated':
            changed, msg, ansible_facts = self.__validate_bulk_inconsistency()
        elif self.state == 'telemetry_configuration_updated':
            changed, msg, ansible_facts = self.__update_telemetry_configuration(
            )
        elif self.state == 'scopes_updated':
            changed, msg, ansible_facts = self.__update_scopes()

        if ansible_facts:
            result = dict(changed=changed,
                          msg=msg,
                          ansible_facts=ansible_facts)
        else:
            result = dict(changed=changed, msg=msg)

        return result
예제 #21
0
    def __update_connection_template(self, bandwidth):
        if 'connectionTemplateUri' not in self.current_resource.data:
            raise OneViewModuleResourceNotFound(
                self.MSG_CONNECTION_TEMPLATE_NOT_FOUND)

        connection_template = self.connection_templates.get_by_uri(
            self.current_resource.data['connectionTemplateUri'])

        merged_data = connection_template.data.copy()
        merged_data.update({'bandwidth': bandwidth})

        if not compare(connection_template.data, merged_data):
            connection_template.update(merged_data)
            return True, connection_template.data
        else:
            return False, connection_template.data
예제 #22
0
    def __get_network_uri_by_name(self, name):
        ethernet_networks = self.oneview_client.ethernet_networks.get_by(
            'name', name)
        if ethernet_networks:
            return ethernet_networks[0]['uri']

        fc_networks = self.oneview_client.fc_networks.get_by('name', name)
        if fc_networks:
            return fc_networks[0]['uri']

        fcoe_networks = self.oneview_client.fcoe_networks.get_by('name', name)
        if not fcoe_networks:
            raise OneViewModuleResourceNotFound(
                self.MSG_NETWORK_NOT_FOUND.format(name))

        return fcoe_networks[0]['uri']
    def execute_module(self):
        if self.state == 'present':
            return self.__present()
        if self.state == 'managed':
            return self.__managed()
        elif self.state == 'absent':
            return self.__absent()
        else:
            if not self.current_resource:
                raise OneViewModuleResourceNotFound(self.MSG_NOT_FOUND)

            if self.state == 'repaired':
                return self.__repair()
            elif self.state == 'snapshot_created':
                return self.__create_snapshot()
            elif self.state == 'snapshot_deleted':
                return self.__delete_snapshot()
    def execute_module(self):
        resource = self.get_by_name(self.data['name'])

        if self.state == 'present':
            changed, msg, ansible_facts = self.__present(self.data, resource)
        elif self.state == 'absent':
            return self.resource_absent(resource)
        else:
            if not resource:
                raise OneViewModuleResourceNotFound(self.MSG_WAS_NOT_FOUND)

            if self.state == 'downloaded':
                changed, msg, ansible_facts = self.__download(self.data, resource)
            elif self.state == 'archive_downloaded':
                changed, msg, ansible_facts = self.__download_archive(self.data, resource)

        return dict(changed=changed,
                    msg=msg,
                    ansible_facts=ansible_facts)
예제 #25
0
    def __update_internal_networks(self):
        self.__validate_options('internalNetworks', self.data)

        networks = []
        for network_uri_or_name in self.data['internalNetworks']:
            if 'name' in network_uri_or_name:
                ethernet_network = self.__get_ethernet_network_by_name(
                    network_uri_or_name['name'])

                if not ethernet_network:
                    msg = self.MSG_ETH_NETWORK_NOT_FOUND + network_uri_or_name[
                        'name']
                    raise OneViewModuleResourceNotFound(msg)

                networks.append(ethernet_network['uri'])
            elif 'uri' in network_uri_or_name:
                networks.append(network_uri_or_name['uri'])

        li = self.current_resource.update_internal_networks(networks)

        return True, self.MSG_INTERNAL_NETWORKS_UPDATED, dict(
            logical_interconnect=li)
예제 #26
0
    def __present(self):
        changed, msg = False, self.MSG_ALREADY_PRESENT

        if not self.current_resource:
            raise OneViewModuleResourceNotFound(self.MSG_RESOURCE_NOT_FOUND)

        if "newName" in self.data:
            self.data["name"] = self.data.pop("newName")

        different = self.current_resource.data.get('name') != self.data.get(
            'name')
        different |= self.current_resource.data.get(
            'description') != self.data.get('description')

        if different:
            self.current_resource.update(self.data)
            changed = True
            msg = self.MSG_UPDATED

        return dict(changed=changed,
                    msg=msg,
                    ansible_facts=dict(
                        server_hardware_type=self.current_resource.data))
예제 #27
0
    def execute_module(self):
        changed, msg, ansible_facts = False, '', {}

        if self.state == 'present':
            changed, msg, ansible_facts = self.__present()
        elif self.state == 'absent':
            changed, msg, ansible_facts = self.__absent()
        else:
            if not self.current_resource:
                raise OneViewModuleResourceNotFound(self.MSG_REQUIRED)

            if self.state == 'firmware_updated':
                changed, msg, ansible_facts = self.__update_firmware()
            elif self.state == 'script_updated':
                changed, msg, ansible_facts = self.__update_script()
            elif self.state == 'dumped':
                changed, msg, ansible_facts = self.__support_dump()
            elif self.state == 'reconfigured':
                changed, msg, ansible_facts = self.__reconfigure()
            elif self.state == 'updated_from_group':
                changed, msg, ansible_facts = self.__update_from_group()

        return dict(changed=changed, msg=msg, ansible_facts=ansible_facts)
    def __create_snapshot(self):
        if 'snapshotParameters' not in self.data:
            raise OneViewModuleResourceNotFound(self.MSG_NO_OPTIONS_PROVIDED)

        self.current_resource.create_snapshot(self.data["snapshotParameters"])
        return dict(changed=True, msg=self.MSG_SNAPSHOT_CREATED)
 def __download(self):
     if not self.current_resource:
         raise OneViewModuleResourceNotFound(self.MSG_REQUIRED)
     self.current_resource.download(self.data['destinationFilePath'])
     return False, self.MSG_DOWNLOADED, {}
 def __extract(self):
     if not self.current_resource:
         raise OneViewModuleResourceNotFound(self.MSG_REQUIRED)
     resource = self.current_resource.extract()
     return True, self.MSG_EXTRACTED, dict(artifact_bundle=resource)