コード例 #1
0
 def test_node_list_limit(self):
     self.api = utils.FakeAPI(fake_responses_pagination)
     self.mgr = node.NodeManager(self.api)
     nodes = self.mgr.list(limit=1)
     expect = [('GET', '/v1/nodes/?limit=1', {}, None)]
     self.assertEqual(expect, self.api.calls)
     self.assertThat(nodes, HasLength(1))
コード例 #2
0
 def test_node_list_sort_dir(self):
     self.api = utils.FakeAPI(fake_responses_sorting)
     self.mgr = node.NodeManager(self.api)
     nodes = self.mgr.list(sort_dir='desc')
     expect = [('GET', '/v1/nodes/?sort_dir=desc', {}, None)]
     self.assertEqual(expect, self.api.calls)
     self.assertEqual(2, len(nodes))
コード例 #3
0
 def test_node_list_marker(self):
     self.api = utils.FakeAPI(fake_responses_pagination)
     self.mgr = node.NodeManager(self.api)
     nodes = self.mgr.list(marker=NODE1['uuid'])
     expect = [('GET', '/v1/nodes/?marker=%s' % NODE1['uuid'], {}, None)]
     self.assertEqual(expect, self.api.calls)
     self.assertThat(nodes, HasLength(1))
コード例 #4
0
    def __init__(self, endpoint=None, *args, **kwargs):
        """Initialize a new client for the Ironic v1 API."""
        if kwargs.get('os_ironic_api_version'):
            kwargs['api_version_select_state'] = "user"
        else:
            if not endpoint:
                raise exc.EndpointException(
                    _("Must provide 'endpoint' if os_ironic_api_version "
                      "isn't specified"))

            # If the user didn't specify a version, use a cached version if
            # one has been stored
            host, netport = http.get_server(endpoint)
            saved_version = filecache.retrieve_data(host=host, port=netport)
            if saved_version:
                kwargs['api_version_select_state'] = "cached"
                kwargs['os_ironic_api_version'] = saved_version
            else:
                kwargs['api_version_select_state'] = "default"
                kwargs['os_ironic_api_version'] = DEFAULT_VER

        self.http_client = http._construct_http_client(endpoint, *args,
                                                       **kwargs)

        self.chassis = chassis.ChassisManager(self.http_client)
        self.node = node.NodeManager(self.http_client)
        self.port = port.PortManager(self.http_client)
        self.volume_connector = volume_connector.VolumeConnectorManager(
            self.http_client)
        self.volume_target = volume_target.VolumeTargetManager(
            self.http_client)
        self.driver = driver.DriverManager(self.http_client)
        self.portgroup = portgroup.PortgroupManager(self.http_client)
コード例 #5
0
 def __init__(self, *args, **kwargs):
     """Initialize a new client for the Ironic v1 API."""
     self.http_client = http._construct_http_client(*args, **kwargs)
     self.chassis = chassis.ChassisManager(self.http_client)
     self.node = node.NodeManager(self.http_client)
     self.port = port.PortManager(self.http_client)
     self.driver = driver.DriverManager(self.http_client)
コード例 #6
0
 def test_node_list_pagination_no_limit(self):
     self.api = utils.FakeAPI(fake_responses_pagination)
     self.mgr = node.NodeManager(self.api)
     nodes = self.mgr.list(limit=0)
     expect = [('GET', '/v1/nodes', {}, None),
               ('GET', '/v1/nodes/?limit=1', {}, None)]
     self.assertEqual(expect, self.api.calls)
     self.assertEqual(2, len(nodes))
