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)
def get_backup(self, id_or_uri): """ Get the details for the backup from an Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. Returns: Dict: Backup for an Artifacts Bundle. """ uri = self.BACKUPS_PATH + '/' + extract_id_from_uri(id_or_uri) return self._client.get(id_or_uri=uri)
def get_backup(self, id_or_uri): """ Get the details for the backup from an Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. Returns: Dict: Backup for an Artifacts Bundle. """ uri = self.BACKUPS_PATH + '/' + extract_id_from_uri(id_or_uri) return self._client.get(id_or_uri=uri)
def get_backup(self, uri): """ Get the details for the backup from an Artifact Bundle. Args: uri: URI of the Artifact Bundle. Returns: Dict: Backup for an Artifacts Bundle. """ uri = self.BACKUPS_PATH + '/' + extract_id_from_uri(uri) return super(ArtifactBundles, self).get_by_uri(uri)
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)
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)
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)
def download_artifact_bundle(self, id_or_uri, file_path): """ Download the Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. file_path(str): Destination file path. Returns: bool: Successfully downloaded. """ uri = self.DOWNLOAD_PATH + '/' + 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 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 download_artifact_bundle(self, id_or_uri, file_path): """ Download the Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. file_path(str): Destination file path. Returns: bool: Successfully downloaded. """ uri = self.DOWNLOAD_PATH + '/' + extract_id_from_uri(id_or_uri) return self._client.download(uri, file_path)
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_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, path, uri=None): """ Download the Artifact Bundle. Args: uri: URI of the Artifact Bundle. path(str): Destination file path. Returns: bool: Successfully downloaded. """ if not uri: uri = self.data['uri'] download_uri = self.DOWNLOAD_PATH + '/' + extract_id_from_uri(uri) return super(ArtifactBundles, self).download(download_uri, path)
def stop_artifact_creation(self, id_or_uri, task_uri): """ Stops creation of the selected Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. task_uri: Task URI associated with the Artifact Bundle. Returns: string: """ data = {"taskUri": task_uri} uri = self.URI + '/' + extract_id_from_uri( id_or_uri) + self.STOP_CREATION_PATH return self._client.update(data, uri=uri)
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_options(self, interconnects, facts): interconnect_uri = interconnects[0]['uri'] if self.options.get('nameServers'): name_servers = self.oneview_client.interconnects.get_name_servers( interconnect_uri) facts['interconnect_name_servers'] = name_servers if self.options.get('statistics'): facts[ 'interconnect_statistics'] = self.oneview_client.interconnects.get_statistics( interconnect_uri) if self.options.get('portStatistics'): port_name = self.options['portStatistics'] port_statistics = self.oneview_client.interconnects.get_statistics( interconnect_uri, port_name) facts['interconnect_port_statistics'] = port_statistics if self.options.get('subPortStatistics'): facts['interconnect_subport_statistics'] = None sub_options = self.options['subPortStatistics'] if isinstance(sub_options, dict) and sub_options.get( 'portName') and sub_options.get('subportNumber'): facts[ 'interconnect_subport_statistics'] = self.oneview_client.interconnects.get_subport_statistics( interconnect_uri, sub_options['portName'], sub_options['subportNumber']) if self.options.get('ports'): ports = self.oneview_client.interconnects.get_ports( interconnect_uri) facts['interconnect_ports'] = ports if self.options.get('port'): port_name = self.options.get('port') port_id = "{}:{}".format(extract_id_from_uri(interconnect_uri), port_name) port = self.oneview_client.interconnects.get_port( interconnect_uri, port_id) facts['interconnect_port'] = port if self.options.get('pluggableModuleInformation'): sfp_info = self.oneview_client.interconnects.get_pluggable_module_information( interconnect_uri) facts['interconnect_pluggable_module_information'] = sfp_info
def download_archive(self, path, uri=None): """ Downloads backup archive for the Artifact Bundle. Args: path(str): Destination file path. uri: URI of the Artifact Bundle. Returns: bool: Successfully downloaded. """ if not uri: uri = self.data['uri'] download_uri = self.BACKUP_ARCHIVE_PATH + '/' + extract_id_from_uri( uri) return super(ArtifactBundles, self).download(download_uri, path)
def stop_artifact_creation(self, id_or_uri, task_uri): """ Stops creation of the selected Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. task_uri: Task URI associated with the Artifact Bundle. Returns: string: """ data = { "taskUri": task_uri } uri = self.URI + '/' + extract_id_from_uri(id_or_uri) + self.STOP_CREATION_PATH return self._client.update(data, 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(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 extract_backup(self, resource, uri=None, timeout=-1): """ Extracts the existing backup bundle on the appliance and creates all the artifacts. Args: resource (dict): Deployment Group to extract. uri: URI of artifact backup 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: A Deployment Group associated with the Artifact Bundle backup. """ if not uri: uri = self.data['uri'] extract_uri = self.BACKUPS_PATH + '/' + extract_id_from_uri(uri) return self._helper.update(resource, extract_uri, timeout=timeout)
def __get_options(self, facts): if self.options.get('nameServers'): name_servers = self.current_resource.get_name_servers() facts['interconnect_name_servers'] = name_servers if self.options.get('statistics'): facts[ 'interconnect_statistics'] = self.current_resource.get_statistics( ) if self.options.get('portStatistics'): port_name = self.options['portStatistics'] port_statistics = self.current_resource.get_statistics(port_name) facts['interconnect_port_statistics'] = port_statistics if self.options.get('subPortStatistics'): facts['interconnect_subport_statistics'] = None sub_options = self.options['subPortStatistics'] if isinstance(sub_options, dict) and sub_options.get( 'portName') and sub_options.get('subportNumber'): facts[ 'interconnect_subport_statistics'] = self.current_resource.get_subport_statistics( sub_options['portName'], sub_options['subportNumber']) if self.options.get('ports'): ports = self.current_resource.get_ports() facts['interconnect_ports'] = ports if self.options.get('port'): port_name = self.options.get('port') port_id = "{}:{}".format( extract_id_from_uri(self.current_resource.data['uri']), port_name) port = self.current_resource.get_port(port_id) facts['interconnect_port'] = port if self.options.get('pluggableModuleInformation'): sfp_info = self.current_resource.get_pluggable_module_information() facts['interconnect_pluggable_module_information'] = sfp_info
} # Try load config from a file (if there is a config file) config = try_load_from_file(config) _client = OneViewClient(config) # Getting the first 5 alerts print("\nGetting the first 5 alerts") alerts = _client.alerts.get_all(0, 5) for alert in alerts: print("uri: '{uri}' | type: '{type}' | alertState: '{alertState}'".format(**alert)) # Get a specific alert (first of the list that was obtained in previous item) print("\nGet a specific alert") id_alert_by_id = extract_id_from_uri(alerts[0]['uri']) print("Find id == %s" % id_alert_by_id) alert_by_id = _client.alerts.get(id_alert_by_id) print("uri: '%s' | alertState: '%s'" % (alert_by_id['uri'], alert_by_id['alertState'])) # Get by Uri print("Find uri == %s" % (alert['uri'])) alert_by_uri = _client.alerts.get(alert['uri']) print("uri: '%s' | alertState: '%s'" % (alert_by_uri['uri'], alert_by_uri['alertState'])) # Find first alert by state print("\nGet first alert by state: Cleared") alert_by_state = _client.alerts.get_by('alertState', 'Cleared')[0] print("Found alert by state: '%s' | uri: '%s'" % (alert_by_state['alertState'], alert_by_state['uri'])) # Updates state alert and add note
} # Try load config from a file (if there is a config file) config = try_load_from_file(config) _client = OneViewClient(config) # Getting the first 5 alerts print("\nGetting the first 5 alerts") alerts = _client.alerts.get_all(0, 5) for alert in alerts: print("uri: '{uri}' | type: '{type}' | alertState: '{alertState}'".format(**alert)) # Get a specific alert (first of the list that was obtained in previous item) print("\nGet a specific alert") id_alert_by_id = extract_id_from_uri(alerts[0]['uri']) print("Find id == %s" % id_alert_by_id) alert_by_id = _client.alerts.get(id_alert_by_id) print("uri: '%s' | alertState: '%s'" % (alert_by_id['uri'], alert_by_id['alertState'])) # Get by Uri print("Find uri == %s" % (alert['uri'])) alert_by_uri = _client.alerts.get(alert['uri']) print("uri: '%s' | alertState: '%s'" % (alert_by_uri['uri'], alert_by_uri['alertState'])) # Find first alert by state print("\nGet first alert by state: Cleared") alert_by_state = _client.alerts.get_by('alertState', 'Cleared')[0] print("Found alert by state: '%s' | uri: '%s'" % (alert_by_state['alertState'], alert_by_state['uri'])) # Updates state alert and add note