示例#1
0
    def __delete_snapshot(self, resource):
        if 'snapshotParameters' not in self.data:
            raise HPOneViewResourceNotFound(self.MSG_NO_OPTIONS_PROVIDED)

        snapshot = self.__get_snapshot_by_name(resource, self.data)
        if not snapshot:
            raise HPOneViewResourceNotFound(self.MSG_SNAPSHOT_NOT_FOUND)
        else:
            self.oneview_client.volumes.delete_snapshot(snapshot)
            return dict(changed=True, msg=self.MSG_SNAPSHOT_DELETED)
示例#2
0
    def execute_module(self):
        changed, msg, ansible_facts = False, '', {}

        logical_enclosure = self.oneview_client.logical_enclosures.get_by_name(
            self.data['name'])

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

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

        return dict(changed=changed, msg=msg, ansible_facts=ansible_facts)
示例#3
0
    def __create_snapshot(self, resource):
        if 'snapshotParameters' not in self.data:
            raise HPOneViewResourceNotFound(self.MSG_NO_OPTIONS_PROVIDED)

        self.oneview_client.volumes.create_snapshot(
            resource['uri'], self.data['snapshotParameters'])
        return dict(changed=True, msg=self.MSG_SNAPSHOT_CREATED)
示例#4
0
    def __get_by_name(self, name):
        sas_interconnects = self.resource_client.get_by('name', name)

        if not sas_interconnects:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

        return sas_interconnects[0]
示例#5
0
    def execute_module(self):

        resource = self.__get_by_name(self.data)

        if self.state == 'present':
            changed, msg, resource = self.__present(resource, self.data)
        elif self.state == 'absent':
            return self.resource_absent(resource, 'remove')
        else:

            if not resource:
                raise HPOneViewResourceNotFound(self.MSG_ENCLOSURE_NOT_FOUND)

            if self.state == 'reconfigured':
                changed, msg, resource = self.__reconfigure(resource)
            elif self.state == 'refreshed':
                changed, msg, resource = self.__refresh(resource, self.data)
            elif self.state == 'support_data_collection_set':
                changed, msg, resource = self.__support_data_collection_set(resource, self.data)
            else:
                changed, msg, resource = self.__patch(resource, self.data)

        return dict(changed=changed,
                    msg=msg,
                    ansible_facts=dict(enclosure=resource))
示例#6
0
    def __get_current_property_value(self, state_name, state, resource, data):
        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(data.keys()) - set(["name"])
        if filter_:
            filter_ = filter_.pop()

        property_current_value = None

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

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

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

        else:
            property_current_value = resource[property_name]

        return property_current_value
示例#7
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 HPOneViewResourceNotFound(
             self.MSG_INTERCONNECT_TYPE_NOT_FOUND)
    def __present(self, data, resource):
        changed = False
        msg = self.MSG_ALREADY_PRESENT

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

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

        return dict(changed=changed,
                    msg=msg,
                    ansible_facts=dict(storage_pool=resource))
示例#9
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['uri']
         else:
             raise HPOneViewResourceNotFound(self.MSG_LOGICAL_INTERCONNECT_NOT_FOUND)
示例#10
0
 def __refresh(self, data, resource):
     if not resource:
         raise HPOneViewResourceNotFound(self.MSG_LOGICAL_SWITCH_NOT_FOUND)
     else:
         logical_switch = self.oneview_client.logical_switches.refresh(
             resource['uri'])
         return True, self.MSG_REFRESHED, dict(
             logical_switch=logical_switch)
示例#11
0
    def __resolve_log_interconnect_names(self, interconnectNames):
        uris = []
        for name in interconnectNames:
            li = self.get_by_name(name)
            if not li:
                raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)
            uris.append(li['uri'])

        return uris
示例#12
0
    def __get_appliance_by_name(self, name):
        appliance = self.oneview_client.os_deployment_servers.get_appliance_by_name(
            name)

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

        return appliance['uri']
示例#13
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['uri']
            else:
                raise HPOneViewResourceNotFound(self.PROFILE_NOT_FOUND)
示例#14
0
    def __update_resource_assignments(self, resource):
        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_RESOURCE_NOT_FOUND)

        scope = self.resource_client.update_resource_assignments(
            resource['uri'], self.data.get('resourceAssignments'))

        return dict(changed=True,
                    msg=self.MSG_RESOURCE_ASSIGNMENTS_UPDATED,
                    ansible_facts=dict(scope=scope))
    def __replace_group_name_by_uri(self, data):
        if 'logicalSwitch' in data and 'logicalSwitchGroupName' in data['logicalSwitch']:
            group_name = data['logicalSwitch']['logicalSwitchGroupName']
            logical_switch_group = self.oneview_client.logical_switch_groups.get_by('name', group_name)

            if logical_switch_group:
                data['logicalSwitch'].pop('logicalSwitchGroupName')
                data['logicalSwitch']['logicalSwitchGroupUri'] = logical_switch_group[0]['uri']
            else:
                raise HPOneViewResourceNotFound(self.MSG_LOGICAL_SWITCH_GROUP_NOT_FOUND)
 def __absent(self, data, resource):
     if self.oneview_client.api_version >= 500:
         if resource:
             raise HPOneViewResourceNotFound(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(resource, 'remove')
示例#17
0
    def execute_module(self):
        resource = self.get_by_name(self.module.params.get('name'))

        if self.state == 'absent':
            return self.resource_absent(resource)

        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)
        else:
            return self.__update_ports(resource)
示例#18
0
 def __get_network_uri(self, network_name_or_uri):
     if 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 HPOneViewResourceNotFound(
                 self.MSG_ETHERNET_NETWORK_NOT_FOUND + network_name_or_uri)
