def setUp(self): super(CellsExtensionTests, self).setUp() extensions = [ extension.Extension(cells.__name__.split(".")[-1], cells), ] self.cs = fakes.FakeClient(extensions=extensions)
def setUp(self): super(ServerExternalEventsTestCase, self).setUp() extensions = [ extension.Extension( ext_events.__name__.split(".")[-1], ext_events), ] self.cs = fakes.FakeClient(extensions=extensions)
def setUp(self): super(MigrationsTest, self).setUp() self.extensions = [ extension.Extension( migrations.__name__.split(".")[-1], migrations), ] self.cs = fakes.FakeClient(extensions=self.extensions)
def get_cls(tname, auth_url, oscfg): ksc, err = os_try_access(oscfg.username, oscfg.password, tname, oscfg.keystone_host, const.REQUEST_TIMEOUT, oscfg.region, auth_url=auth_url, log=log) if not ksc: log.error("Cloudn't establish connection to OpenStack, error: %s", err) sys.exit(1) eptype = 'internal' if oscfg.use_internal_endpoints else 'public' ckwopts = { 'connect_retries': const.CONNECT_RETRIES, 'region_name': oscfg.region, 'interface': eptype } neuc = nnclient.Client('2', session=ksc.session, retries=const.API_RETRIES, **ckwopts) extns = [extension.Extension('list_extensions', list_extensions)] novc = nvclient.Client('2.15', session=ksc.session, extensions=extns, **ckwopts) return ksc, neuc, novc
def discover_extensions(*args, **kwargs): """Returns the list of extensions, which can be discovered by python path and by entry-point 'novaclient.extension'. """ chain = itertools.chain(_discover_via_python_path(), _discover_via_entry_points()) return [ext.Extension(name, module) for name, module in chain]
def setUp(self): super(BaremetalExtensionTest, self).setUp() extensions = [ extension.Extension(baremetal.__name__.split(".")[-1], baremetal), ] self.cs = fakes.FakeClient(api_versions.APIVersion("2.0"), extensions=extensions)
def setUp(self): super(InstanceActionExtensionTests, self).setUp() extensions = [ extension.Extension( instance_action.__name__.split(".")[-1], instance_action), ] self.cs = fakes.FakeClient(extensions=extensions)
def make_client(instance): """Returns a compute service client.""" # Defer client imports until we actually need them from novaclient import client as nova_client from novaclient import extension try: from novaclient.v2.contrib import list_extensions except ImportError: from novaclient.v1_1.contrib import list_extensions compute_client = nova_client.get_client_class( instance._api_version[API_NAME], ) LOG.debug('Instantiating compute client: %s', compute_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] client = compute_client( session=instance.session, extensions=extensions, http_log_debug=http_log_debug, timings=instance.timing, region_name=instance._region_name, ) return client
def setUp(self): super(AssistedVolumeSnapshotsTestCase, self).setUp() extensions = [ extension.Extension( assisted_snaps.__name__.split(".")[-1], assisted_snaps), ] self.cs = fakes.FakeClient(extensions=extensions)
def setUp(self): super(ListExtensionsTests, self).setUp() extensions = [ extension.Extension(list_extensions.__name__.split(".")[-1], list_extensions), ] self.cs = fakes.FakeClient(extensions=extensions)
def setUp(self): super(TenantNetworkExtensionTests, self).setUp() extensions = [ extension.Extension(tenant_networks.__name__.split(".")[-1], tenant_networks), ] self.cs = fakes.FakeClient(extensions=extensions)
def discover_extensions(version): extensions = [] for name, module in itertools.chain(_discover_via_python_path(), _discover_via_contrib_path(version), _discover_via_entry_points()): extension = ext.Extension(name, module) extensions.append(extension) return extensions
def __init__(self, version, username, password, tenant_name, auth_url): if migrations: extensions = [extension.Extension('migrations', migrations)] else: extensions = None self.nova = nova_client.Client(version, username, password, tenant_name, auth_url, extensions=extensions)
def discover_extensions(version): if not isinstance(version, api_versions.APIVersion): version = api_versions.get_api_version(version) extensions = [] for name, module in itertools.chain(_discover_via_python_path(), _discover_via_contrib_path(version), _discover_via_entry_points()): extension = ext.Extension(name, module) extensions.append(extension) return extensions
def discover_extensions(*args, **kwargs): """Returns the list of extensions, which can be discovered by python path and by entry-point 'novaclient.extension'. """ # TODO(mriedem): Remove support for 'only_contrib' in Queens. if 'only_contrib' in kwargs and kwargs['only_contrib']: warnings.warn(_('Discovering extensions only by contrib path is no ' 'longer supported since all contrib extensions ' 'have either been made required or removed. The ' 'only_contrib argument is deprecated and will be ' 'removed in a future release.')) return [] chain = itertools.chain(_discover_via_python_path(), _discover_via_entry_points()) return [ext.Extension(name, module) for name, module in chain]
def discover_extensions(version, only_contrib=False): """Returns the list of extensions, which can be discovered by python path, contrib path and by entry-point 'novaclient.extension'. :param version: api version :type version: str or novaclient.api_versions.APIVersion :param only_contrib: search only in contrib directory or not :type only_contrib: bool """ if not isinstance(version, api_versions.APIVersion): version = api_versions.get_api_version(version) if only_contrib: chain = _discover_via_contrib_path(version) else: chain = itertools.chain(_discover_via_python_path(), _discover_via_contrib_path(version), _discover_via_entry_points()) return [ext.Extension(name, module) for name, module in chain]
def make_client(instance): """Returns a compute service client.""" compute_client = utils.get_client_class(API_NAME, instance._api_version[API_NAME], API_VERSIONS) LOG.debug('Instantiating compute client: %s', compute_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] client = compute_client( session=instance.session, extensions=extensions, http_log_debug=http_log_debug, timings=instance.timing, ) return client
def make_client(instance): """Returns a compute service client.""" compute_client = utils.get_client_class( API_NAME, instance._api_version[API_NAME], API_VERSIONS) LOG.debug('Instantiating compute client: %s', compute_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] client = compute_client( username=instance._username, api_key=instance._password, project_id=instance._project_name, auth_url=instance._auth_url, cacert=instance._cacert, insecure=instance._insecure, region_name=instance._region_name, # FIXME(dhellmann): get endpoint_type from option? endpoint_type='publicURL', extensions=extensions, service_type=API_NAME, # FIXME(dhellmann): what is service_name? service_name='', http_log_debug=http_log_debug, timings=instance.timing, ) # Populate the Nova client to skip another auth query to Identity if instance._url: # token flow client.client.management_url = instance._url else: # password flow client.client.management_url = instance.get_endpoint_for_service_type( API_NAME) client.client.service_catalog = instance._service_catalog client.client.auth_token = instance._token return client
def GetOpenStackClient(): creds = get_nova_creds() extensions = [ extension.Extension( openclcontexts.__name__.split(".")[-1], openclcontexts), extension.Extension( opencldevices.__name__.split(".")[-1], opencldevices), extension.Extension( openclprograms.__name__.split(".")[-1], openclprograms), extension.Extension( openclbuffers.__name__.split(".")[-1], openclbuffers), extension.Extension( openclkernels.__name__.split(".")[-1], openclkernels), extension.Extension( openclqueues.__name__.split(".")[-1], openclqueues), ] return client.Client(http_log_debug=True, extensions=extensions, **creds)
cfg.StrOpt('nova_ca_certificates_file', default=None, help='Location of ca certificates file to use for nova client ' 'requests.'), cfg.BoolOpt('nova_api_insecure', default=False, help='Allow to perform insecure SSL requests to nova'), ] CONF = cfg.CONF CONF.register_opts(nova_opts) LOG = logging.getLogger(__name__) nova_extensions = (assisted_volume_snapshots, extension.Extension('list_extensions', list_extensions)) def novaclient(context, admin_endpoint=False, privileged_user=False, timeout=None): """Returns a Nova client @param admin_endpoint: If True, use the admin endpoint template from configuration ('nova_endpoint_admin_template' and 'nova_catalog_info') @param privileged_user: If True, use the account from configuration (requires 'os_privileged_user_name', 'os_privileged_user_password' and 'os_privileged_user_tenant' to be set) @param timeout: Number of seconds to wait for an answer before raising a Timeout exception (None to disable)
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.tests import utils from novaclient.tests.v1_1.contrib import fakes from novaclient.v1_1.contrib import baremetal extensions = [ extension.Extension(baremetal.__name__.split(".")[-1], baremetal), ] cs = fakes.FakeClient(extensions=extensions) class BaremetalExtensionTest(utils.TestCase): def test_list_nodes(self): nl = cs.baremetal.list() cs.assert_called('GET', '/os-baremetal-nodes') for n in nl: self.assertIsInstance(n, baremetal.BareMetalNode) def test_get_node(self): n = cs.baremetal.get(1) cs.assert_called('GET', '/os-baremetal-nodes/1')
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.tests.unit import utils from novaclient.tests.unit.v2.contrib import fakes from novaclient.v2.contrib import cells extensions = [ extension.Extension(cells.__name__.split(".")[-1], cells), ] cs = fakes.FakeClient(extensions=extensions) class CellsExtensionTests(utils.TestCase): def test_get_cells(self): cell_name = 'child_cell' cs.cells.get(cell_name) cs.assert_called('GET', '/os-cells/%s' % cell_name) def test_get_capacities_for_a_given_cell(self): cell_name = 'child_cell' cs.cells.capacities(cell_name) cs.assert_called('GET', '/os-cells/%s/capacities' % cell_name)
from novaclient import extension from novaclient.v1_1.contrib import list_extensions from novaclient.tests import utils from novaclient.tests.v1_1 import fakes extensions = [ extension.Extension( list_extensions.__name__.split(".")[-1], list_extensions), ] cs = fakes.FakeClient(extensions=extensions) class ListExtensionsTests(utils.TestCase): def test_list_extensions(self): all_exts = cs.list_extensions.show_all() cs.assert_called('GET', '/extensions') self.assertTrue(len(all_exts) > 0) for r in all_exts: self.assertTrue(len(r.summary) > 0)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ External event triggering for servers, not to be used by users. """ from novaclient import extension from novaclient.tests import utils from novaclient.tests.v1_1.contrib import fakes from novaclient.v1_1.contrib import server_external_events as ext_events extensions = [ extension.Extension(ext_events.__name__.split(".")[-1], ext_events), ] cs = fakes.FakeClient(extensions=extensions) class ServerExternalEventsTestCase(utils.TestCase): def test_external_event(self): events = [{ 'server_uuid': 'fake-uuid1', 'name': 'test-event', 'status': 'completed', 'tag': 'tag' }, { 'server_uuid': 'fake-uuid2', 'name': 'test-event', 'status': 'completed',
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.v1_1.contrib import openclqueues from novaclient.tests.v1_1.contrib import fakes from novaclient.tests import utils extensions = [ extension.Extension(openclqueues.__name__.split(".")[-1], openclqueues), ] cs = fakes.FakeClient(extensions=extensions) class OpenclqueuesinterfaceTest(object): def test_list_queues(self): ocs = cs.openclqueues.list() cs.assert_called('GET', '/os-openclqueues') print(ocs) def test_queue_properties(self): queue_id = 0 ocs = cs.openclqueues.show(queue_id) cs.assert_called('GET', '/os-openclqueues/%d' % queue_id)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.v1_1.contrib import tenant_networks from novaclient.tests import utils from novaclient.tests.v1_1.contrib import fakes extensions = [ extension.Extension( tenant_networks.__name__.split(".")[-1], tenant_networks), ] cs = fakes.FakeClient(extensions=extensions) class TenantNetworkExtensionTests(utils.TestCase): def test_list_tenant_networks(self): nets = cs.tenant_networks.list() cs.assert_called('GET', '/os-tenant-networks') self.assertTrue(len(nets) > 0) def test_get_tenant_network(self): cs.tenant_networks.get(1) cs.assert_called('GET', '/os-tenant-networks/1') def test_create_tenant_networks(self):
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.v1_1.contrib import opencldevices from novaclient.tests.v1_1.contrib import fakes from novaclient.tests import utils extensions = [ extension.Extension(opencldevices.__name__.split(".")[-1], opencldevices), ] cs = fakes.FakeClient(extensions=extensions) class OpencldevicesinterfaceTest(object): def test_list_devices(self): ocs = cs.opencldevices.list() cs.assert_called('GET', '/os-opencldevices') print(ocs) def test_device_properties(self): device_id = 0 ocs = cs.opencldevices.show(device_id) cs.assert_called('GET', '/os-opencldevices/%d' % device_id)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from novaclient import extension from novaclient.tests import utils from novaclient.tests.v1_1 import fakes from novaclient.v1_1.contrib import migrations extensions = [ extension.Extension(migrations.__name__.split(".")[-1], migrations), ] cs = fakes.FakeClient(extensions=extensions) class MigrationsTest(utils.TestCase): def test_list_migrations(self): ml = cs.migrations.list() cs.assert_called('GET', '/os-migrations') for m in ml: self.assertTrue(isinstance(m, migrations.Migration)) def test_list_migrations_with_filters(self): ml = cs.migrations.list('host1', 'finished', 'child1') cs.assert_called(
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Assisted volume snapshots - to be used by Cinder and not end users. """ from novaclient import extension from novaclient.tests.unit import utils from novaclient.tests.unit.v1_1.contrib import fakes from novaclient.v1_1.contrib import assisted_volume_snapshots as assisted_snaps extensions = [ extension.Extension( assisted_snaps.__name__.split(".")[-1], assisted_snaps), ] cs = fakes.FakeClient(extensions=extensions) class AssistedVolumeSnapshotsTestCase(utils.TestCase): def test_create_snap(self): cs.assisted_volume_snapshots.create('1', {}) cs.assert_called('POST', '/os-assisted-volume-snapshots') def test_delete_snap(self): cs.assisted_volume_snapshots.delete('x', {}) cs.assert_called('DELETE', '/os-assisted-volume-snapshots/x?delete_info={}')
from novaclient.v1_1 import client from novaclient.v1_1 import services from novaclient import utils from novaclient.v1_1.contrib import list_extensions from novaclient.v1_1.contrib import openclcontexts from novaclient.v1_1.contrib import opencldevices from novaclient.v1_1.contrib import openclprograms from novaclient.v1_1.contrib import openclbuffers from novaclient.v1_1.contrib import openclkernels from novaclient.v1_1.contrib import openclqueues from credentials import get_nova_creds creds = get_nova_creds() extensions = [ extension.Extension( openclcontexts.__name__.split(".")[-1], openclcontexts), extension.Extension(opencldevices.__name__.split(".")[-1], opencldevices), extension.Extension( openclprograms.__name__.split(".")[-1], openclprograms), extension.Extension(openclbuffers.__name__.split(".")[-1], openclbuffers), extension.Extension(openclkernels.__name__.split(".")[-1], openclkernels), extension.Extension(openclqueues.__name__.split(".")[-1], openclqueues), ] cl = client.Client(http_log_debug=True, extensions=extensions, **creds) print "Create a Context: " devices = [ 0, ] properties = [] context, retVal = cl.openclcontexts.create(devices, properties)