コード例 #7
0
    def __init__(self, endpoint_override=None, *args, **kwargs):
        """Initialize a new client for the Ironic v1 API."""
        allow_downgrade = kwargs.pop('allow_api_version_downgrade', False)
        if kwargs.get('os_ironic_api_version'):
            # TODO(TheJulia): We should sanity check os_ironic_api_version
            # against our maximum supported version, so the client fails
            # immediately upon an unsupported version being provided.
            # This logic should also likely live in common/http.py
            if allow_downgrade:
                if kwargs['os_ironic_api_version'] == 'latest':
                    raise ValueError(
                        "Invalid configuration defined. "
                        "The os_ironic_api_version can not be set "
                        "to 'latest' while allow_api_version_downgrade "
                        "is set.")
                # NOTE(dtantsur): here we allow the HTTP client to negotiate a
                # lower version if the requested is too high
                kwargs['api_version_select_state'] = "default"
            else:
                kwargs['api_version_select_state'] = "user"
        else:
            if endpoint_override:
                # If the user didn't specify a version, use a cached version if
                # one has been stored
                host, netport = http.get_server(endpoint_override)
                saved_version = filecache.retrieve_data(host=host,
                                                        port=netport)
                if saved_version:
                    kwargs['api_version_select_state'] = "cached"
                    kwargs['os_ironic_api_version'] = saved_version
                else:
                    kwargs['api_version_select_state'] = "default"
                    kwargs['os_ironic_api_version'] = DEFAULT_VER
            else:
                LOG.debug('Cannot use cached API version since endpoint '
                          'override is not provided. Will negotiate again.')
                kwargs['api_version_select_state'] = "default"
                kwargs['os_ironic_api_version'] = DEFAULT_VER

        if endpoint_override:
            kwargs['endpoint_override'] = endpoint_override
        self.http_client = http._construct_http_client(*args, **kwargs)

        self.chassis = chassis.ChassisManager(self.http_client)
        self.node = node.NodeManager(self.http_client)
        self.port = port.PortManager(self.http_client)
        self.volume_connector = volume_connector.VolumeConnectorManager(
            self.http_client)
        self.volume_target = volume_target.VolumeTargetManager(
            self.http_client)
        self.driver = driver.DriverManager(self.http_client)
        self.portgroup = portgroup.PortgroupManager(self.http_client)
        self.conductor = conductor.ConductorManager(self.http_client)
        self.events = events.EventManager(self.http_client)
        self.allocation = allocation.AllocationManager(self.http_client)
        self.deploy_template = deploy_template.DeployTemplateManager(
            self.http_client)
コード例 #8
0
 def test_node_port_list_marker(self):
     self.api = utils.FakeAPI(fake_responses_pagination)
     self.mgr = node.NodeManager(self.api)
     ports = self.mgr.list_ports(NODE1['uuid'], marker=PORT['uuid'])
     expect = [
         ('GET', '/v1/nodes/%s/ports?marker=%s' % (NODE1['uuid'],
                                                   PORT['uuid']), {}, None),
     ]
     self.assertEqual(expect, self.api.calls)
     self.assertThat(ports, HasLength(1))
コード例 #9
0
 def test_node_port_list_limit(self):
     self.api = utils.FakeAPI(fake_responses_pagination)
     self.mgr = node.NodeManager(self.api)
     ports = self.mgr.list_ports(NODE1['uuid'], limit=1)
     expect = [
         ('GET', '/v1/nodes/%s/ports?limit=1' % NODE1['uuid'], {}, None),
     ]
     self.assertEqual(expect, self.api.calls)
     self.assertThat(ports, HasLength(1))
     self.assertEqual(PORT['uuid'], ports[0].uuid)
     self.assertEqual(PORT['address'], ports[0].address)
コード例 #10
0
ファイル: client.py プロジェクト: sapcc/python-ironicclient
    def __init__(self, endpoint=None, endpoint_override=None, *args, **kwargs):
        """Initialize a new client for the Ironic v1 API."""
        allow_downgrade = kwargs.pop('allow_api_version_downgrade', False)
        if endpoint_override is None and endpoint is not None:
            LOG.warning('Passing "endpoint" parameter to Client constructor '
                        'is deprecated, and it will be removed in Stein '
                        'release. Please use "endpoint_override" instead.')
            endpoint_override = endpoint
        if kwargs.get('os_ironic_api_version'):
            # TODO(TheJulia): We should sanity check os_ironic_api_version
            # against our maximum suported version, so the client fails
            # immediately upon an unsupported version being provided.
            # This logic should also likely live in common/http.py
            if allow_downgrade:
                if kwargs['os_ironic_api_version'] == 'latest':
                    raise ValueError(
                        "Invalid configuration defined. "
                        "The os_ironic_api_version can not be set "
                        "to 'latest' while allow_api_version_downgrade "
                        "is set.")
                # NOTE(dtantsur): here we allow the HTTP client to negotiate a
                # lower version if the requested is too high
                kwargs['api_version_select_state'] = "default"
            else:
                kwargs['api_version_select_state'] = "user"
        else:
            if not endpoint_override:
                raise exc.EndpointException(
                    _("Must provide 'endpoint_override' if "
                      "'os_ironic_api_version' isn't specified"))

            # If the user didn't specify a version, use a cached version if
            # one has been stored
            host, netport = http.get_server(endpoint_override)
            saved_version = filecache.retrieve_data(host=host, port=netport)
            if saved_version:
                kwargs['api_version_select_state'] = "cached"
                kwargs['os_ironic_api_version'] = saved_version
            else:
                kwargs['api_version_select_state'] = "default"
                kwargs['os_ironic_api_version'] = DEFAULT_VER

        kwargs['endpoint_override'] = endpoint_override
        self.http_client = http._construct_http_client(*args, **kwargs)

        self.chassis = chassis.ChassisManager(self.http_client)
        self.node = node.NodeManager(self.http_client)
        self.port = port.PortManager(self.http_client)
        self.volume_connector = volume_connector.VolumeConnectorManager(
            self.http_client)
        self.volume_target = volume_target.VolumeTargetManager(
            self.http_client)
        self.driver = driver.DriverManager(self.http_client)
        self.portgroup = portgroup.PortgroupManager(self.http_client)
