我是python和openstack的新手,所以请不要失去你的冷静:)
这里我试图实例化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')
我尝试这样做时出现以下错误:
farooqui@ubuntu:/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'
farooqui@ubuntu:/projects/kenobi$
完整版的baremetal.py可以在这里找到: https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/contrib/baremetal.py
答案 0 :(得分: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()