2014-07-17 71 views
0

我是新來的Python和OpenStack的,所以請不要失去冷靜:)AttributeError的:對象類型「ManagerWithFind」有沒有屬性「客戶」

在這裏,我試圖實例BareMetalNodeManager類對象(從np_orchestration。 PY)。

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作爲投影傳遞= None –

相關問題