From f89ef9a9ee968c778af3444c7f9d2a39489fcf2b Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Thu, 11 Oct 2018 11:05:02 +0800 Subject: Manage host power from cobbler JIRA: COMPASS-616 1. Use fence_ipmilan to control power of baremetal servers. Add fence_libvirt to control power of virtual servers. 2. Use power_manage field instead of ipmi field 3. Add power_type to specify machine's power manage tool 4. Store power manage information in db and update to cobbler 5. Manage power from cobbler for both virtual and baremetal machines Change-Id: Ic36ae640dc0aa1703566b5b0b549880a71be36e4 Signed-off-by: Harry Huang --- compass-deck/db/api/cluster.py | 6 +++--- compass-deck/db/api/machine.py | 24 ++++++++++++------------ compass-deck/db/api/switch.py | 22 +++++++++++----------- compass-deck/db/api/utils.py | 35 +++++++++++++++++------------------ 4 files changed, 43 insertions(+), 44 deletions(-) (limited to 'compass-deck/db/api') diff --git a/compass-deck/db/api/cluster.py b/compass-deck/db/api/cluster.py index 9a0b8f0..82bcaab 100644 --- a/compass-deck/db/api/cluster.py +++ b/compass-deck/db/api/cluster.py @@ -48,9 +48,9 @@ RESP_CLUSTERHOST_FIELDS = [ 'cluster_id', 'clustername', 'location', 'tag', 'networks', 'mac', 'switch_ip', 'port', 'switches', 'os_installed', 'distributed_system_installed', - 'os_name', 'os_id', 'ip', - 'reinstall_os', 'reinstall_distributed_system', - 'owner', 'cluster_id', 'ipmi_credentials', + 'os_name', 'os_id', 'ip', 'reinstall_os', + 'reinstall_distributed_system', 'owner', 'cluster_id', + 'power_type', 'power_manage', 'created_at', 'updated_at', 'patched_roles' ] diff --git a/compass-deck/db/api/machine.py b/compass-deck/db/api/machine.py index 7991ada..11d19e6 100644 --- a/compass-deck/db/api/machine.py +++ b/compass-deck/db/api/machine.py @@ -29,20 +29,20 @@ from compass.utils import util MACHINE_PRIMARY_FILEDS = ['mac', 'owner_id'] SUPPORTED_FIELDS = [ - 'mac', 'tag', 'location', 'ipmi_credentials', - 'machine_attributes', 'owner_id'] + 'mac', 'tag', 'location', 'power_manage', + 'machine_attributes', 'owner_id', 'power_type'] IGNORE_FIELDS = ['id', 'created_at', 'updated_at'] UPDATED_FIELDS = [ - 'ipmi_credentials', 'machine_attributes', - 'tag', 'location'] + 'mac', 'tag', 'location', 'power_manage', + 'machine_attributes', 'power_type'] PATCHED_FIELDS = [ - 'patched_ipmi_credentials', 'patched_tag', + 'patched_power_manage', 'patched_tag', 'patched_location' ] RESP_FIELDS = [ - 'id', 'mac', 'ipmi_credentials', 'switches', 'switch_ip', + 'id', 'mac', 'power_manage', 'switches', 'switch_ip', 'port', 'vlans', 'machine_attributes', 'owner_id', - 'tag', 'location', 'created_at', 'updated_at' + 'tag', 'location', 'power_type', 'created_at', 'updated_at' ] RESP_DEPLOY_FIELDS = [ 'status', 'machine' @@ -149,7 +149,7 @@ def _update_machine(machine_id, session=None, **kwargs): optional_support_keys=UPDATED_FIELDS, ignore_support_keys=IGNORE_FIELDS ) -@utils.input_validates(ipmi_credentials=utils.check_ipmi_credentials) +@utils.input_validates(power_manage=utils.check_power_manage) @database.run_in_session() @user_api.check_user_permission( permission.PERMISSION_ADD_MACHINE @@ -161,11 +161,11 @@ def update_machine(machine_id, user=None, session=None, **kwargs): ) -# replace [ipmi_credentials, tag, location] to -# [patched_ipmi_credentials, patched_tag, patched_location] +# replace [power_manage, tag, location] to +# [patched_power_manage, patched_tag, patched_location] # in kwargs. It tells db these fields will be patched. @utils.replace_filters( - ipmi_credentials='patched_ipmi_credentials', + power_manage='patched_power_manage', tag='patched_tag', location='patched_location' ) @@ -174,7 +174,7 @@ def update_machine(machine_id, user=None, session=None, **kwargs): ignore_support_keys=IGNORE_FIELDS ) @database.run_in_session() -@utils.output_validates(ipmi_credentials=utils.check_ipmi_credentials) +@utils.output_validates(power_manage=utils.check_power_manage) @user_api.check_user_permission( permission.PERMISSION_ADD_MACHINE ) diff --git a/compass-deck/db/api/switch.py b/compass-deck/db/api/switch.py index 647eec0..92d7a7f 100644 --- a/compass-deck/db/api/switch.py +++ b/compass-deck/db/api/switch.py @@ -58,17 +58,17 @@ UPDATED_FILTERS_FIELDS = ['put_machine_filters'] PATCHED_FILTERS_FIELDS = ['patched_machine_filters'] ADDED_MACHINES_FIELDS = ['mac'] OPTIONAL_ADDED_MACHINES_FIELDS = [ - 'ipmi_credentials', 'tag', 'location', 'owner_id' + 'power_manage', 'tag', 'location', 'owner_id' ] ADDED_SWITCH_MACHINES_FIELDS = ['port'] OPTIONAL_ADDED_SWITCH_MACHINES_FIELDS = ['vlans'] UPDATED_MACHINES_FIELDS = [ - 'ipmi_credentials', + 'power_manage', 'tag', 'location' ] UPDATED_SWITCH_MACHINES_FIELDS = ['port', 'vlans', 'owner_id'] PATCHED_MACHINES_FIELDS = [ - 'patched_ipmi_credentials', + 'patched_power_manage', 'patched_tag', 'patched_location' ] PATCHED_SWITCH_MACHINES_FIELDS = ['patched_vlans'] @@ -85,13 +85,13 @@ RESP_ACTION_FIELDS = [ RESP_MACHINES_FIELDS = [ 'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id', 'port', 'vlans', 'mac', 'owner_id', - 'ipmi_credentials', 'tag', 'location', + 'power_manage', 'tag', 'location', 'created_at', 'updated_at' ] RESP_MACHINES_HOSTS_FIELDS = [ 'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id', 'port', 'vlans', 'mac', - 'ipmi_credentials', 'tag', 'location', 'ip', + 'power_manage', 'tag', 'location', 'ip', 'name', 'hostname', 'os_name', 'owner', 'os_installer', 'reinstall_os', 'os_installed', 'clusters', 'created_at', 'updated_at' @@ -988,13 +988,13 @@ def update_switchmachine(switch_machine_id, user=None, session=None, **kwargs): ) -# replace [vlans, ipmi_credentials, tag, location] to -# [patched_vlans, patched_ipmi_credentials, patched_tag, +# replace [vlans, power_manage, tag, location] to +# [patched_vlans, patched_power_manage, patched_tag, # patched_location] in kwargs. It tells db these fields will # be patched. @utils.replace_filters( vlans='patched_vlans', - ipmi_credentials='patched_ipmi_credentials', + power_manage='patched_power_manage', tag='patched_tag', location='patched_location' ) @@ -1024,13 +1024,13 @@ def patch_switch_machine( ) -# replace [vlans, ipmi_credentials, tag, location] to -# [patched_vlans, patched_ipmi_credentials, patched_tag, +# replace [vlans, power_manage, tag, location] to +# [patched_vlans, patched_power_manage, patched_tag, # patched_location] in kwargs. It tells db these fields will # be patched. @utils.replace_filters( vlans='patched_vlans', - ipmi_credentials='patched_ipmi_credentials', + power_manage='patched_power_manage', tag='patched_tag', location='patched_location' ) diff --git a/compass-deck/db/api/utils.py b/compass-deck/db/api/utils.py index a44f26e..ef975ef 100644 --- a/compass-deck/db/api/utils.py +++ b/compass-deck/db/api/utils.py @@ -1208,42 +1208,41 @@ def check_name(name): ) -def _check_ipmi_credentials_ip(ip): +def _check_power_manage_ip(ip): check_ip(ip) -def check_ipmi_credentials(ipmi_credentials): - """Check ipmi credentials format is correct.""" - if not ipmi_credentials: +def check_power_manage(power_manage): + """Check power manage format is correct.""" + if not power_manage: return - if not isinstance(ipmi_credentials, dict): + if not isinstance(power_manage, dict): raise exception.InvalidParameter( - 'invalid ipmi credentials %s' % ipmi_credentials - + 'invalid power manage %s' % power_manage ) - for key in ipmi_credentials: + for key in power_manage: if key not in ['ip', 'username', 'password']: raise exception.InvalidParameter( - 'unrecognized field %s in ipmi credentials %s' % ( - key, ipmi_credentials + 'unrecognized field %s in power manage %s' % ( + key, power_manage ) ) for key in ['ip', 'username', 'password']: - if key not in ipmi_credentials: + if key not in power_manage: raise exception.InvalidParameter( - 'no field %s in ipmi credentials %s' % ( - key, ipmi_credentials + 'no field %s in power manage %s' % ( + key, power_manage ) ) - check_ipmi_credential_field = '_check_ipmi_credentials_%s' % key + check_power_manage_field = '_check_power_manage_%s' % key this_module = globals() - if check_ipmi_credential_field in this_module: - this_module[check_ipmi_credential_field]( - ipmi_credentials[key] + if check_power_manage_field in this_module: + this_module[check_power_manage_field]( + power_manage[key] ) else: logging.debug( - 'function %s is not defined', check_ipmi_credential_field + 'function %s is not defined', check_power_manage_field ) -- cgit 1.2.3-korg