コード例 #11
0
 def test_node_port_list_sort_key(self):
     self.api = utils.FakeAPI(fake_responses_sorting)
     self.mgr = node.NodeManager(self.api)
     ports = self.mgr.list_ports(NODE1['uuid'], sort_key='updated_at')
     expect = [
         ('GET', '/v1/nodes/%s/ports?sort_key=updated_at' % NODE1['uuid'],
          {}, None),
     ]
     self.assertEqual(expect, self.api.calls)
     self.assertThat(ports, HasLength(1))
     self.assertEqual(PORT['uuid'], ports[0].uuid)
     self.assertEqual(PORT['address'], ports[0].address)
コード例 #12
0
 def __init__(self, *args, **kwargs):
     """Initialize a new client for the Ironic v1 API."""
     # set the default API version header string, if none specified
     if not kwargs.get('os_ironic_api_version'):
         kwargs['os_ironic_api_version'] = DEFAULT_VER
         kwargs['api_version_select_state'] = "default"
     else:
         kwargs['api_version_select_state'] = "user"
     self.http_client = http._construct_http_client(*args, **kwargs)
     self.chassis = chassis.ChassisManager(self.http_client)
     self.node = node.NodeManager(self.http_client)
     self.port = port.PortManager(self.http_client)
     self.driver = driver.DriverManager(self.http_client)
コード例 #13
0
ファイル: client.py プロジェクト: 571451370/devstack_mitaka
    def __init__(self, *args, **kwargs):
        """Initialize a new client for the Ironic v1 API."""
        if kwargs.get('os_ironic_api_version'):
            kwargs['api_version_select_state'] = "user"
        else:
            # If the user didn't specify a version, use a cached version if
            # one has been stored
            host, netport = http.get_server(args[0])
            saved_version = filecache.retrieve_data(host=host, port=netport)
            if saved_version:
                kwargs['api_version_select_state'] = "cached"
                kwargs['os_ironic_api_version'] = saved_version
            else:
                kwargs['api_version_select_state'] = "default"
                kwargs['os_ironic_api_version'] = DEFAULT_VER

        self.http_client = http._construct_http_client(*args, **kwargs)

        self.chassis = chassis.ChassisManager(self.http_client)
        self.node = node.NodeManager(self.http_client)
        self.port = port.PortManager(self.http_client)
        self.driver = driver.DriverManager(self.http_client)
コード例 #14
0
 def setUp(self):
     super(NodeManagerTest, self).setUp()
     self.api = utils.FakeAPI(fake_responses)
     self.mgr = node.NodeManager(self.api)
