Skip to content

Commit

Permalink
refactor apis for faults, power management, kvm, server actions
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>
  • Loading branch information
waghswapnil committed Jan 30, 2017
1 parent a869e26 commit 5ed5941
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 171 deletions.
58 changes: 32 additions & 26 deletions imcsdk/apis/admin/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""


def get_current_certificate(handle):
def current_certificate_get(handle):
"""
This api gets the current certificate installed on the system
Expand All @@ -32,7 +32,7 @@ def get_current_certificate(handle):
return cert_mo[0]


def generate_certificate_signing_request(handle, name, org, org_unit, country,
def certificate_signing_request_generate(handle, name, org, org_unit, country,
state, locality, username=None,
password=None, server=None,
file_name=None, protocol=None,
Expand Down Expand Up @@ -61,7 +61,7 @@ def generate_certificate_signing_request(handle, name, org, org_unit, country,
None
Examples:
generate_certificate_signing_request(
certificate_signing_request_generate(
handle, name="test-cert", org="test-org", org_unit="test-unit",
country=GenerateCertificateSigningRequestConsts.COUNTRY_CODE_UNITED_STATES,
state="California", locality="San Francisco", self_signed=True)
Expand All @@ -73,26 +73,29 @@ def generate_certificate_signing_request(handle, name, org, org_unit, country,

mo = GenerateCertificateSigningRequest(parent_mo_or_dn="sys/cert-mgmt")

mo.common_name = name
mo.organization = org
mo.organizational_unit = org_unit
mo.country_code = country
mo.state = state
mo.locality = locality
params = {
"common_name": name,
"organization": org,
"organizational_unit": org_unit,
"country_code": country,
"state": state,
"locality": locality
}

if self_signed:
mo.self_signed = "yes"
params["self_signed"] = "yes"
else:
mo.user = username
mo.pwd = password
mo.remote_server = server
mo.remote_file = file_name
mo.protocol = protocol
params["user"] = username
params["pwd"] = password
params["remote_server"] = server
params["remote_file"] = file_name
params["protocol"] = protocol

mo.set_prop_multiple(**params)
handle.add_mo(mo, modify_present=True)


def get_certificate_signing_status(handle):
def certificate_signing_status_get(handle):
"""
This api checks the status of the certificate generation request
submitted previously
Expand All @@ -105,13 +108,13 @@ def get_certificate_signing_status(handle):
"""

mo = handle.query_classid("GenerateCertificateSigningRequest")
return mo[0].csr_status
return mo[0].csr_status if mo else ""


def upload_certificate(handle, username, password, server, file_name, protocol):
def certificate_upload(handle, username, password, server, file_name, protocol):
"""
This api uploads the certificate generated using \
generate_certificate_signing_request
certificate_signing_request_generate
Args:
handle (ImcHandle)
Expand All @@ -129,11 +132,14 @@ def upload_certificate(handle, username, password, server, file_name, protocol):
UploadCertificateConsts

mo = UploadCertificate(parent_mo_or_dn="sys/cert-mgmt")
mo.admin_action = UploadCertificateConsts.ADMIN_ACTION_REMOTE_CERT_UPLOAD
mo.user = username
mo.pwd = password
mo.remote_server = server
mo.remote_file = file_name
mo.protocol = protocol

params = {
"admin_action": UploadCertificateConsts.ADMIN_ACTION_REMOTE_CERT_UPLOAD,
"user": username,
"pwd": password,
"remote_server": server,
"remote_file": file_name,
"protocol": protocol,
}

mo.set_prop_multiple(**params)
handle.add_mo(mo, modify_present=True)
12 changes: 6 additions & 6 deletions imcsdk/apis/server/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
"""


def get_faults(handle, parent_class_id=None, dump=False):
def faults_get(handle, parent_class_id=None, dump=False):
"""
Fetch fault related information
Fetch fault related information.
By default, fetches all the faults in the system.
Args:
handle (ImcHandle)
parent_class_id (string): Class Id for which faults are needed. If \n
None then get all faults.
parent_class_id (string): Class Id for which faults are needed.
dump (bool): True or False
Returns:
FaultInst: List of Managed Objects
Examples:
get_faults(handle, parent_class_id="computeRackUnit", dump=False)
get_faults(handle, dump=True)
faults_get(handle, parent_class_id="computeRackUnit", dump=False)
faults_get(handle, dump=True)
"""

from imcsdk.imccoreutils import write_object
Expand Down
113 changes: 79 additions & 34 deletions imcsdk/apis/server/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@

from imcsdk.imccoreutils import get_server_dn
from imcsdk.imcexception import ImcOperationError
from imcsdk.mometa.power.PowerBudget import PowerBudget, PowerBudgetConsts
from imcsdk.mometa.standard.StandardPowerProfile import StandardPowerProfile

import logging
log = logging.getLogger('imc')

# This list is currently maintained manually.
# Ideally all such config/capabilites should come from a capability file
supported_models = ['UCSC-C220-M4', 'UCSC-C240-M4', 'UCSC-C3X60-M4']
supported_models = ['UCSC-C220-M4', 'UCSC-C240-M4', 'UCSC-C3K-M4']
supported_variants = ['M4', 'M5']


def is_supported_model(handle):
for model in supported_models:
if handle.model.find(model) != -1:
for variant in supported_variants:
if handle.model.find(variant) != -1:
return True
log.info("Current Model:'%s' does not support Power Cap and Budgeting" %
handle.model)
Expand All @@ -43,7 +46,7 @@ def get_supported_models():
return supported_models


def get_power_budget(handle, server_id=1):
def server_power_budget_get(handle, server_id=1):
"""
This api gets the min and max power limits for the platform, cpu and memory
for this specific server
Expand All @@ -58,8 +61,8 @@ def get_power_budget(handle, server_id=1):

