class ApplianceDeviceSNMPv3TrapDestinations(object):
    """
    ApplianceDeviceSNMPv3TrapDestinations API client.
    The appliance has the ability to forward events received from monitored or managed server hardware to the specified destinations as SNMPv3 traps.
    """
    URI = '/rest/appliance/snmpv3-trap-forwarding/destinations'

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)

    def create(self, resource, timeout=-1):
        """
        Adds the specified trap forwarding destination.
        The trap destination associated with the specified id will be created if trap destination with that id does not exists.
        The id can only be an integer greater than 0.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Created resource.

        """
        return self._client.create(resource, timeout=timeout)

    def get(self, id_or_uri):
        """
        Returns the SNMPv3 trap forwarding destination with the specified ID, if it exists.

        Args:
            id_or_uri: ID or URI of SNMPv3 trap destination.

        Returns:
            dict: Appliance SNMPv3 trap destination.
        """
        return self._client.get(id_or_uri)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Retrieves all SNMPv3 trap forwarding destinations.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of SNMPv3 Trap Destionations.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get_by(self, field, value):
        """
        Gets all SNMPv3 trap forwarding destinations that match the filter.
        The search is case-insensitive.

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            list: A list of SNMPv3 Trap Destionations.
        """
        return self._client.get_by(field, value)

    def delete(self, id_or_uri, timeout=-1):
        """
        Deletes SNMPv3 trap forwarding destination based on {Id} only if no User is assigned to it.

        Args:
            id_or_uri: dict object to delete
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(id_or_uri, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates SNMPv3 trap forwarding destination based on Id.

        Args:
            resource: dict object with changes.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Updated appliance SNMPv3 trap destinations.
        """
        return self._client.update(resource, timeout=timeout)
コード例 #2
0
ファイル: events.py プロジェクト: prakashmirji/oneview-python
class Events(object):
    URI = '/rest/events'

    DEFAULT_VALUES = {
        '200': {"type": "EventResourceV3"},
        '300': {"type": "EventResourceV3"}
    }

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)

    def get(self, id_or_uri):
        """
        Retrieve an event by its URI or ID.

        Args:
            id_or_uri: event ID or URI.

        Returns:
            dict: The event.

        """

        event = self._client.get(id_or_uri)
        return event

    def get_all(self, start=0, count=-1, filter='', query='', sort='', view=''):
        """
        Gets all the events based upon filters provided.

        Args:
            start:
                 The first item to return, using 0-based indexing. If not specified, the default is 0 - start with the
                 first available item.
            count:
                The number of resources to return. A count of -1 requests all items. The actual number of items in
                the response may differ from the requested count if the sum of start and count exceed the total number
                of items.
            filter (list or str):
                 A general filter/query string to narrow the list of items returned. The default is no filter; all
                 resources are returned.
            query:
                 A general query string to narrow the list of resources returned. The default is no query (all
                 resources are returned).
            sort:
                The sort order of the returned data set. By default, the sort order is based on create time, with the
                oldest entry first.
            view:
                 Returns a specific subset of the attributes of the resource or collection, by specifying the name of a
                 predefined view. The default view is expand (show all attributes of the resource and all elements of
                 collections of resources).

        Returns:
            list: A list of events.
        """
        return self._client.get_all(start=start, count=count, filter=filter, query=query, sort=sort, view=view)

    def get_by(self, field, value):
        """
        Gets all events that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: List of events.

        """
        return self._client.get_by(field, value)

    def create(self, resource, timeout=-1):
        """
        Creates an Event.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Created resource.

        """
        return self._client.create(resource, timeout=timeout, default_values=self.DEFAULT_VALUES)
コード例 #3
0
class InterconnectLinkTopologies(object):
    """
    Interconnect Link Topologies API client.

    Note:
        This resource is only available on HPE Synergy.

    """

    URI = '/rest/interconnect-link-topologies'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of all the interconnect link topologies based on the specified parameters.

        Filters can be used in the URL to control the number of interconnect link topologies that are returned.
        With no filters specified, the API returns all interconnect link toplogies.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of interconnect link topologies.

        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets an interconnect link topology by ID or by URI.

        Args:
            id_or_uri: Can be either the interconnect type id or the interconnect type uri.

        Returns:
            dict: The interconnect link topology.
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all interconnect link topologies that match the filter.
        The search is case-insensitive

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of interconnect link topologies.
        """
        return self._client.get_by(field, value)
コード例 #4
0
class OsVolumes(object):
    URI = '/rest/os-volumes'

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)
        self.__default_values = {
            'type': 'OeVolume',
        }

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a list of the OS Volume based on optional sorting and filtering, and constrained by start and count
        parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of OS Volume.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Retrieves the overview details of the selected OS Volume as per the selected attributes.

        Args:
            id_or_uri: ID or URI of the OS Volume.

        Returns:
            dict: The OS Volume.
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all OS Volume that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of OS Volume.
        """
        return self._client.get_by(field, value)

    def get_by_name(self, name):
        """
        Gets an OS Volume by name.

        Args:
            name: Name of the OS Volume.

        Returns:
            dict: The OS Volume.
        """
        return self._client.get_by_name(name)

    def download_archive(self, name, file_path):
        """
        Download archived logs of the OS Volume.

        Args:
            name: Name of the OS Volume.
            file_path (str): Destination file path.

        Returns:
            bool: Indicates if the resource was successfully downloaded.
        """
        uri = self.URI + "/archive/" + name
        return self._client.download(uri, file_path)

    def get_storage(self, id_or_uri):
        """
        Get storage details of an OS Volume.

        Args:
            id_or_uri: ID or URI of the OS Volume.

        Returns:
            dict: Storage details
        """
        uri = self.URI + "/{}/storage".format(extract_id_from_uri(id_or_uri))
        return self._client.get(uri)
