def attach_volume(self, instance, connection_info, ebs_root=False):
        """Attach a volume to the SCSI controller or to the SATA controller if
        ebs_root is True.

        .. notes:
            This action require the instance to be powered off
        """
        LOG.debug("Attach_volume: %(connection_info)s to %(instance_name)s",
                  {'connection_info': connection_info,
                   'instance_name': instance.name})

        if ebs_root:
            # Attaching to the first slot of SATA controller
            controller = constants.SYSTEM_BUS_SATA.upper()
            port, device = (0, 0)
        else:
            # Attaching to the first available port of SCSI controller
            controller = constants.SYSTEM_BUS_SCSI.upper()
            port, device = vhdutils.get_available_attach_point(instance,
                                                               controller)
        try:
            self._vbox_manage.scsi_storage_attach(
                instance, controller, port, device, connection_info,
                self.get_initiator(instance))
        except (vbox_exc.VBoxException, exception.InstanceInvalidState) as exc:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Unable to attach volume to "
                              "instance %(instance)s: %(reason)s"),
                          {"instance": instance.name, "reason": exc})
                self.detach_volume(instance, connection_info)
    def test_get_available_attach_point(self, mock_get_controllers):
        mock_get_controllers.return_value = {
            mock.sentinel.controller: {
                (0, 0): {"path": mock.sentinel.path,
                         "uuid": mock.sentinel.uuid},
                (1, 0): {"path": None,
                         "uuid": None},
            }
        }

        attach_point = vhdutils.get_available_attach_point(
            self._instance, mock.sentinel.controller)

        self.assertEqual((1, 0), attach_point)
Example #3
0
    def test_get_available_attach_point(self, mock_get_controllers):
        mock_get_controllers.return_value = {
            mock.sentinel.controller: {
                (0, 0): {
                    "path": mock.sentinel.path,
                    "uuid": mock.sentinel.uuid
                },
                (1, 0): {
                    "path": None,
                    "uuid": None
                },
            }
        }

        attach_point = vhdutils.get_available_attach_point(
            self._instance, mock.sentinel.controller)

        self.assertEqual((1, 0), attach_point)