コード例 #15
0
def data(TEST):

    # BareMetalNode
    TEST.baremetalclient_nodes = test_data_utils.TestDataContainer()
    bm_node_1 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '1',
         'uuid': 'd0ace338-a702-426a-b344-394ce861e070',
         'ipmi_address': '1.1.1.1',
         'ipmi_username': '******',
         'ipmi_password': '******',
         'ip_address': '192.0.2.36',
         'instance_uuid': 'aa',
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': 'active',
         "pm_address": '1.1.1.1',
         "pm_user": '******',
         "interfaces": [{"address": "52:54:00:90:38:01"},
                        {"address": "52:54:00:90:38:02"}],
         })
    bm_node_2 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '2',
         'uuid': 'bd70e5e7-52e6-40d6-b862-c7f7ea1f262e',
         'instance_uuid': 'bb',
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': 'active',
         "pm_address": None,
         "pm_user": None,
         "interfaces": [{"address": "52:54:00:90:38:01"}],
         })
    bm_node_3 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '3',
         'uuid': '74981-2cfa-4e15-be96-3f0ec5635115',
         'instance_uuid': 'cc',
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': 'reboot',
         "pm_address": None,
         "pm_user": None,
         "interfaces": [{"address": "52:54:00:90:38:01"}],
         })
    bm_node_4 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '4',
         'uuid': 'f5c1df48-dcbe-4eb5-bd44-9eef2cb9139a',
         'instance_uuid': 'cc',
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': 'active',
         "pm_address": None,
         "pm_user": None,
         "interfaces": [{"address": "52:54:00:90:38:01"}],
         })
    bm_node_5 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '5',
         'uuid': 'c8998d40-2ff6-4233-8535-b44a825b20c3',
         'instance_uuid': 'dd',
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': 'error',
         "pm_address": None,
         "pm_user": None,
         "interfaces": [{"address": "52:54:00:90:38:01"}],
         })
    bm_node_6 = baremetal.BareMetalNode(
        baremetal.BareMetalNodeManager(None),
        {'id': '6',
         'uuid': 'cfd5a2cf-f21c-4044-a604-acb855478e44',
         'instance_uuid': None,
         "service_host": "undercloud",
         "cpus": 1,
         "memory_mb": 4096,
         "local_gb": 20,
         'task_state': None,
         "pm_address": None,
         "pm_user": None,
         "interfaces": [{"address": "52:54:00:90:38:01"}],
         })
    TEST.baremetalclient_nodes.add(
        bm_node_1, bm_node_2, bm_node_3, bm_node_4, bm_node_5, bm_node_6)

    # IronicNode
    TEST.ironicclient_nodes = test_data_utils.TestDataContainer()
    node_1 = node.Node(
        node.NodeManager(None),
        {'id': '1',
         'uuid': 'aa-11',
         'instance_uuid': 'aa',
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '1.1.1.1',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.2'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_2 = node.Node(
        node.NodeManager(None),
        {'id': '2',
         'uuid': 'bb-22',
         'instance_uuid': 'bb',
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '2.2.2.2',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.3'
         },
         'properties': {
             'cpus': '16',
             'memory_mb': '4096',
             'local_gb': '100',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_3 = node.Node(
        node.NodeManager(None),
        {'id': '3',
         'uuid': 'cc-33',
         'instance_uuid': 'cc',
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '3.3.3.3',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.4'
         },
         'properties': {
             'cpus': '32',
             'memory_mb': '8192',
             'local_gb': '1',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'rebooting',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_4 = node.Node(
        node.NodeManager(None),
        {'id': '4',
         'uuid': 'cc-44',
         'instance_uuid': 'cc',
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '4.4.4.4',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.5'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_5 = node.Node(
        node.NodeManager(None),
        {'id': '5',
         'uuid': 'dd-55',
         'instance_uuid': 'dd',
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '5.5.5.5',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.6'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'error',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_6 = node.Node(
        node.NodeManager(None),
        {'id': '6',
         'uuid': 'ff-66',
         'instance_uuid': None,
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '5.5.5.5',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.6'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': None,
         'newly_discovered': None,
         })
    node_7 = node.Node(
        node.NodeManager(None),
        {'id': '7',
         'uuid': 'gg-77',
         'instance_uuid': None,
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '7.7.7.7',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.7'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': True,
         'newly_discovered': None,
         })
    node_8 = node.Node(
        node.NodeManager(None),
        {'id': '8',
         'uuid': 'hh-88',
         'instance_uuid': None,
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '8.8.8.8',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.8'
         },
         'properties': {
             'cpus': '8',
             'memory_mb': '4096',
             'local_gb': '10',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': True,
         'newly_discovered': True,
         })
    node_9 = node.Node(
        node.NodeManager(None),
        {'id': '9',
         'uuid': 'ii-99',
         'instance_uuid': None,
         'driver': 'pxe_ipmitool',
         'driver_info': {
             'ipmi_address': '9.9.9.9',
             'ipmi_username': '******',
             'ipmi_password': '******',
             'ip_address': '1.2.2.9'
         },
         'properties': {
             'cpus': '16',
             'memory_mb': '8192',
             'local_gb': '1000',
             'cpu_arch': 'x86_64',
         },
         'power_state': 'on',
         'maintenance': True,
         'newly_discovered': True,
         })
    TEST.ironicclient_nodes.add(node_1, node_2, node_3, node_4, node_5, node_6,
                                node_7, node_8, node_9)

    # Ports
    TEST.ironicclient_ports = test_data_utils.TestDataContainer()
    port_1 = port.Port(
        port.PortManager(None),
        {'id': '1-port-id',
         'type': 'port',
         'address': 'aa:aa:aa:aa:aa:aa'})
    port_2 = port.Port(
        port.PortManager(None),
        {'id': '2-port-id',
         'type': 'port',
         'address': 'bb:bb:bb:bb:bb:bb'})
    port_3 = port.Port(
        port.PortManager(None),
        {'id': '3-port-id',
         'type': 'port',
         'address': 'cc:cc:cc:cc:cc:cc'})
    port_4 = port.Port(
        port.PortManager(None),
        {'id': '4-port-id',
         'type': 'port',
         'address': 'dd:dd:dd:dd:dd:dd'})
    TEST.ironicclient_ports.add(port_1, port_2, port_3, port_4)