2014-07-17 4 views
0

Я новичок в Python и OpenStack поэтому, пожалуйста, не теряйте круто :)AttributeError: тип объекта «ManagerWithFind» не имеет атрибут «клиент»

Здесь я пытаюсь создать экземпляр BareMetalNodeManager объект класса (от np_orchestration. ру).

np_orchestration.py

from baremetal import BareMetalNodeManager 
from novaclient import base 

class np_orchestration: 
    def provisionNodes(self): 
     obj = BareMetalNodeManager(base.ManagerWithFind); 
     var =  obj.create(self,"192.168.XXX.XXX",1,514,1,"00:0C:29:XX:XX:XX","192.168.XXX.XXX","XXXX","XXXX") 
     print var 

obj = np_orchestration() 
obj.provisionNodes() 

Этот класс (расположен в baremetal.py) требует base.ManagerWithFind в качестве параметра (который является абстрактным классом)

baremetal.py

class BareMetalNodeManager(base.ManagerWithFind): 
""" 
Manage :class:`BareMetalNode` resources. 
""" 
resource_class = BareMetalNode 

def create(self, 
      service_host, 
      cpus, 
      memory_mb, 
      local_gb, 
      prov_mac_address, 
      pm_address=None, 
      pm_user=None, 
      pm_password=None, 
      terminal_port=None): 
    """ 
    Create a baremetal node. 

    :param service_host: Name of controlling compute host 
    :param cpus: Number of CPUs in the node 
    :param memory_mb: Megabytes of RAM in the node 
    :param local_gb: Gigabytes of local storage in the node 
    :param pm_address: Power management IP for the node 
    :param pm_user: Username for the node's power management 
    :param pm_password: Password for the node's power management 
    :param prov_mac_address: MAC address to provision the node 
    :param terminal_port: ShellInABox port 
    :rtype: :class:`BareMetalNode` 
    """ 
    body = {'node': {'service_host': service_host, 
        'cpus': cpus, 
        'memory_mb': memory_mb, 
        'local_gb': local_gb, 
        'pm_address': pm_address, 
        'pm_user': pm_user, 
        'pm_password': pm_password, 
        'prov_mac_address': prov_mac_address, 
        'terminal_port': terminal_port}} 

    return self._create('/os-baremetal-nodes', body, 'node') 

При попытке сделать следующее:

[email protected]:/projects/kenobi$ python np_orchestration.py 
Traceback (most recent call last): 
File "np_orchestration.py", line 15, in <module> 
obj.provisionNodes() 
File "np_orchestration.py", line 11, in provisionNodes 
var = obj.create(self,"192.168.42.134",1,514,1,"00:0C:29:CF:E6:D9","192.168.42.225","admin","abc") 
File "/projects/kenobi/baremetal.py", line 82, in create 
return self._create('/os-baremetal-nodes', body, 'node') 
File "/opt/stack/python-novaclient/novaclient/base.py", line 100, in _create 
_resp, body = self.api.client.post(url, body=body) 
AttributeError: type object 'ManagerWithFind' has no attribute 'client' 
[email protected]:/projects/kenobi$ 

полная версия baremetal.py можно найти здесь: https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/contrib/baremetal.py

ответ

1
import json 
from baremetal import BareMetalNodeManager 
from novaclient import base, client 
import os 

config_file = open('config.json') 
config_data = json.load(config_file) 

class np_orchestration: 

    def __init__(self): 
     self.os_auth_url = config_data["config"]["OS_AUTH_URL"] 
     self.os_username = config_data["config"]["OS_USER"] 
     self.os_password = config_data["config"]["OS_PASSWORD"] 
     self.os_tenant_name = config_data["config"]["OS_TENANT_NAME"] 
     self.os_tenant_id = config_data["config"]["OS_TENANT_ID"] 
     self.client = client._construct_http_client(self.os_username, self.os_password, project_id=None, 
          auth_url= self.os_auth_url, endpoint_type='publicURL', 
          service_type='compute', 
          auth_system='keystone', auth_plugin=None, 
          auth_token=None, cacert=None, tenant_id= self.os_tenant_id) 

    def provisionNodes(self): 
     obj = BareMetalNodeManager(self); 
     var = obj.create(self,"192.168.XXX.XXX",1,514,1,"00:0C:29:XX:XX:XX","192.168.XXX.XXX","XXXX","XXXX") 
     print var 

obj = np_orchestration() 
obj.provisionNodes() 
+0

Спасибо. Для дальнейшего использования новейший novaclient ожидает client.HTTPClient вместо _construct_http_client(), а также для project_id = None для передачи как projectid = None –

 Смежные вопросы

  • Нет связанных вопросов^_^