Initial tinycore support on compass-core.
1. Added an endpoint for adding machines. 2. Added user concept to machine model. Change-Id: I603296d30dbd7182678d98fd5f8f56503cbdc634
This commit is contained in:
parent
d8d369de24
commit
d3f203535a
@ -1582,6 +1582,22 @@ def list_machines():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/machines", methods=['POST'])
|
||||||
|
def add_machine():
|
||||||
|
"""add machine by tinycore.
|
||||||
|
|
||||||
|
supported fileds: [
|
||||||
|
'tag', 'location', 'ipmi_credentials',
|
||||||
|
'machine_attributes'
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
data = _get_request_data()
|
||||||
|
return utils.make_json_response(
|
||||||
|
200,
|
||||||
|
machine_api.add_machine(**data)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/machines/<int:machine_id>", methods=['GET'])
|
@app.route("/machines/<int:machine_id>", methods=['GET'])
|
||||||
@log_user_action
|
@log_user_action
|
||||||
@login_required
|
@login_required
|
||||||
@ -1605,7 +1621,8 @@ def update_machine(machine_id):
|
|||||||
"""update machine.
|
"""update machine.
|
||||||
|
|
||||||
Supported fields: [
|
Supported fields: [
|
||||||
'tag', 'location', 'ipmi_credentials'
|
'tag', 'location', 'ipmi_credentials',
|
||||||
|
'machine_attributes'
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
data = _get_request_data()
|
data = _get_request_data()
|
||||||
@ -1625,7 +1642,8 @@ def patch_machine(machine_id):
|
|||||||
"""patch machine.
|
"""patch machine.
|
||||||
|
|
||||||
Supported fields: [
|
Supported fields: [
|
||||||
'tag', 'location', 'ipmi_credentials'
|
'tag', 'location', 'ipmi_credentials',
|
||||||
|
'machine_attributes'
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
data = _get_request_data()
|
data = _get_request_data()
|
||||||
|
@ -27,16 +27,21 @@ from compass.utils import setting_wrapper as setting
|
|||||||
from compass.utils import util
|
from compass.utils import util
|
||||||
|
|
||||||
|
|
||||||
SUPPORTED_FIELDS = ['mac', 'tag', 'location']
|
MACHINE_PRIMARY_FILEDS = ['mac', 'owner_id']
|
||||||
|
SUPPORTED_FIELDS = [
|
||||||
|
'mac', 'tag', 'location',
|
||||||
|
'machine_attributes', 'owner_id']
|
||||||
IGNORE_FIELDS = ['id', 'created_at', 'updated_at']
|
IGNORE_FIELDS = ['id', 'created_at', 'updated_at']
|
||||||
UPDATED_FIELDS = ['ipmi_credentials', 'tag', 'location']
|
UPDATED_FIELDS = [
|
||||||
|
'ipmi_credentials', 'machine_attributes',
|
||||||
|
'tag', 'location']
|
||||||
PATCHED_FIELDS = [
|
PATCHED_FIELDS = [
|
||||||
'patched_ipmi_credentials', 'patched_tag',
|
'patched_ipmi_credentials', 'patched_tag',
|
||||||
'patched_location'
|
'patched_location'
|
||||||
]
|
]
|
||||||
RESP_FIELDS = [
|
RESP_FIELDS = [
|
||||||
'id', 'mac', 'ipmi_credentials', 'switches', 'switch_ip',
|
'id', 'mac', 'ipmi_credentials', 'switches', 'switch_ip',
|
||||||
'port', 'vlans',
|
'port', 'vlans', 'machine_attributes', 'owner_id',
|
||||||
'tag', 'location', 'created_at', 'updated_at'
|
'tag', 'location', 'created_at', 'updated_at'
|
||||||
]
|
]
|
||||||
RESP_DEPLOY_FIELDS = [
|
RESP_DEPLOY_FIELDS = [
|
||||||
@ -56,6 +61,39 @@ def _get_machine(machine_id, session=None, **kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.supported_filters(
|
||||||
|
MACHINE_PRIMARY_FILEDS,
|
||||||
|
optional_support_keys=SUPPORTED_FIELDS
|
||||||
|
)
|
||||||
|
@utils.input_validates(mac=utils.check_mac)
|
||||||
|
def _add_machine(mac, owner_id=None, session=None, **kwargs):
|
||||||
|
"""Add a machine."""
|
||||||
|
if isinstance(owner_id, (int, long)):
|
||||||
|
return utils.add_db_object(
|
||||||
|
session, models.Machine,
|
||||||
|
True,
|
||||||
|
mac,
|
||||||
|
owner_id=owner_id,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
raise exception.InvalidParameter(
|
||||||
|
'owner id %s type is not int compatible' % owner_id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@database.run_in_session()
|
||||||
|
@utils.wrap_to_dict(RESP_FIELDS)
|
||||||
|
def add_machine(
|
||||||
|
mac, owner_id=None, session=None, user=None, **kwargs
|
||||||
|
):
|
||||||
|
"""Add a machine."""
|
||||||
|
return _add_machine(
|
||||||
|
mac,
|
||||||
|
owner_id=owner_id,
|
||||||
|
session=session, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_machine_internal(machine_id, session=None, **kwargs):
|
def get_machine_internal(machine_id, session=None, **kwargs):
|
||||||
"""Helper function to other files under db/api."""
|
"""Helper function to other files under db/api."""
|
||||||
return _get_machine(machine_id, session=session, **kwargs)
|
return _get_machine(machine_id, session=session, **kwargs)
|
||||||
|
@ -1523,6 +1523,8 @@ class Machine(BASE, HelperMixin, TimestampMixin):
|
|||||||
ipmi_credentials = Column(JSONEncoded, default={})
|
ipmi_credentials = Column(JSONEncoded, default={})
|
||||||
tag = Column(JSONEncoded, default={})
|
tag = Column(JSONEncoded, default={})
|
||||||
location = Column(JSONEncoded, default={})
|
location = Column(JSONEncoded, default={})
|
||||||
|
owner_id = Column(Integer, ForeignKey('user.id'))
|
||||||
|
machine_attributes = Column(JSONEncoded, default={})
|
||||||
|
|
||||||
switch_machines = relationship(
|
switch_machines = relationship(
|
||||||
SwitchMachine,
|
SwitchMachine,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user