Initial Commit
This commit is contained in:
0
api/app/models/vmware/reports/capacity/__init__.py
Normal file
0
api/app/models/vmware/reports/capacity/__init__.py
Normal file
25
api/app/models/vmware/reports/capacity/frame.py
Normal file
25
api/app/models/vmware/reports/capacity/frame.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, Integer, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from models.common.base import BaseModel
|
||||
|
||||
|
||||
class frame(BaseModel):
|
||||
__tablename__ = "tvrc_frames"
|
||||
_s_collection_name = "frames"
|
||||
http_methods = {"get", "post", "delete"}
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
||||
timestamp = Column(
|
||||
DateTime,
|
||||
default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
capacity = relationship(
|
||||
"capacity",
|
||||
backref="frame",
|
||||
cascade="save-update, delete"
|
||||
)
|
||||
131
api/app/models/vmware/reports/capacity/report.py
Normal file
131
api/app/models/vmware/reports/capacity/report.py
Normal file
@@ -0,0 +1,131 @@
|
||||
from safrs import jsonapi_rpc, SAFRSFormattedResponse
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Integer,
|
||||
Float,
|
||||
ForeignKey
|
||||
)
|
||||
|
||||
from helpers.database import db
|
||||
from helpers.math import safe_division
|
||||
from models.common.base import BaseModel
|
||||
from models.vmware.reports.capacity.frame import frame
|
||||
|
||||
|
||||
class capacity(BaseModel):
|
||||
"""
|
||||
description: Capacity report model
|
||||
"""
|
||||
__tablename__ = "tvrc_report"
|
||||
_s_collection_name = "capacity"
|
||||
|
||||
http_methods = {"get", "post"}
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
||||
hosts_on_duty = Column(Integer, nullable=False)
|
||||
hosts_in_maintenance = Column(Integer, nullable=False)
|
||||
hosts_reserved = Column(Integer, nullable=False)
|
||||
hosts_staged_dcm = Column(Integer, nullable=False)
|
||||
vms_total = Column(Integer, nullable=False)
|
||||
sockets_total = Column(Integer, nullable=False)
|
||||
pcpu_total = Column(Integer, nullable=False)
|
||||
pcpu_host_max = Column(Integer, nullable=False)
|
||||
vcpu_provisioned = Column(Integer, nullable=False)
|
||||
pmemory_total = Column(Float, nullable=False)
|
||||
vmemory_provisioned = Column(Float, nullable=False)
|
||||
pstorage_total = Column(Float, nullable=False)
|
||||
vstorage_used = Column(Float, nullable=False)
|
||||
vstorage_provisioned = Column(Float, nullable=False)
|
||||
rdm_total = Column(Float, nullable=False)
|
||||
pcpu_ovp_target = Column(Float, nullable=False)
|
||||
pmemory_ovp_target = Column(Float, nullable=False)
|
||||
pstorage_ovp_target = Column(Float, nullable=False)
|
||||
pcpu_retire_target = Column(Float, nullable=False)
|
||||
|
||||
frame_id = Column(
|
||||
Integer, ForeignKey("tvrc_frames.id"),
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
cluster_id = Column(
|
||||
Integer,
|
||||
ForeignKey("tvc_clusters.id"),
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@jsonapi_rpc(http_methods=["GET"])
|
||||
def get_last(self, *args, **kwargs):
|
||||
"""
|
||||
description : Get capacity report by last frameid
|
||||
summary : Get last capacity report
|
||||
tags:
|
||||
- capacity
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
"""
|
||||
|
||||
frame_obj = db.session.query(frame).order_by(frame.id.desc()).first()
|
||||
|
||||
reports = db.session.query(capacity).\
|
||||
filter(capacity.frame_id == frame_obj.id).all()
|
||||
|
||||
data = [reports]
|
||||
response = SAFRSFormattedResponse(
|
||||
data,
|
||||
self._s_meta(),
|
||||
{},
|
||||
{},
|
||||
len(reports)
|
||||
)
|
||||
return response
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pcpu_ovp_current = kwargs.pop("pcpu_ovp_current", None) # noqa
|
||||
pmemory_ovp_current = kwargs.pop("pmemory_ovp_current", None) # noqa
|
||||
pstorage_ovp_current = kwargs.pop("pstorage_ovp_current", None) # noqa
|
||||
|
||||
cpu_cap_used = kwargs.pop("cpu_cap_used", None) # noqa
|
||||
mem_cap_used = kwargs.pop("mem_cap_used", None) # noqa
|
||||
str_cap_used = kwargs.pop("str_cap_used", None) # noqa
|
||||
|
||||
hosts_total = kwargs.pop("hosts_total", None) # noqa
|
||||
|
||||
BaseModel.__init__(self, **kwargs)
|
||||
|
||||
def to_dict(self):
|
||||
result = BaseModel.to_dict(self)
|
||||
|
||||
result['pcpu_ovp_current'] = safe_division(
|
||||
result['vcpu_provisioned'],
|
||||
result['pcpu_total']
|
||||
)
|
||||
result['pmemory_ovp_current'] = safe_division(
|
||||
result['vmemory_provisioned'],
|
||||
result['pmemory_total']
|
||||
)
|
||||
result['pstorage_ovp_current'] = safe_division(
|
||||
result['vstorage_provisioned'],
|
||||
result['pstorage_total']
|
||||
)
|
||||
|
||||
result['cpu_cap_used'] = round(safe_division(
|
||||
result['pcpu_ovp_current'],
|
||||
result['pcpu_ovp_target']
|
||||
)*100)
|
||||
result['mem_cap_used'] = round(safe_division(
|
||||
result['pmemory_ovp_current'],
|
||||
result['pmemory_ovp_target']
|
||||
)*100)
|
||||
result['str_cap_used'] = round(safe_division(
|
||||
result['pstorage_ovp_current'],
|
||||
result['pstorage_ovp_target']
|
||||
)*100)
|
||||
|
||||
result['hosts_total'] = result['hosts_on_duty'] +\
|
||||
result['hosts_reserved'] +\
|
||||
result['hosts_in_maintenance']
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user