Skip to content

Commit

Permalink
feat: Extend server metadata details
Browse files Browse the repository at this point in the history
Added rack, u-location and blade of host metadata

fixes: #448
fixes: #440

Change-Id: I0d3986bb8468045f8c076e1ee1b7175e8c337943
  • Loading branch information
athiruma authored and sadsfae committed Jan 10, 2025
1 parent 189cd16 commit 55fefe4
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/quads/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,9 @@ def action_hostresource(self):
"host_type": self.cli_args.get("hosttype"),
"model": self.cli_args.get("model"),
"force": self.cli_args.get("force"),
"rack": self.cli_args.get("rack"),
"uloc": self.cli_args.get("uloc"),
"blade": self.cli_args.get("blade"),
}
try:
_host = self.quads.create_host(data)
Expand Down
24 changes: 24 additions & 0 deletions src/quads/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,30 @@
help="Modify notification of a cloud",
)

action_group.add_argument(
"--rack",
dest="action",
action="store_const",
const="rack",
help="rack name of the host",
)

action_group.add_argument(
"--blade",
dest="action",
action="store_const",
const="blade",
help="blade name of the host",
)

action_group.add_argument(
"--uloc",
dest="action",
action="store_const",
const="uloc",
help="U-location name of the host",
)

mod_notification_arg_names = [
"fail", "success", "initial", "pre-initial",
"pre", "one-day", "three-days", "five-days", "seven-days"]
Expand Down
6 changes: 6 additions & 0 deletions src/quads/server/blueprints/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def create_host() -> Response:
default_cloud = data.get("default_cloud")
host_type = data.get("host_type")
can_self_schedule = data.get("can_self_schedule")
rack = data.get("rack")
uloc = data.get("uloc")
blade = data.get("blade")

if not model:
response = {
Expand Down Expand Up @@ -228,6 +231,9 @@ def create_host() -> Response:
can_self_schedule=can_self_schedule,
default_cloud=_default_cloud,
cloud=_default_cloud,
rack=rack,
uloc=uloc,
blade=blade,
)
db.session.add(_host_obj)
BaseDao.safe_commit()
Expand Down
6 changes: 5 additions & 1 deletion src/quads/server/dao/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class HostDao(BaseDao):
@classmethod
def create_host(
cls, name: str, model: str, host_type: str, default_cloud: str, can_self_schedule: bool = False
cls, name: str, model: str, host_type: str, default_cloud: str, can_self_schedule: bool = False,
rack: str = None, uloc: str = None, blade: str = None
) -> Host:
_host_obj = cls.get_host(name)
if _host_obj:
Expand All @@ -35,6 +36,9 @@ def create_host(
can_self_schedule=can_self_schedule,
default_cloud=_default_cloud_obj,
cloud=_default_cloud_obj,
rack=rack,
uloc=uloc,
blade=blade,
)
db.session.add(_host)
cls.safe_commit()
Expand Down
8 changes: 7 additions & 1 deletion src/quads/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ class Host(Serialize, TimestampMixin, Base):
retired = Column(Boolean, default=False)
last_build = Column(DateTime)
can_self_schedule = Column(Boolean, default=True)
rack = Column(String)
uloc = Column(String)
blade = Column(String)

# many-to-one
cloud_id = Column(Integer, ForeignKey("clouds.id"))
Expand All @@ -560,7 +563,7 @@ def __repr__(self):
"<Host(id='{}', name='{}', model='{}', host_type='{}', build='{}', "
"validated='{}', switch_config_applied='{}', broken='{}', retired='{}', "
"last_build='{}', can_self_schedule='{}', cloud='{}', default_cloud='{}', interfaces='{}', "
"disks='{}', memory='{}', processors='{}')>".format(
"disks='{}', memory='{}', processors='{}', rack='{}', uloc='{}', blade='{}')>".format(
self.id,
self.name,
self.model,
Expand All @@ -578,6 +581,9 @@ def __repr__(self):
self.disks,
self.memory,
self.processors,
self.rack,
self.uloc,
self.blade
)
)

Expand Down
12 changes: 12 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
"build_start": None,
"end": "Tue, 06 Jun 2023 22:00:00 GMT",
"host": {
'blade': None,
"broken": False,
"build": False,
"can_self_schedule": True,
Expand All @@ -621,8 +622,10 @@
"last_build": None,
"model": "R640",
"name": "host2.example.com",
'rack': None,
"retired": False,
"switch_config_applied": False,
'uloc': None,
"validated": False,
},
"host_id": 2,
Expand Down Expand Up @@ -680,6 +683,7 @@
"build_start": None,
"end": "Tue, 06 Jun 2023 22:00:00 GMT",
"host": {
'blade': None,
"broken": False,
"build": False,
"can_self_schedule": True,
Expand All @@ -698,8 +702,10 @@
"last_build": None,
"model": "1029P",
"name": "host3.example.com",
'rack': None,
"retired": False,
"switch_config_applied": False,
'uloc': None,
"validated": False,
},
"host_id": 3,
Expand Down Expand Up @@ -842,6 +848,7 @@
"created_at": "Tue, 07 Mar 2023 11:36:53 GMT",
"end": "Tue, 18 Mar 2042 22:00:00 GMT",
"host": {
'blade': None,
"broken": False,
"build": False,
"can_self_schedule": True,
Expand All @@ -863,8 +870,10 @@
"last_build": None,
"model": "R640",
"name": "host2.example.com",
'rack': None,
"retired": False,
"switch_config_applied": False,
'uloc': None,
"validated": False,
},
"host_id": 2,
Expand Down Expand Up @@ -927,6 +936,7 @@
"created_at": "Tue, 07 Mar 2023 11:36:53 GMT",
"end": "Fri, 18 Mar 2044 22:00:00 GMT",
"host": {
'blade': None,
"broken": False,
"build": False,
"can_self_schedule": True,
Expand All @@ -948,8 +958,10 @@
"last_build": None,
"model": "1029P",
"name": "host3.example.com",
'rack': None,
"retired": False,
"switch_config_applied": False,
'uloc': None,
"validated": False,
},
"host_id": 3,
Expand Down

0 comments on commit 55fefe4

Please sign in to comment.