コード例 #5
0
class DeploymentGroups(object):

    URI = '/rest/deployment-groups'

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a list of the Deployment Group based on optional sorting and filtering, and constrained by start and count
        parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of Deployment Group.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Retrieves the overview details of the selected Deployment Group as per the selected attributes.

        Args:
            id_or_uri: ID or URI of the Deployment Group.

        Returns:
            dict: The Deployment Group.
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all Deployment Groups that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of Deployment Group.
        """
        return self._client.get_by(field, value)

    def get_by_name(self, name):
        """
        Gets a Deployment Group by name.

        Args:
            name: Name of the Deployment Group.

        Returns:
            dict: The Deployment Group.
        """
        return self._client.get_by_name(name)
コード例 #6
0
class ApplianceDeviceSNMPv3Users(object):
    """
    ApplianceDeviceSNMPv3Users API client [Available only since API 600].

    As part of SNMPv3 trap forwarding support, the appliance provides APIs for creating User-based Security Model (USM) and forwarding destinations.
    The following protocols are supported while defining USM.

    Authentication protocols: MD5 / SHA1 / SHA256 / SHA384 / SHA512
    Privacy protocols: AES / DES
    The security levels supported while defining USM are None, Authentication only and both Authentication and Privacy.

    """
    URI = '/rest/appliance/snmpv3-trap-forwarding/users'

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)

    def create(self, resource, timeout=-1):
        """
        Creates a new SNMPv3 user.
        This user will be used for sending the SNMPv3 trap to the associated destinations.
        One user can be assigned to multiple destinations.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Created resource.

        """
        return self._client.create(resource, timeout=timeout)

    def get(self, id_or_uri):
        """
        Returns the SNMPv3 user with the specified ID, if it exists.

        Args:
            id_or_uri: ID or URI of SNMPv3 user.

        Returns:
            dict: Appliance SNMPv3 user.
        """
        return self._client.get(id_or_uri)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Lists all SNMPv3 Users.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of SNMPv3 Users.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get_by(self, field, value):
        """
        Gets all SNMPv3 users that match the filter.
        The search is case-insensitive.

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            list: A list of SNMPv3 Users.
        """
        return self._client.get_by(field, value)

    def delete_all(self, filter=None, timeout=-1):
        """
        Delete an SNMPv3 User based on User name specified in filter. The user will be deleted only if it has no associated destinations.

        Args:
            username: ID or URI of SNMPv3 user.
            filter: A general filter/query string to narrow the list of items returned.
                    The default is no filter - all resources are returned.

        Returns:
            bool: Indicates if the resource was successfully deleted.
        """
        return self._client.delete_all(filter=filter, timeout=timeout)

    def delete(self, id_or_uri, timeout=-1):
        """
        Delete an SNMPv3 User based on User Id specified in {Id}.
        The user will be deleted only if it has no associated destinations.

        Args:
            id_or_uri: dict object to delete
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(id_or_uri, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates SNMPv3 User based on User Id as specified in {Id}

        Args:
            resource: dict object with changes.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Updated appliance SNMPv3 user.
        """
        return self._client.update(resource, timeout=timeout)
コード例 #7
0
class SasLogicalJbodAttachments(object):
    """
    SAS Logical JBOD Attachments API client.

    Note:
        This resource is only available on HPE Synergy

    """
    URI = '/rest/sas-logical-jbod-attachments'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of SAS Logical JBOD Attachments. The collection is based on optional
        sorting and filtering and is constrained by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of SAS Logical JBOD Attachments.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets the SAS Logical JBOD Attachment with the specified ID or URI.

        Args:
            id_or_uri: ID or URI of the SAS Logical JBOD Attachment.

        Returns:
            dict: SAS Logical JBOD Attachment
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all SAS Logical JBOD Attachments that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of SAS Logical JBOD Attachments.
        """
        return self._client.get_by(field, value)
コード例 #8
0
ファイル: alerts.py プロジェクト: prakashmirji/oneview-python
class Alerts(object):
    URI = '/rest/alerts'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get(self, id_or_uri):
        """
        Retrieve an alert by its URI or ID.

        Args:
            id_or_uri: alert ID or URI.

        Returns:
            dict: The alert.

        """

        alert = self._client.get(id_or_uri)
        return alert

    def get_all(self,
                start=0,
                count=-1,
                filter='',
                query='',
                sort='',
                view=''):
        """
        Gets all the alerts based upon filters provided.

        Args:
            start:
                 The first item to return, using 0-based indexing. If not specified, the default is 0 - start with the
                 first available item.
            count:
                The number of resources to return. A count of -1 requests all items. The actual number of items in
                the response may differ from the requested count if the sum of start and count exceed the total number
                of items.
            filter (list or str):
                 A general filter/query string to narrow the list of items returned. The default is no filter; all
                 resources are returned.
            query:
                 A general query string to narrow the list of resources returned. The default is no query (all
                 resources are returned).
            sort:
                The sort order of the returned data set. By default, the sort order is based on create time, with the
                oldest entry first.
            view:
                 Returns a specific subset of the attributes of the resource or collection, by specifying the name of a
                 predefined view. The default view is expand (show all attributes of the resource and all elements of
                 collections of resources).

        Returns:
            list: A list of alerts.
        """
        return self._client.get_all(start=start,
                                    count=count,
                                    filter=filter,
                                    query=query,
                                    sort=sort,
                                    view=view)

    def get_by(self, field, value):
        """
        Gets all alerts that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: List of alerts.

        """
        return self._client.get_by(field, value)

    def delete(self, resource):
        """
        Deletes an alert.

        Args:
            resource: dict object to delete

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(resource)

    def delete_all(self, filter, timeout=-1):
        """
        Deletes all Alert objects from the appliance that match the provided filter.

        Args:
            filter (list or str):
                 A general filter string to narrow the list of items to delete. The default is no filter; all
                 resources are deleted.
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates whether the alerts were successfully deleted.
        """
        return self._client.delete_all(filter=filter, timeout=timeout)

    def update(self, resource, id_or_uri=None, timeout=-1):
        """
        Updates the specified alert resource.

        Args:
            resource (dict): Object to update.
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated alert.
        """
        uri = resource.pop('uri', None)
        if not uri:
            if not id_or_uri:
                raise ValueError("URI was not provided")
            uri = self._client.build_uri(id_or_uri)
        return self._client.update(resource=resource, uri=uri, timeout=timeout)

    def delete_alert_change_log(self, id_or_uri):
        """
        Deletes alert change log by alert ID or URI.

        Args:
            id_or_uri: alert ID or URI.
        """
        uri = self.URI + "/AlertChangeLog/" + extract_id_from_uri(id_or_uri)
        resource = {"uri": uri}
        self._client.delete(resource)
コード例 #9
0
class Switches(object):
    """
    Switches API client.

    Note:
        This resource is only available on C7000 enclosures.

    """
    URI = '/rest/switches'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_statistics(self, id_or_uri, port_name=''):
        """
        Gets statistics for a switch.

        Args:
            id_or_uri: Can be either the switch id or the switch uri.
            port_name: switch port number (optional)

        Returns:
            dict
        """
        uri = self._client.build_uri(id_or_uri) + "/statistics"

        if port_name:
            uri += "/" + port_name

        return self._client.get(uri)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a list of top of rack switches.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of rack switches.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets a switch by ID or by URI.

        Args:
            id_or_uri: Can be either the switch ID or URI.

        Returns:
            dict: Switch
        """
        return self._client.get(id_or_uri)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes a migrated switch.

        Args:
            resource (dict): Object to delete.
            force (bool):
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.
        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def get_environmental_configuration(self, id_or_uri):
        """
        Gets the environmental configuration for a switch.

        Args:
            id_or_uri: Can be either the resource ID or URI.

        Returns:
            dict: environmental configuration
        """
        uri = self._client.build_uri(id_or_uri) + "/environmentalConfiguration"
        return self._client.get(uri)

    def get_by(self, field, value):
        """
        Gets all switches that match the filter.

        The search is case-insensitive.

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            list: A list of rack switches.
        """
        return self._client.get_by(field, value)

    def update_ports(self, ports, id_or_uri):
        """
        Updates the switch ports. Only the ports under the management of OneView and those that are unlinked are
        supported for update.

        Note:
            This method is available for API version 300 or later.

        Args:
            ports: List of Switch Ports.
            id_or_uri: Can be either the switch id or the switch uri.

        Returns:
            dict: Switch
        """
        ports = merge_default_values(ports, {'type': 'port'})

        uri = self._client.build_uri(id_or_uri) + "/update-ports"
        return self._client.update(uri=uri, resource=ports)

    def patch(self, id_or_uri, operation, path, value, timeout=-1):
        """
        Uses the PATCH to update a resource for a given logical switch.

        Only one operation can be performed in each PATCH call.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.
            operation: Patch operation
            path: Path
            value: Value
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated resource.
        """
        return self._client.patch(id_or_uri,
                                  operation,
                                  path,
                                  value,
                                  timeout=timeout)
コード例 #10
0
class LogicalSwitches(object):
    """
    Logical Switches API client.

    Note:
        This resource is only available on C7000 enclosures.

    """
    URI = '/rest/logical-switches'

    SWITCH_DEFAULT_VALUES = {
        '200': {
            "type": "logical-switch"
        },
        '300': {
            "type": "logical-switchV300"
        },
        '500': {
            "type": "logical-switchV300"
        },
        '600': {
            "type": "logical-switchV4"
        }
    }

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of Logical Switches. The collection is based on optional
        sorting and filtering and is constrained by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of Logical Switches.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes a Logical Switch.

        Args:
            resource: dict object to delete
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def get(self, id_or_uri):
        """
        Gets the Logical Switch with the specified ID.

        Args:
            id_or_uri: Can be either the Logical Switch ID or URI

        Returns:
            dict: Logical Switch.
        """
        return self._client.get(id_or_uri)

    def create(self, resource, timeout=-1):
        """
        Creates a Logical Switch.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Created resource.
        """
        self.__set_default_values(resource)
        return self._client.create(resource, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates a Logical Switch.

        Args:
            resource (dict): Object to update.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Updated resource.
        """
        self.__set_default_values(resource)
        uri = self._client.build_uri(resource['logicalSwitch']['uri'])
        return self._client.update(resource, uri=uri, timeout=timeout)

    def get_by(self, field, value):
        """
        Gets all Logical Switches that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of Logical Switches.
        """
        return self._client.get_by(field, value)

    def refresh(self, id_or_uri, timeout=-1):
        """
        The Refresh action reclaims the top-of-rack switches in a logical switch.

        Args:
            id_or_uri:
                Can be either the Logical Switch ID or URI
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: The Logical Switch
        """
        uri = self._client.build_uri(id_or_uri) + "/refresh"
        return self._client.update_with_zero_body(uri, timeout=timeout)

    def patch(self, id_or_uri, operation, path, value, timeout=-1):
        """
        Uses the PATCH to update a resource for a given logical switch group.

        Only one operation can be performed in each PATCH call.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.
            operation: Patch operation
            path: Path
            value: Value
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated resource.
        """
        return self._client.patch(id_or_uri,
                                  operation,
                                  path,
                                  value,
                                  timeout=timeout)

    def __set_default_values(self, resource):
        if 'logicalSwitch' in resource:
            resource['logicalSwitch'] = self._client.merge_default_values(
                resource['logicalSwitch'], self.SWITCH_DEFAULT_VALUES)
コード例 #11
0
class DriveEnclosures(object):
    """
    Drive Enclosures API client.

    Note:
        This resource is only available on HPE Synergy

    """
    URI = '/rest/drive-enclosures'
    PORT_MAP_PATH = "/port-map"
    REFRESH_STATE_PATH = "/refreshState"

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets information about all drive enclosures. Filtering and sorting are supported with the retrieval of
        managed storage systems. The following storage system attributes can be used with filtering and sorting
        operation: name, model, serialNumber, firmware, status, managedDomain, and state.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of all drive enclosures.
        """
        return self._client.get_all(start=start, count=count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets the specified drive enclosure resource by ID or by URI.

        Args:
            id_or_uri: Can be either the drive enclosure ID or the drive enclosure URI.

        Returns:
            dict: The drive enclosure.
        """
        return self._client.get(id_or_uri=id_or_uri)

    def get_by(self, field, value):
        """
        Gets all drive enclosures that match the filter.

        The search is case-insensitive.

        Args:
            Field: field name to filter.
            Value: value to filter.

        Returns:
            list: A list of drive enclosures.
        """
        return self._client.get_by(field=field, value=value)

    def get_port_map(self, id_or_uri):
        """
        Use to get the drive enclosure I/O adapter port to SAS interconnect port connectivity.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.

        Returns:
            dict: Drive Enclosure Port Map
        """
        uri = self._client.build_uri(id_or_uri) + self.PORT_MAP_PATH
        return self._client.get(id_or_uri=uri)

    def refresh_state(self, id_or_uri, configuration, timeout=-1):
        """
        Refreshes a drive enclosure.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.
            configuration: Configuration
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Drive Enclosure
        """
        uri = self._client.build_uri(id_or_uri) + self.REFRESH_STATE_PATH
        return self._client.update(resource=configuration, uri=uri, timeout=timeout)

    def patch(self, id_or_uri, operation, path, value, timeout=-1):
        """
        Performs a specific patch operation for the given drive enclosure. If the server supports the particular
        operation, the operation is performed and a response is returned to the caller with the results.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.
            operation: Patch operation
            path: Path
            value: Value
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Drive Enclosure.
        """
        return self._client.patch(id_or_uri=id_or_uri, operation=operation, path=path, value=value, timeout=timeout)
コード例 #12
0
class PowerDevices(object):
    """
    Power Devices API client.

    """
    URI = '/rest/power-devices'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', query='', sort=''):
        """
        Gets a set of power delivery device resources according to the specified parameters. Filters can be used to get
        a specific set of power delivery devices. With no filters specified, the API returns a potentially paginated
        list of all the power delivery device resources subject to start/count/sort parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            query:
                 A general query string to narrow the list of resources returned. The default
                 is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
             list of power devices
        """
        return self._client.get_all(start,
                                    count,
                                    filter=filter,
                                    sort=sort,
                                    query=query)

    def get(self, id_or_uri):
        """
        Gets a single power delivery device resource based upon its uri or id.

        Args:
            id_or_uri:
                Can be either the power device id or the uri

        Returns:
            dict: The power device
        """
        return self._client.get(id_or_uri)

    def add(self, information, timeout=-1):
        """
        Adds a power delivery device resource based upon the attributes specified. Use this method to create a
        representation of power delivery devices that provide power to other resources but cannot otherwise be
        discovered by the management appliance.

        Args:
            information:
                power device information
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: added power device.
        """
        return self._client.create(information, timeout=timeout)

    def remove(self, resource, force=False, timeout=-1):
        """
        Deletes the set of power-devices according to the specified parameters. A filter is required to identify the
        set of resources to be deleted.

        Args:
            resource: dict object to remove
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
             bool: operation success
        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def add_ipdu(self, information, timeout=-1):
        """
        Add an HP iPDU and bring all components under management by discovery of its management module. Bring the
        management module under exclusive management by the appliance, configure any management or data collection
        settings, and create a private set of administrative credentials to enable ongoing communication and management
        of the iPDU. Use "force" to claim the device, even if claimed by another management appliance

        Args:
            resource: power device information
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: added power device.
        """
        uri = self.URI + "/discover"
        return self._client.create(information, uri=uri, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates the resource for the specified {id}. The properties that are omitted (not included as part of the the
        request body) are reset to their respective default values. The id and uuid properties are required and cannot
        be changed.

        Args:
            resource (dict): Object to update
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated power device
        """
        return self._client.update(resource, timeout=timeout)

    def get_power_state(self, id_or_uri):
        """
        Gets the power state (on, off or unknown) of the specified power delivery device that supports power control.
        The device must be an HP Intelligent Outlet.

        Args:
            id_or_uri:
                Can be either the power device id or the uri

        Returns:
            str: The power state
        """
        uri = self._client.build_uri(id_or_uri) + "/powerState"
        return self._client.get(uri)

    def update_power_state(self, id_or_uri, power_state):
        """
        Sets the power state of the specified power delivery device. The device must be an HP Intelligent Outlet.

        Args:
            id_or_uri:
                Can be either the power device id or the uri
            power_state:
                {"powerState":"On|Off"}

        Returns:
            str: The power state
        """
        uri = self._client.build_uri(id_or_uri) + "/powerState"
        return self._client.update(power_state, uri)

    def update_refresh_state(self, id_or_uri, refresh_state_data):
        """
        Refreshes a given intelligent power delivery device.

        Args:
            id_or_uri:
                Can be either the power device id or the uri
            refresh_state_data:
                Power device refresh request

        Returns:
            str: The power state
        """
        uri = self._client.build_uri(id_or_uri) + "/refreshState"
        return self._client.update(refresh_state_data, uri=uri)

    def remove_synchronous(self, resource, force=False, timeout=-1):
        """
        Deletes the resource specified by {id} synchronously.

        Args:
            resource: dict object to remove
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: operation success
        """
        uri = self._client.build_uri(resource['uri']) + "/synchronous"
        remove_resource = {'uri': uri}
        return self._client.delete(remove_resource,
                                   force=force,
                                   timeout=timeout)

    def get_uid_state(self, id_or_uri):
        """
        Retrieves the unit identification (UID) state (on, off, unknown) of the specified power outlet or extension bar
        resource. The device must be an HP iPDU component with a locator light (HP Intelligent Load Segment,
        HP AC Module, HP Intelligent Outlet Bar, or HP Intelligent Outlet).

        Args:
            id_or_uri:
                Can be either the power device id or the uri

        Returns:
            str: unit identification (UID) state
        """
        uri = self._client.build_uri(id_or_uri) + "/uidState"
        return self._client.get(uri)

    def update_uid_state(self, id_or_uri, refresh_state_data):
        """
        Sets the unit identification (UID) light state of the specified power delivery device. The device must be an
        HP iPDU component with a locator light (HP Intelligent Load Segment, HP AC Module, HP Intelligent Outlet Bar,
        or HP Intelligent Outlet)

        Args:
            id_or_uri:
                Can be either the power device id or the uri
            refresh_state_data:
                Power device refresh request

        Returns:
            str: The UID state
        """
        uri = self._client.build_uri(id_or_uri) + "/uidState"
        return self._client.update(refresh_state_data, uri)

    def get_utilization(self,
                        id_or_uri,
                        fields=None,
                        filter=None,
                        refresh=False,
                        view=None):
        """
        Retrieves historical utilization data for the specified metrics and time span. The device must be a component
        of an HPE iPDU.

        Args:
            id_or_uri:
                The power device id or the resource uri
            fields:
                Name of the metric(s) to be retrieved in the format METRIC[,METRIC]...If unspecified, all metrics
                supported are returned. Power delivery devices support the following utilization metrics:

                    * AveragePower
                        Average power consumption in Watts during this sample interval.
                    * PeakPower
                        Peak power consumption in Watts during this sample interval.

            filter (list or str):
                Filters should be in the format: FILTER_NAME=VALUE[,FILTER_NAME=VALUE]...

                For Example: 'startDate=2016-05-30T11:20:44.541Z,endDate=2016-05-30T19:20:44.541Z'

                startDate:
                    Start date of requested starting time range in ISO 8601 format. If omitted, the startDate is
                    determined by the endDate minus 24 hours.
                endDate:
                    End date of requested starting time range in ISO 8601 format. When omitted the endDate includes the
                    latest data sample available.

                If an excessive number of samples would otherwise be returned, the results will be segmented. The caller
                is responsible for comparing the returned sliceStartTime with the requested startTime in the response.
                If the sliceStartTime is greater than the oldestSampleTime and the requested start time, the caller is
                responsible for repeating the request with endTime set to sliceStartTime to obtain the next segment.
                This process is repeated until the full data set is retrieved.

                If the resource has no data, the UtilizationData is still returned, but will contain no samples and
                sliceStartTime/sliceEndTime will be equal. oldestSampleTime/newestSampleTime will still be set
                appropriately (null if no data is available). If the filter does not happen to overlap the data
                that a resource does have, then the metric history service will return null sample values for any
                missing samples.

            refresh:
                Specifies that if necessary, an additional request will be queued to obtain the most recent utilization
                data from the enclosure. The response will not include any refreshed data. To track the availability
                of the newly collected data, monitor the TaskResource identified by the refreshTaskUri property in
                the response. If null, no refresh was queued.
            view:
                Specifies the resolution interval length of the samples to be retrieved. This is reflected in the
                resolution in the returned response. Utilization data is automatically purged to stay within storage
                space constraints. Supported views are listed below:

                native (DEFAULT)
                    Resolution of the samples returned will be one sample for each 5-minute time period. This is the
                    default view and matches the resolution of the data returned by the enclosure. Samples at this
                    resolution are retained up to one year.
                hour
                    Resolution of the samples returned will be one sample for each 60-minute time period. Samples are
                    calculated by averaging the available 5-minute data samples that occurred within the hour, except
                    for PeakPower which is calculated by reporting the peak observed 5-minute sample value data during
                    the hour. Samples at this resolution are retained up to three years.
                day
                    Resolution of the samples returned will be one sample for each 24-hour time period. One day is a
                    24-hour period that starts at midnight GMT regardless of the time zone in which the appliance or
                    client is located. Samples are calculated by averaging the available 5-minute data samples that
                    occurred during the day, except for PeakPower which is calculated by reporting the peak observed
                    5-minute sample value data during the day. Samples at this resolution are retained up to three
                    years.

        Returns:
            dict: Utilization data
        """

        return self._client.get_utilization(id_or_uri, fields, filter, refresh,
                                            view)

    def get_by(self, field, value):
        """
        Gets all power devices that match the filter
        The search is case-insensitive

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            dict: power devices
        """
        return self._client.get_by(field, value)
コード例 #13
0
class OsDeploymentServers(object):
    URI = '/rest/deployment-servers'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self,
                start=0,
                count=-1,
                filter='',
                fields='',
                query='',
                sort='',
                view=''):
        """
        Gets a list of Deployment Servers based on optional sorting and filtering, and constrained by start and count
        parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            fields:
                Specifies which fields should be returned in the result set.
            query:
                 A general query string to narrow the list of resources returned. The default
                 is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.
            view:
                Return a specific subset of the attributes of the resource or collection, by
                specifying the name of a predefined view. The default view is expand - show all
                attributes of the resource and all elements of collections of resources.

        Returns:
             list: Os Deployment Servers
        """
        return self._client.get_all(start,
                                    count,
                                    filter=filter,
                                    sort=sort,
                                    query=query,
                                    fields=fields,
                                    view=view)

    def get(self, id_or_uri):
        """
        Get the details of the particular OS Deployment Server based on its URI or ID.

        Args:
            id_or_uri:
                Can be either the Os Deployment Server ID or the URI

        Returns:
            dict: Os Deployment Server
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all Os Deployment Servers that match the filter.
        The search is case-insensitive.

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            list: Os Deployment Servers
        """
        return self._client.get_by(field, value)

    def get_by_name(self, name):
        """
        Gets the Os Deployment Server by name.

        Args:
            name: Name of the Os Deployment Server

        Returns:
            dict: Os Deployment Server
        """
        os_deployment_server = self.get_by('name', name) or [None]
        return os_deployment_server[0]

    def add(self, resource, timeout=-1):
        """
        Adds a Deployment Server using the information provided in the request body. Note: The type of the Deployment
        Server is always assigned as "Image streamer".

        Args:
            resource (dict):
                Deployment Manager resource.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: The added resource.
        """
        return self._client.create(resource, timeout=timeout)

    def update(self, resource, force=False, timeout=-1):
        """
        Updates the Deployment Server resource. The properties that are omitted (not included as part
        of the request body) are ignored.

        Args:
            resource (dict): Object to update.
            force:
                If set to true, the operation completes despite any problems with network connectivity or errors on
                the resource itself. The default is false.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stops waiting for its completion.

        Returns:
            Updated resource.
        """
        return self._client.update(resource, timeout=timeout, force=force)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes a Deployment Server object based on its UUID or URI.

        Args:
            resource (dict):
                Object to delete.
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the volume was successfully deleted.
        """

        return self._client.delete(resource, force=force, timeout=timeout)

    def get_networks(self):
        """
        Gets a list of all the One View networks.

        Returns:
             list: Networks
        """
        uri = self.URI + '/network'
        return self._client.get(uri)

    def get_appliances(self,
                       start=0,
                       count=-1,
                       filter='',
                       fields='',
                       query='',
                       sort='',
                       view=''):
        """
        Gets a list of all the Image Streamer resources based on optional sorting and filtering, and constrained
        by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            fields:
                Specifies which fields should be returned in the result set.
            query:
                 A general query string to narrow the list of resources returned. The default
                 is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.
            view:
                Return a specific subset of the attributes of the resource or collection, by
                specifying the name of a predefined view. The default view is expand - show all
                attributes of the resource and all elements of collections of resources.

        Returns:
             list: Image Streamer resources associated with the Deployment Servers.
        """
        uri = self.URI + '/image-streamer-appliances'
        return self._client.get_all(start,
                                    count,
                                    filter=filter,
                                    sort=sort,
                                    query=query,
                                    fields=fields,
                                    view=view,
                                    uri=uri)

    def get_appliance(self, id_or_uri, fields=''):
        """
        Gets the particular Image Streamer resource based on its ID or URI.

        Args:
            id_or_uri:
                Can be either the Os Deployment Server ID or the URI
            fields:
                Specifies which fields should be returned in the result.

        Returns:
             dict: Image Streamer resource.
        """
        uri = self.URI + '/image-streamer-appliances/' + extract_id_from_uri(
            id_or_uri)
        if fields:
            uri += '?fields=' + fields

        return self._client.get(uri)

    def get_appliance_by_name(self, appliance_name):
        """
        Gets the particular Image Streamer resource based on its name.

        Args:
            appliance_name:
                The Image Streamer resource name.

        Returns:
             dict: Image Streamer resource.
        """
        appliances = self.get_appliances()

        if appliances:
            for appliance in appliances:
                if appliance['name'] == appliance_name:
                    return appliance
        return None
コード例 #14
0
class LogicalDownlinks(object):
    """
    Logical Downlinks API client.

    """
    URI = '/rest/logical-downlinks'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of logical downlinks. The collection is based on
        optional sorting and filtering and is constrained by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of logical downlinks.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets a logical downlink by ID or by URI.

        Args:
            id_or_uri: Can be either the logical downlink id or the logical downlink uri.

        Returns:
            dict: The logical downlink.
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all logical downlinks that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of logical downlinks.
        """
        return self._client.get_by(field, value)

    def get_all_without_ethernet(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of logical downlinks without ethernet. The collection is
        based on optional sorting and filtering and is constrained by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            dict
        """
        without_ethernet_client = ResourceClient(
            self._connection, "/rest/logical-downlinks/withoutEthernet")
        return without_ethernet_client.get_all(start,
                                               count,
                                               filter=filter,
                                               sort=sort)

    def get_without_ethernet(self, id_or_uri):
        """
        Gets the logical downlink with the specified ID without ethernet.

        Args:
            id_or_uri: Can be either the logical downlink id or the logical downlink uri.

        Returns:
            dict
        """
        uri = self._client.build_uri(id_or_uri) + "/withoutEthernet"
        return self._client.get(uri)
コード例 #15
0
class GoldenImages(object):
    URI = '/rest/golden-images'

    def __init__(self, con):
        self._client = ResourceClient(con, self.URI)
        self._task_monitor = TaskMonitor(con)
        self.__default_values = {
            'type': 'GoldenImage',
        }

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Retrieves a list of Golden Image resources as per the specified parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of Golden Images.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def create(self, resource, timeout=-1):
        """
        Creates a Golden Image resource from the deployed OS Volume as per the attributes specified.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Golden Image created.
        """
        data = self.__default_values.copy()
        data.update(resource)
        return self._client.create(data, timeout=timeout)

    def upload(self, file_path, golden_image_info):
        """
        Adds a Golden Image resource from the file that is uploaded from a local drive. Only the .zip format file can
        be used for the upload.

        Args:
            file_path (str): File name to upload.
            golden_image_info (dict): Golden Image information.

        Returns:
            dict: Golden Image.
        """
        uri = "{0}?name={1}&description={2}".format(
            self.URI, quote(golden_image_info.get('name', '')),
            quote(golden_image_info.get('description', '')))

        return self._client.upload(file_path, uri)

    def download_archive(self, id_or_uri, file_path):
        """
        Download the details of the Golden Image capture logs, which has been archived based on the specific attribute
        ID.

        Args:
            id_or_uri: ID or URI of the Golden Image.
            file_path (str): File name to save the archive.

        Returns:
            bool: Success.
        """
        uri = self.URI + "/archive/" + extract_id_from_uri(id_or_uri)
        return self._client.download(uri, file_path)

    def download(self, id_or_uri, file_path):
        """
        Downloads the content of the selected Golden Image as per the specified attributes.

        Args:
            id_or_uri: ID or URI of the Golden Image.
            file_path(str): Destination file path.

        Returns:
            bool: Successfully downloaded.
        """
        uri = self.URI + "/download/" + extract_id_from_uri(id_or_uri)
        return self._client.download(uri, file_path)

    def get(self, id_or_uri):
        """
        Retrieves the overview details of the selected Golden Image as per the specified attributes.

        Args:
            id_or_uri: ID or URI of the Golden Image.

        Returns:
            dict: The Golden Image.
        """
        return self._client.get(id_or_uri)

    def update(self, resource, timeout=-1):
        """
        Updates the properties of the Golden Image.

        Args:
            resource (dict): Object to update.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Updated resource.

        """
        return self._client.update(resource, timeout=timeout)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes the Golden Image specified.

        Args:
            resource: dict object to delete
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def get_by(self, field, value):
        """
        Gets all Golden Images that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of Golden Images.
        """
        return self._client.get_by(field, value)
コード例 #16
0
class SanManagers(object):
    """
    SAN Managers API client.

    """
    URI = '/rest/fc-sans/device-managers'
    PROVIDER_URI = '/rest/fc-sans/providers'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)
        self._provider_client = ResourceClient(con, self.PROVIDER_URI)

    def get_all(self, start=0, count=-1, query='', sort=''):
        """
        Retrieves the list of registered SAN Managers.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items. The actual number of items in
                the response may differ from the requested count if the sum of start and count exceed the total number
                of items.
            query:
                A general query string to narrow the list of resources returned.
                The default is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of SAN managers.

        """
        return self._client.get_all(start=start,
                                    count=count,
                                    query=query,
                                    sort=sort)

    def get(self, id_or_uri):
        """
        Retrieves a single registered SAN Manager by ID or URI.

        Args:
            id_or_uri: Can be either the SAN Manager resource ID or URI.

        Returns:
            dict: The SAN Manager resource.
        """
        return self._client.get(id_or_uri=id_or_uri)

    def update(self, resource, id_or_uri):
        """
        Updates a registered Device Manager.

        Args:
            resource (dict): Object to update.
            id_or_uri: Can be either the Device manager ID or URI.

        Returns:
            dict: The device manager resource.
        """
        return self._client.update(resource=resource, uri=id_or_uri)

    def add(self, resource, provider_uri_or_id, timeout=-1):
        """
        Adds a Device Manager under the specified provider.

        Args:
            resource (dict): Object to add.
            provider_uri_or_id: ID or URI of provider.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView, just stop waiting for its completion.

        Returns:
            dict: Added SAN Manager.
        """
        uri = self._provider_client.build_uri(
            provider_uri_or_id) + "/device-managers"
        return self._client.create(resource=resource, uri=uri, timeout=timeout)

    def get_provider_uri(self, provider_display_name):
        """
        Gets uri for a specific provider.

        Args:
            provider_display_name: Display name of the provider.

        Returns:
            uri
        """
        providers = self._provider_client.get_by('displayName',
                                                 provider_display_name)
        return providers[0]['uri'] if providers else None

    def get_default_connection_info(self, provider_name):
        """
        Gets default connection info for a specific provider.

        Args:
            provider_name: Name of the provider.

        Returns:
            dict: Default connection information.
        """
        provider = self._provider_client.get_by_name(provider_name)
        if provider:
            return provider['defaultConnectionInfo']
        else:
            return {}

    def remove(self, resource, timeout=-1):
        """
        Removes a registered SAN Manager.

        Args:
            resource (dict): Object to delete.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully removed.
        """
        return self._client.delete(resource, timeout=timeout)

    def get_by_name(self, name):
        """
        Gets a SAN Manager by name.

        Args:
            name: Name of the SAN Manager

        Returns:
            dict: SAN Manager.
        """
        san_managers = self._client.get_all()
        result = [x for x in san_managers if x['name'] == name]
        return result[0] if result else None

    def get_by_provider_display_name(self, provider_display_name):
        """
        Gets a SAN Manager by provider display name.

        Args:
            provider_display_name: Name of the Provider Display Name

        Returns:
            dict: SAN Manager.
        """
        san_managers = self._client.get_all()
        result = [
            x for x in san_managers
            if x['providerDisplayName'] == provider_display_name
        ]
        return result[0] if result else None
コード例 #17
0
class UnmanagedDevices(object):
    URI = '/rest/unmanaged-devices'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', query='', sort=''):
        """
        Gets a set of unmanaged device resources according to the specified parameters. Filters can be used to get a
        specific set of unmanaged devices. With no filters specified, the API returns a potentially paginated list of
        all the unmanaged device resources subject to start/count/sort parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            query:
                 A general query string to narrow the list of resources returned. The default
                 is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
             list: Unmanaged Devices
        """
        return self._client.get_all(start, count, filter=filter, sort=sort, query=query)

    def get(self, id_or_uri):
        """
        Gets a single Unmanaged Device resource based upon its uri or id.

        Args:
            id_or_uri:
                Can be either the Unmanaged Device id or the uri

        Returns:
            dict: The Unmanaged Device
        """
        return self._client.get(id_or_uri)

    def add(self, information, timeout=-1):
        """
        Adds an unmanaged device resource based upon the attributes specified. Use this method to create an unmanaged
        device to represent resources that consume space within a rack, or consume power from a power delivery device
        but cannot otherwise be represented by the management appliance.

        Args:
            information:
                Unmanaged Device information
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Added Unmanaged Device
        """
        return self._client.create(information, timeout=timeout)

    def remove(self, resource, force=False, timeout=-1):
        """
        Deletes the resource specified.

        Args:
            resource:
                 Dict object to remove
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                 Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                 in OneView; it just stops waiting for its completion.

        Returns:
             bool: operation success
        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def remove_all(self, filter, force=False, timeout=-1):
        """
        Deletes the set of unmanaged-devices according to the specified parameters. A filter is required to identify
        the set of resources to be deleted.

        Args:
            filter:
                 A general filter/query string to narrow the list of items that will be removed.
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                 Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                 in OneView; it just stops waiting for its completion.

        Returns:
             bool: operation success
        """
        return self._client.delete_all(filter=filter, force=force, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates the resource for the specified. The properties that are omitted (not included as part of the the
        request body) are reset to their respective default values. The id and uuid properties are required and cannot
        be changed.

        Args:
            resource (dict): Object to update
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated Unmanaged Devices
        """
        return self._client.update(resource, timeout=timeout)

    def get_environmental_configuration(self, id_or_uri):
        """
        Returns a description of the environmental configuration (supported feature set, calibrated minimum & maximum
        power, location & dimensions, ...) of the resource.

        Args:
            id_or_uri:
                Can be either the Unmanaged Device id or the uri

        Returns:
            dict:
                EnvironmentalConfiguration
        """
        uri = self._client.build_uri(id_or_uri) + "/environmentalConfiguration"
        return self._client.get(uri)

    def get_by(self, field, value):
        """
        Gets all Unmanaged Devices that match the filter
        The search is case-insensitive

        Args:
            field: field name to filter
            value: value to filter

        Returns:
            dict: Unmanaged Devices
        """
        return self._client.get_by(field, value)
コード例 #18
0
class Connections(object):
    """
    Connections API client.

    """

    URI = '/rest/connections'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort='', view='', fields=''):
        """
        Gets a paginated collection of connections based on optional sorting and filtering,
        and constrained by start and count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.
            fields:
                Specifies which fields should be returned in the result set.
            view:
                 Returns a specific subset of the attributes of the resource or collection, by
                 specifying the name of a predefined view. The default view is expand (show
                 all attributes of the resource and all elements of collections of resources).

        Returns:
            list: A list of connections.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort, view=view, fields=fields)

    def get_by(self, field, value):
        """
        Gets all connections that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of connections.
        """
        return self._client.get_by(field, value)

    def get(self, id_or_uri):
        """
        Returns the connection with the specified ID or URI.

        Args:
            id: ID or URI of connection

        Returns:
            dict
        """
        return self._client.get(id_or_uri)
コード例 #19
0
class BuildPlans(object):
    URI = '/rest/build-plans'

    DEFAULT_VALUES = {
        '300': {
            'type': 'OeBuildPlan'
        },
        '500': {
            'type': 'OeBuildPlanV5'
        },
        '600': {
            'type': 'OeBuildPlanV5'
        }
    }

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a list of OS Build Plan resources based on optional sorting and filtering, and constrained by start and
        count parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of OS Build Plan.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get_by(self, field, value):
        """
        Gets all OS Build Plans that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of OS Build Plans.
        """
        return self._client.get_by(field, value)

    def get(self, id_or_uri):
        """
        Retrieves a specific OS Build Plan resource based on the ID or URI provided.

        Args:
            id_or_uri: ID or URI of the Build Plan.

        Returns:
            dict: The OS Build Plan.
        """
        return self._client.get(id_or_uri)

    def create(self, resource, timeout=-1):
        """
        Creates an OS Build Plan using the information provided. The OS Build Plan can be one of the following types -
        Deploy or Capture.

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Created OS Build Plan.

        """
        return self._client.create(resource,
                                   timeout=timeout,
                                   default_values=self.DEFAULT_VALUES)

    def update(self, resource, timeout=-1):
        """
        Updates the properties of the OS Build Plan.

        Args:
            resource (dict): Object to update.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Updated OS Build Plan.

        """
        return self._client.update(resource, timeout=timeout)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes an OS Build Plan resource.

        Args:
            resource: dict object to delete
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(resource, force=force, timeout=timeout)
コード例 #20
0
class Datacenters(object):
    """
    Datacenters API client.

    """
    URI = '/rest/datacenters'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', query='', sort=''):
        """
        Gets a set of data center resources according to the specified parameters. Filters can be used to get a specific
        set of data centers.

        Args:
            start:
                The first item to return, using 0-based indexing.

                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            query:
                 A general query string to narrow the list of resources returned. The default
                 is no query - all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: List of data centers.
        """
        return self._client.get_all(start,
                                    count,
                                    filter=filter,
                                    sort=sort,
                                    query=query)

    def get(self, id_or_uri):
        """
        Gets a single data center resource based upon its ID or URI.

        Args:
            id_or_uri:
                Can be either the data center id or the data center uri.

        Returns:
            dict: The data center.
        """
        return self._client.get(id_or_uri)

    def get_visual_content(self, id_or_uri):
        """
        Gets a list of visual content objects describing each rack within the data center. The response aggregates data
        center and rack data with a specified metric (peak24HourTemp) to provide simplified access to display data for
        the data center.

        Args:
            id_or_uri: Can be either the resource ID or the resource URI.

        Return:
            list: List of visual content objects.
        """
        uri = self._client.build_uri(id_or_uri) + "/visualContent"
        return self._client.get(uri)

    def get_by(self, field, value):
        """
        Gets all data centers that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: List of data centers.

        """
        return self._client.get_by(field, value)

    def remove(self, resource, force=False, timeout=-1):
        """
        Deletes the resource specified.

        Args:
            resource (dict): Object to remove.
            force:
                 If set to true, the operation completes despite any problems with network connectivity or errors on the
                 resource itself. The default is false.
            timeout:
                Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns: Result status.
        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def add(self, information, timeout=-1):
        """
        Adds a data center resource based upon the attributes specified.

        Args:
            information: Data center information
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Added data center.
        """
        return self._client.create(information, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates the specified data center resource.

        Args:
            resource (dict): Object to update.
            timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            dict: Updated data center.
        """
        return self._client.update(resource, timeout=timeout)

    def remove_all(self, filter, force=False, timeout=-1):
        """
        Deletes the set of datacenters according to the specified parameters. A filter is required to identify the set
        of resources to be deleted.

        Args:
            filter:
                 A general filter/query string to narrow the list of items that will be removed.
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                 Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
                 in OneView; it just stops waiting for its completion.

        Returns:
             bool: operation success
        """
        return self._client.delete_all(filter=filter,
                                       force=force,
                                       timeout=timeout)
コード例 #21
0
class Fabrics(object):
    """
    Fabrics API client.

    """
    URI = '/rest/fabrics'

    DEFAULT_VALUES = {
        '300': {
            'type': 'vlan-pool'
        },
        '500': {
            'type': 'vlan-pool'
        }
    }

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a paginated collection of all fabrics based on the specified parameters.

        Filters can be used in the URL to control the number of fabrics that are returned.
        With no filters specified, the API returns all supported fabrics.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.
                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of fabrics.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def get(self, id_or_uri):
        """
        Gets the fabric with the specified ID.

        Args:
            id_or_uri: ID or URI of fabric.

        Returns:
            dict: The fabric.
        """
        return self._client.get(id_or_uri)

    def get_by(self, field, value):
        """
        Gets all fabrics that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of fabrics.
        """
        return self._client.get_by(field, value)

    def get_reserved_vlan_range(self, id_or_uri):
        """
        Gets the reserved vlan ID range for the fabric.

        Note:
            This method is only available on HPE Synergy.

        Args:
            id_or_uri: ID or URI of fabric.

        Returns:
            dict: vlan-pool
        """
        uri = self._client.build_uri(id_or_uri) + "/reserved-vlan-range"
        return self._client.get(uri)

    def update_reserved_vlan_range(self, id_or_uri, vlan_pool, force=False):
        """
        Updates the reserved vlan ID range for the fabric.

        Note:
            This method is only available on HPE Synergy.

        Args:
            id_or_uri: ID or URI of fabric.
            vlan_pool (dict): vlan-pool data to update.
            force:  If set to true, the operation completes despite any problems with network connectivity or errors
                on the resource itself. The default is false.

        Returns:
            dict: The fabric
        """
        uri = self._client.build_uri(id_or_uri) + "/reserved-vlan-range"
        return self._client.update(resource=vlan_pool,
                                   uri=uri,
                                   force=force,
                                   default_values=self.DEFAULT_VALUES)
コード例 #22
0
class PlanScripts(object):
    URI = '/rest/plan-scripts'

    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, self.URI)
        self.__default_values = {
            'type': 'PlanScript',
        }

    def get_all(self, start=0, count=-1, filter='', sort=''):
        """
        Gets a list of Plan Scripts based on optional sorting and filtering, and constrained by start and count
        parameters.

        Args:
            start:
                The first item to return, using 0-based indexing.
                If not specified, the default is 0 - start with the first available item.
            count:
                The number of resources to return. A count of -1 requests all items.

                The actual number of items in the response might differ from the requested
                count if the sum of start and count exceeds the total number of items.
            filter (list or str):
                A general filter/query string to narrow the list of items returned. The
                default is no filter; all resources are returned.
            sort:
                The sort order of the returned data set. By default, the sort order is based
                on create time with the oldest entry first.

        Returns:
            list: A list of Plan Scripts.
        """
        return self._client.get_all(start, count, filter=filter, sort=sort)

    def delete(self, resource, force=False, timeout=-1):
        """
        Deletes a Plan Script object from the appliance based on its Plan Script UUID.

        Args:
            resource: dict object to delete
            force:
                 If set to true, the operation completes despite any problems with
                 network connectivity or errors on the resource itself. The default is false.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView; it just stops waiting for its completion.

        Returns:
            bool: Indicates if the resource was successfully deleted.

        """
        return self._client.delete(resource, force=force, timeout=timeout)

    def get(self, id_or_uri):
        """
        Retrieves the overview details of the selected Plan Script as per the selected attributes.

        Args:
            id_or_uri: ID or URI of the Plan Script.

        Returns:
            dict: The Plan Script.
        """
        return self._client.get(id_or_uri)

    def create(self, resource, timeout=-1):
        """
        Adds a Plan Script using the information provided in the request body. The plan type can be one of the
        following types: General, deploy and capture. Note: The OS type for the Plan Script is always assigned
        as "ESXi".

        Args:
            resource (dict): Object to create.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Created Plan Script.

        """
        data = self.__default_values.copy()
        data.update(resource)
        return self._client.create(data, timeout=timeout)

    def update(self, resource, timeout=-1):
        """
        Updates the properties of the Plan Script.

        Args:
            resource (dict): Object to update.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Updated resource.

        """
        return self._client.update(resource, timeout=timeout)

    def get_by(self, field, value):
        """
        Gets all Plan Scripts that match the filter.

        The search is case-insensitive.

        Args:
            field: Field name to filter.
            value: Value to filter.

        Returns:
            list: A list of Plan Scripts.
        """
        return self._client.get_by(field, value)

    def retrieve_differences(self, id_or_uri, content, timeout=-1):
        """
        Retrieves the modified contents of the selected Plan Script according to the provided content object, as per
        the selected attributes.

        Args:
            id_or_uri: ID or URI of the Plan Script.
            content (str): Plan Script content.
            timeout:
                Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
                in OneView, it just stops waiting for its completion.

        Returns:
            dict: Script differences.
        """
        uri = self.URI + "/differences/" + extract_id_from_uri(id_or_uri)
        return self._client.create(content, uri=uri, timeout=timeout)

    def get_usedby_and_readonly(self, id):
        """
        Gets the build plans details os teh selected plan script as per the selected attributes.

        Args:
            id: ID of the Plan Script.

        Returns:
            array of build plans
        """
        uri = self.URI + "/" + id + "/usedby/readonly"
        return self._client.get(uri)