def _umount_virtual_cd(self, connection, response): unmount_path = None unmount_body = None if self.typepath.defs.isgen10 or \ self.typepath.defs.isgen9: unmount_path = self._get_eject_media(response) unmount_body = {} if not unmount_path: operation = _("Failed to unmount image") error = _("Failed to find unmount path") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error) else: unmount_path = response.dict.get("@odata.id", "") unmount_body = { "Action": "EjectVirtualMedia", "Target": self.typepath.defs.oempath } resp = connection.post(path=unmount_path, body=unmount_body) if resp.status != 200: self.log.error("Unmounting cd failed: %r, cd location: %r", resp, unmount_path) operation = _("Failed to unmount image") error = self._get_error(resp) raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error)
def _check_success(response): if response.status >= 200 and response.status < 300: return True else: try: _ = response.dict raise virtmedia_exception.VirtmediaOperationError( "Response status is %d, %s" % (response.status, response.dict["error"] ["@Message.ExtendedInfo"][0]["MessageId"].split("."))) except Exception: raise virtmedia_exception.VirtmediaOperationError( "Response status is not 200, %s" % response)
def _mount_virtual_cd(self, connection, image_location): instances = self._get_instances(connection) for instance in instances: for vmlink in self._get_virtual_media_devices( connection, instance): response = connection.get(vmlink["@odata.id"]) if response.status == 200 and "DVD" in response.dict[ "MediaTypes"]: if response.dict['Inserted']: self._umount_virtual_cd(connection, response) body = {"Image": image_location} if image_location: body["Oem"] = {self.typepath.defs.oemhp: {"BootOnNextServerReset": \ True}} response = connection.patch(path=vmlink["@odata.id"], body=body) elif response.status != 200: self.log.error("Failed to mount image") error = self._get_error(response) operation = _("Failed to mount image") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error)
def _prepare_floppy_image(task, params): """Prepares the floppy image for passing the parameters. This method prepares a temporary vfat filesystem image, which contains the parameters to be passed to the ramdisk. Then it uploads the file NFS or CIFS server. :param task: a TaskManager instance containing the node to act on. :param params: a dictionary containing 'parameter name'->'value' mapping to be passed to the deploy ramdisk via the floppy image. :returns: floppy image filename :raises: ImageCreationFailed, if it failed while creating the floppy image. :raises: VirtmediaOperationError, if copying floppy image file failed. """ floppy_filename = _get_floppy_image_name(task.node) floppy_fullpathname = os.path.join(CONF.remote_image_share_root, floppy_filename) with tempfile.NamedTemporaryFile() as vfat_image_tmpfile_obj: images.create_vfat_image(vfat_image_tmpfile_obj.name, parameters=params) try: shutil.copyfile(vfat_image_tmpfile_obj.name, floppy_fullpathname) except IOError as e: operation = _("Copying floppy image file") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=e) return floppy_filename
def _check_supported_idrac_version(self, connection): response = connection.get('%s/VirtualMedia/CD' % self.idrac_location) self._check_success(response) data = response.dict for i in data.get('Actions', []): if i == "#VirtualMedia.InsertMedia" or i == "#VirtualMedia.EjectMedia": return True raise virtmedia_exception.VirtmediaOperationError( "Unsupported version of iDRAC, please update before continuing")
def _get_virtual_media_devices(self, connection): idr = connection.get("%s" % self.idrac_location) self._check_success(idr) try: virtual_media = connection.get( idr.dict["VirtualMedia"]["@odata.id"]) self._check_success(virtual_media) except KeyError: self.log.error("Cannot find a single virtual media device") raise virtmedia_exception.VirtmediaOperationError( "Cannot find any virtual media device on the server") return virtual_media.dict["Members"]
def _init_connection(self, driver_info): """Get connection info and init rest_object""" host = 'https://' + driver_info['address'] user = driver_info['username'] password = driver_info['password'] redfishclient = None self.log.debug("Init connection: user: %s, passwd: %s, host: %s", user, password, host) try: redfishclient = redfish_client(base_url=host, \ username=user, password=password) redfishclient.login(auth=AuthMethod.SESSION) except ServerDownOrUnreachableError as error: operation = _("iDRAC not responding") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error) except Exception as error: operation = _("Failed to login to iDRAC") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error) return redfishclient
def _init_connection(self, driver_info): """Get connection info and init rest_object""" host = 'https://' + driver_info['address'] user = driver_info['username'] password = driver_info['password'] redfishclient = None try: redfishclient = redfish_client(base_url=host, \ username=user, password=password, \ default_prefix="/redfish/v1") redfishclient.login(auth=AuthMethod.SESSION) self._init_typepath(redfishclient) except ServerDownOrUnreachableError as error: operation = _("iLO not responding") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error) except Exception as error: operation = _("Failed to login to iLO") raise virtmedia_exception.VirtmediaOperationError( operation=operation, error=error) return redfishclient