示例#19
0
    def __get_drive_enclosure(self, data):
        name = data.get('name')
        if not name:
            raise HPOneViewValueError(self.MSG_NAME_REQUIRED)
        else:
            result = self.oneview_client.drive_enclosures.get_by('name', name)

            if not result:
                raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

            return result[0]
    def execute_module(self):

        resource = self.__get_by_name(self.data)

        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

        changed, msg, ansible_facts = False, '', dict()
        uri = resource['uri']

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

        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 __default_bandwidth_reset(self, resource):

        if not resource:
            raise HPOneViewResourceNotFound(
                self.MSG_ETHERNET_NETWORK_NOT_FOUND)

        default_connection_template = self.oneview_client.connection_templates.get_default(
        )

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

        return changed, self.MSG_CONNECTION_TEMPLATE_RESET, dict(
            ethernet_network_connection_template=connection_template)
示例#22
0
    def __get_by_name(self, name):
        logical_interconnect = self.resource_client.get_by_name(name=name)
        if not logical_interconnect:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

        facts = dict(logical_interconnects=logical_interconnect)

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

        if options:
            options_facts = self.__get_options(logical_interconnect, options)
            facts.update(options_facts)

        return facts
示例#23
0
    def __reserved_vlan_range_updated(self):
        resource = self.get_by_name(self.data['name'])
        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)
        resource_vlan_range = resource.get('reservedVlanRange')
        merged_data = resource_vlan_range.copy()
        merged_data.update(self.data['reservedVlanRangeParameters'])

        if ResourceComparator.compare(resource_vlan_range, merged_data):
            return dict(changed=False,
                        msg=self.MSG_ALREADY_PRESENT,
                        ansible_facts=dict(fabric=resource))
        else:
            return self.__update_vlan_range(self.data, resource)
示例#24
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 HPOneViewResourceNotFound(
                self.MSG_NETWORK_NOT_FOUND.format(name))

        return fcoe_networks[0]['uri']
示例#25
0
    def execute_module(self):
        resource = self.__get_resource(self.data)

        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

        if self.state == 'present':
            exit_status = self.__update(self.data, resource)
        elif self.state == 'refresh_state_set':
            exit_status = self.__set_refresh_state(self.data, resource)
        elif self.state == 'endpoints_csv_file_created':
            exit_status = self.__create_endpoints_csv_file(resource)
        elif self.state == 'issues_report_created':
            exit_status = self.__create_issue_report(resource)

        return dict(exit_status)
    def __update(self, data, resource):
        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_LOGICAL_SWITCH_NOT_FOUND)
        else:
            data['logicalSwitch']['uri'] = resource['uri']

            if 'logicalSwitchGroupUri' not in data['logicalSwitch']:
                data['logicalSwitch']['logicalSwitchGroupUri'] = resource['logicalSwitchGroupUri']
            if 'switchCredentialConfiguration' not in data['logicalSwitch']:
                data['logicalSwitch']['switchCredentialConfiguration'] = resource['switchCredentialConfiguration']

            if 'newName' in data['logicalSwitch']:
                data['logicalSwitch']['name'] = data['logicalSwitch'].pop('newName')

            self.__replace_group_name_by_uri(data)
            updated_resource = self.oneview_client.logical_switches.update(data)
            return True, self.MSG_UPDATED, dict(logical_switch=updated_resource)
示例#27
0
    def __update_internal_networks(self, uri, data):
        self.__validate_options('internalNetworks', data)

        networks = []
        for network_uri_or_name in 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 HPOneViewResourceNotFound(msg)
                networks.append(ethernet_network['uri'])
            elif 'uri' in network_uri_or_name:
                networks.append(network_uri_or_name['uri'])

        li = self.oneview_client.logical_interconnects.update_internal_networks(uri, networks)

        return True, self.MSG_INTERNAL_NETWORKS_UPDATED, dict(logical_interconnect=li)
示例#28
0
    def execute_module(self):
        resource = self.get_by_name(self.data.get('name'))

        if self.state == 'present':
            return self.__present(resource)
        elif self.state == 'absent':
            return self.__absent(resource)
        else:
            if not resource:
                raise HPOneViewResourceNotFound(self.MSG_NOT_FOUND)

            if self.state == 'repaired':
                return self.__repair(resource)
            elif self.state == 'snapshot_created':
                return self.__create_snapshot(resource)
            elif self.state == 'snapshot_deleted':
                return self.__delete_snapshot(resource)
示例#29
0
    def __get_interconnect(self):
        interconnect_ip = self.module.params['ip']
        interconnect_name = self.module.params['name']

        if interconnect_ip:
            interconnects = self.oneview_client.interconnects.get_by(
                'interconnectIP', interconnect_ip) or []
        elif interconnect_name:
            interconnects = self.oneview_client.interconnects.get_by(
                'name', interconnect_name) or []
        else:
            raise HPOneViewValueError(self.MSG_MISSING_KEY)

        if not interconnects:
            raise HPOneViewResourceNotFound(self.MSG_INTERCONNECT_NOT_FOUND)

        return interconnects[0]
示例#30
0
    def __present(self, resource):
        changed, msg = False, self.MSG_ALREADY_PRESENT

        if not resource:
            raise HPOneViewResourceNotFound(self.MSG_RESOURCE_NOT_FOUND)

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

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

        if different:
            resource = self.resource_client.update(self.data, resource['uri'])
            changed = True
            msg = self.MSG_UPDATED

        return dict(changed=changed, msg=msg, ansible_facts=dict(server_hardware_type=resource))