De-client-ify fixed method get_nic_by_mac

Additionally removed traces of ironic exceptions
being parsed in operatorcloud.py and removed legacy
tasks related to port lookups.

Also remove patch machine task wrapper as that appears
to have been migrated previously.

Change-Id: Iee9e15f44b8375fdcf00ddba2b44afe217faf478
This commit is contained in:
Julia Kreger 2017-11-29 15:54:50 -05:00
parent bd38f39243
commit 6f5bfd16a1
2 changed files with 18 additions and 51 deletions

View File

@ -1,37 +0,0 @@
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# 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 shade import task_manager
class MachinePortGet(task_manager.Task):
def main(self, client):
return client.ironic_client.port.get(**self.args)
class MachinePortGetByAddress(task_manager.Task):
def main(self, client):
return client.ironic_client.port.get_by_address(**self.args)
class MachineNodeUpdate(task_manager.Task):
def main(self, client):
return client.ironic_client.node.update(**self.args)
class MachineNodeValidate(task_manager.Task):
def main(self, client):
return client.ironic_client.node.validate(**self.args)

View File

@ -15,11 +15,8 @@ import iso8601
import jsonpatch import jsonpatch
import munch import munch
from ironicclient import exceptions as ironic_exceptions
from shade.exc import * # noqa from shade.exc import * # noqa
from shade import openstackcloud from shade import openstackcloud
from shade import _tasks
from shade import _utils from shade import _utils
@ -54,13 +51,14 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
error_message=msg) error_message=msg)
def get_nic_by_mac(self, mac): def get_nic_by_mac(self, mac):
# TODO(TheJulia): Query /ports?address=mac when converting
try: try:
return self._normalize_machine( url = '/ports/detail?address=%s' % mac
self.manager.submit_task( data = self._baremetal_client.get(url)
_tasks.MachinePortGetByAddress(address=mac))) if len(data['ports']) == 1:
except ironic_exceptions.ClientException: return data['ports'][0]
return None except Exception:
pass
return None
def list_machines(self): def list_machines(self):
msg = "Error fetching machine node list" msg = "Error fetching machine node list"
@ -568,14 +566,20 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
) )
def validate_node(self, uuid): def validate_node(self, uuid):
with _utils.shade_exceptions(): # TODO(TheJulia): There are soooooo many other interfaces
ifaces = self.manager.submit_task( # that we can support validating, while these are essential,
_tasks.MachineNodeValidate(node_uuid=uuid)) # we should support more.
# TODO(TheJulia): Add a doc string :(
msg = ("Failed to query the API for validation status of "
"node {node_id}").format(node_id=uuid)
url = '/nodes/{node_id}/validate'.format(node_id=uuid)
ifaces = self._baremetal_client.get(url, error_message=msg)
if not ifaces.deploy or not ifaces.power: if not ifaces['deploy'] or not ifaces['power']:
raise OpenStackCloudException( raise OpenStackCloudException(
"ironic node %s failed to validate. " "ironic node %s failed to validate. "
"(deploy: %s, power: %s)" % (ifaces.deploy, ifaces.power)) "(deploy: %s, power: %s)" % (ifaces['deploy'],
ifaces['power']))
def node_set_provision_state(self, def node_set_provision_state(self,
name_or_id, name_or_id,