if not is_supported_model(handle):
return
server_dn = get_server_dn(handle, server_id)
power_budget_mo = handle.query_children(in_dn=server_dn,

power_budget_mo = handle.query_children(in_dn=get_server_dn(handle, server_id),
class_id="PowerBudget")
if not power_budget_mo:
raise ImcOperationError("Get Power Budget",
Expand All @@ -68,78 +71,121 @@ def get_power_budget(handle, server_id=1):
return power_budget_mo[0]


def set_power_characterization(handle, run_at_boot="yes", server_id=1):
def server_power_characterization_enable(handle, server_id=1):
"""
This api sets the property
Enables power characterization.
Args:
handle (ImcHandle)
run_at_boot (string) : "yes", "no"
server_id (int): Server Id to be specified for C3260 platforms
Returns:
PowerBudget object
"""
if not is_supported_model(handle):
return
power_budget_mo = PowerBudget(
parent_mo_or_dn=get_server_dn(handle, server_id))
power_budget_mo.pow_char_enable = "enabled"
handle.set_mo(power_budget_mo)
return power_budget_mo


def server_power_characterization_start(handle, server_id=1):
"""
Starts a power characterization run.
From 3.0(1c) onwards, server_power_characterization_enable needs to be
explicitly done, before invoking this api.
from imcsdk.mometa.power.PowerBudget import PowerBudget, PowerBudgetConsts
Args:
handle (ImcHandle)
server_id (int): Server Id to be specified for C3260 platforms
Returns:
PowerBudget object
"""
if not is_supported_model(handle):
return
server_dn = get_server_dn(handle, server_id)
power_budget_mo = PowerBudget(parent_mo_or_dn=server_dn)
power_budget_mo = PowerBudget(parent_mo_or_dn=get_server_dn(handle, server_id))

power_budget_mo.admin_action = \
PowerBudgetConsts.ADMIN_ACTION_START_POWER_CHAR
PowerBudgetConsts.ADMIN_ACTION_START_POWER_CHAR
handle.set_mo(power_budget_mo)
return power_budget_mo


def server_power_capping_enable(handle, server_id=1):
"""
Enables power capping feature on the server.
Args:
handle (ImcHandle)
server_id (int): Server Id to be specified for C3260 platforms
Returns:
PowerBudget object
"""

if not is_supported_model(handle):
return
power_budget_mo = PowerBudget(parent_mo_or_dn=get_server_dn(handle, server_id))
power_budget_mo.admin_state = "enabled"
handle.set_mo(power_budget_mo)
return power_budget_mo


def set_standard_power_cap(handle, throttle="no", power_limit=0,
correction_time=3, corrective_action="alert",
hard_cap="no", server_id=1):
def server_standard_power_cap_set(handle, power_limit, throttle=False,
correction_time=3, corrective_action="alert",
hard_cap=False, server_id=1):
"""
This method sets up the standard power cap configuration profile
Args:
handle (ImcHandle)
throttle (string): "yes", "no"
power_limit (int): Power limit in Watts. Range (157-300) W
throttle (bool)
power_limit (int): Power limit in Watts.
Range can be retrieved from min_power and max_power
fields of PowerBudget object
correction_time (int): Time in seconds before power_limit is enforced
and corrective action is taken. Range (1-600)s
corrective_action (string): "none","alert","shutdown","alert,shutdown"
hard_cap (string): "yes", "no"
hard_cap (bool): Enable hard power cap
server_id (int): Server Id to be specified for C3260 platforms
Returns:
StandardPowerProfile object
Examples:
set_standard_power_cap(handle,
correction_time=5,
corrective_action="alert")
set_standard_power_cap(handle, throttle=True,
server_standard_power_cap_set(handle,
correction_time=5,
corrective_action="alert")
server_standard_power_cap_set(handle, throttle=True,
power_limit=200, correction_time=5,
corrective_action="alert, shutdown")
"""

from imcsdk.mometa.standard.StandardPowerProfile import StandardPowerProfile
if not is_supported_model(handle):
return
server_dn = get_server_dn(handle, server_id)
power_budget_dn = server_dn + "/budget"

power_budget_dn = get_server_dn(handle, server_id) + "/budget"
stdpowerprof_mo = StandardPowerProfile(
parent_mo_or_dn=power_budget_dn)

stdpowerprof_mo.allow_throttle = throttle
stdpowerprof_mo.power_limit = str(power_limit)
stdpowerprof_mo.corr_time = str(correction_time)
stdpowerprof_mo.corr_action = corrective_action
stdpowerprof_mo.profile_enabled = "yes"
stdpowerprof_mo.hard_cap = hard_cap
params = {
"allow_throttle": ("no", "yes")[throttle],
"power_limit": str(power_limit),
"corr_time": str(correction_time),
"corr_action": corrective_action,
"profile_enabled": "yes",
"hard_cap": ("no", "yes")[hard_cap]
}

stdpowerprof_mo.set_prop_multiple(**params)
handle.set_mo(stdpowerprof_mo)
return stdpowerprof_mo


def disable_standard_cap(handle, server_id=1):
def server_standard_power_cap_disable(handle, server_id=1):
"""
This method disables the standard power profile
Expand All @@ -151,7 +197,6 @@ def disable_standard_cap(handle, server_id=1):
None
"""

from imcsdk.mometa.standard.StandardPowerProfile import StandardPowerProfile
if not is_supported_model(handle):
return
server_dn = get_server_dn(handle, server_id)
Expand Down
Loading

0 comments on commit 5ed5941

Please sign in to comment.