Skip to content

Commit

Permalink
[usermode] add options for oar-usermode init script
Browse files Browse the repository at this point in the history
  • Loading branch information
augu5te committed Oct 19, 2024
1 parent 1ce9faf commit e04c7ba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
55 changes: 49 additions & 6 deletions oar/cli/oar-usermode.py → oar/cli/oar_usermode.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import os
import shutil
import sys

import click
from alembic.migration import MigrationContext
from alembic.operations import Operations
from ClusterShell.NodeSet import NodeSet
from sqlalchemy import Column, Integer
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.orm import sessionmaker

import oar.tools as tools
from oar.lib.globals import init_oar
from oar.lib.models import DeferredReflectionModel, Model, Queue, Resource


def db_create():
def db_create(nodes, nb_core, skip):
config, engine = init_oar(no_reflect=True)

if config["USER_MODE"] == "NO":
Expand Down Expand Up @@ -56,15 +61,53 @@ def db_create():
state="Active",
)

for i in range(5):
print(i)
Resource.create(session, network_address="localhost" + str(int(i / 2)))
nodeset = NodeSet(nodes)
core = 1
if skip:
nodeset = nodeset[1:]
for node in nodeset:
for _ in range(nb_core):
Resource.create(session, network_address=node, core=core)
core += 1
session.commit()

# reflect_base(Model.metadata, DeferredReflectionModel, engine)
# DeferredReflectionModel.prepare(engine)
engine.dispose()


if __name__ == "__main__":
db_create()
@click.command()
@click.option("-c", "--create-db", is_flag=True, help="Create database")
@click.option(
"-b",
"--base-configfile",
is_flag=True,
help="Copy base configuration file ('oar_usermode.conf')",
)
@click.option(
"-n",
"--nodes",
type=click.STRING,
help="nodes to declare in database following nodeset formate (ex: node[1,6-7])",
)
@click.option(
"-s",
"--skip",
is_flag=True,
help="skip the first node from nodes (usually reserved to OAR services",
)
@click.option(
"-o",
"--nb-core",
type=click.INT,
default=os.cpu_count(),
help="Number of cores for each node",
)
def cli(base_configfile, create_db, nodes, skip, nb_core):
if base_configfile:
oar_configfile = "oar_usermode.conf"
shutil.copyfile(tools.get_absolute_script_path(oar_configfile), oar_configfile)
if create_db:
if not nodes:
nodes = "node[1-5]"
db_create(nodes, nb_core, skip)
File renamed without changes.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ oar-leon = 'oar.modules.leon:main'
oar-node-change-state = 'oar.modules.node_change_state:main'
oar-bipbip = 'oar.modules.bipbip:main'
oar-proxy-cleaner = 'oar.cli.oarproxycleaner:cli'
oar-usermode = 'oar.cli.oar-usermode:main'
oar-usermode = 'oar.cli.oar_usermode:cli'
oarexec-usermode = 'oar.tools.oarexec_usermode:main'

[tool.poetry.dependencies]
python = ">=3.10, <4"
Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ def get_requirements(basename):
url="https://github.com/oar-team/oar3",
packages=find_packages(exclude=["tests"]),
package_dir={"oar": "oar"},
package_data={"oar": ["tools/*.pl", "tools/*.pm", "tools/*.sh", "tools/oarexec"]},
package_data={
"oar": [
"tools/*.pl",
"tools/*.pm",
"tools/*.sh",
"tools/oarexec",
"tools/oar_usermode.conf",
]
},
install_requires=get_requirements("base"),
extras_require=extras_require,
include_package_data=True,
Expand Down Expand Up @@ -97,5 +105,7 @@ def get_requirements(basename):
oar-node-change-state=oar.modules.node_change_state:main
oar-bipbip=oar.modules.bipbip:main
oar-proxy-cleaner=oar.cli.oarproxycleaner:cli
oar-usermode=oar.cli.oar_usermode:cli
oarexec-usermode=oar.tools.oarexec_usermode:main
""",
)

0 comments on commit e04c7ba

Please sign in to comment.