def main(): """By default, this script will only cleanup unused cached images. Options: --all_cached - Destroy all cached images instead of just unused cached images. --dry_run - Don't actually destroy the VDIs. """ config.parse_args(sys.argv) utils.monkey_patch() _session = session.XenAPISession(CONF.xenserver.connection_url, CONF.xenserver.connection_username, CONF.xenserver.connection_password) sr_ref = vm_utils.safe_find_sr(_session) destroyed = vm_utils.destroy_cached_images(_session, sr_ref, all_cached=CONF.all_cached, dry_run=CONF.dry_run) if '--verbose' in sys.argv: print('\n'.join(destroyed)) print("Destroyed %d cached VDIs" % len(destroyed))
def test_session_login_with_timeout(self, mock_verify, mock_version, create_session, mock_timeout): self.flags(connection_concurrent=2, group='xenserver') sess = mock.Mock() create_session.return_value = sess mock_version.return_value = ('version', 'brand') session.XenAPISession('http://someserver', 'username', 'password') self.assertEqual(2, sess.login_with_password.call_count) self.assertEqual(2, mock_timeout.call_count)
def test_session_passes_version(self, mock_verify, mock_version, create_session): sess = mock.Mock() create_session.return_value = sess mock_version.return_value = ('version', 'brand') session.XenAPISession('url', 'username', 'password') expected_version = '%s %s %s' % (version.vendor_string(), version.product_string(), version.version_string_with_package()) sess.login_with_password.assert_called_with('username', 'password', expected_version, 'OpenStack')
def test_relax_xsm_sr_check_true(self, mock_create_session, mock_verify_plugin_version, mock_get_software_version, mock_call_plugin): sess = mock.Mock() mock_create_session.return_value = sess mock_get_software_version.return_value = {'product_version': '6.5.0', 'product_brand': 'XenServer', 'platform_version': '1.9.0'} # mark relax-xsm-sr-check=True in /etc/xapi.conf mock_call_plugin.return_value = "True" xenapi_sess = session.XenAPISession( 'http://someserver', 'username', 'password') self.assertTrue(xenapi_sess.is_xsm_sr_check_relaxed())
def test_session_raises_exception(self, mock_ref, mock_uuid, mock_verify, mock_version, create_session, mock_timeout): import XenAPI self.flags(connection_concurrent=2, group='xenserver') sess = mock.Mock() create_session.return_value = sess # First login fails, second login in except block succeeds, # third login for the pool succeeds sess.login_with_password.side_effect = [ XenAPI.Failure(['HOST_IS_SLAVE', 'master']), None, None ] mock_version.return_value = ('version', 'brand') session.XenAPISession('http://slave', 'username', 'password') self.assertEqual(3, sess.login_with_password.call_count) self.assertEqual(3, mock_timeout.call_count)
def main(): config.parse_args(sys.argv) utils.monkey_patch() _session = session.XenAPISession(CONF.xenserver.connection_url, CONF.xenserver.connection_username, CONF.xenserver.connection_password) sr_ref = vm_utils.safe_find_sr(_session) destroyed = vm_utils.destroy_cached_images( _session, sr_ref, all_cached=CONF.all_cached, dry_run=CONF.dry_run) if '--verbose' in sys.argv: print '\n'.join(destroyed) print "Destroyed %d cached VDIs" % len(destroyed)
def __init__(self, virtapi, read_only=False): super(XenAPIDriver, self).__init__(virtapi) url = CONF.xenserver.connection_url username = CONF.xenserver.connection_username password = CONF.xenserver.connection_password if not url or password is None: raise Exception(_('Must specify connection_url, ' 'connection_username (optionally), and ' 'connection_password to use ' 'compute_driver=xenapi.XenAPIDriver')) self._session = session.XenAPISession(url, username, password) self._volumeops = volumeops.VolumeOps(self._session) self._host_state = None self._host = host.Host(self._session, self.virtapi) self._vmops = vmops.VMOps(self._session, self.virtapi) self._initiator = None self._hypervisor_hostname = None self._pool = pool.ResourcePool(self._session, self.virtapi)
def _setup_mock_vmops(self, product_brand=None, product_version=None): stubs.stubout_session(self.stubs, xenapi_fake.SessionBase) self._session = xenapi_session.XenAPISession('test_url', 'root', 'test_pass') self.vmops = vmops.VMOps(self._session, fake.FakeVirtAPI())