Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/941.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support setting the `use_host_network` option of scaling group in the client-py.
28 changes: 26 additions & 2 deletions src/ai/backend/client/cli/admin/scaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,19 @@ def list(ctx: CLIContext) -> None:
default="{}",
help="Set scheduler options as a JSON string.",
)
@click.option(
"--use-host-network", is_flag=True, help="If true, run containers on host networking mode."
)
def add(
ctx: CLIContext, name, description, inactive, driver, driver_opts, scheduler, scheduler_opts
ctx: CLIContext,
name,
description,
inactive,
driver,
driver_opts,
scheduler,
scheduler_opts,
use_host_network,
):
"""
Add a new scaling group.
Expand All @@ -100,6 +111,7 @@ def add(
driver_opts=driver_opts,
scheduler=scheduler,
scheduler_opts=scheduler_opts,
use_host_network=use_host_network,
)
except Exception as e:
ctx.output.print_mutation_error(
Expand Down Expand Up @@ -137,8 +149,19 @@ def add(
default=None,
help="Set scheduler options as a JSON string.",
)
@click.option(
"--use-host-network", is_flag=True, help="If true, run containers on host networking mode."
)
def update(
ctx: CLIContext, name, description, inactive, driver, driver_opts, scheduler, scheduler_opts
ctx: CLIContext,
name,
description,
inactive,
driver,
driver_opts,
scheduler,
scheduler_opts,
use_host_network,
):
"""
Update existing scaling group.
Expand All @@ -155,6 +178,7 @@ def update(
driver_opts=driver_opts,
scheduler=scheduler,
scheduler_opts=scheduler_opts,
use_host_network=use_host_network,
)
except Exception as e:
ctx.output.print_mutation_error(
Expand Down
6 changes: 6 additions & 0 deletions src/ai/backend/client/func/scaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
scaling_group_fields["created_at"],
scaling_group_fields["driver"],
scaling_group_fields["scheduler"],
scaling_group_fields["use_host_network"],
)

_default_detail_fields = (
Expand All @@ -29,6 +30,7 @@
scaling_group_fields["driver_opts"],
scaling_group_fields["scheduler"],
scaling_group_fields["scheduler_opts"],
scaling_group_fields["use_host_network"],
)


Expand Down Expand Up @@ -121,6 +123,7 @@ async def create(
driver_opts: Mapping[str, str] = None,
scheduler: str = None,
scheduler_opts: Mapping[str, str] = None,
use_host_network: bool = False,
fields: Iterable[FieldSpec | str] = None,
) -> dict:
"""
Expand Down Expand Up @@ -148,6 +151,7 @@ async def create(
"driver_opts": json.dumps(driver_opts),
"scheduler": scheduler,
"scheduler_opts": json.dumps(scheduler_opts),
"use_host_network": use_host_network,
},
}
data = await api_session.get().Admin._query(query, variables)
Expand All @@ -164,6 +168,7 @@ async def update(
driver_opts: Mapping[str, str] = None,
scheduler: str = None,
scheduler_opts: Mapping[str, str] = None,
use_host_network: bool = False,
fields: Iterable[FieldSpec | str] = None,
) -> dict:
"""
Expand Down Expand Up @@ -191,6 +196,7 @@ async def update(
"driver_opts": None if driver_opts is None else json.dumps(driver_opts),
"scheduler": scheduler,
"scheduler_opts": None if scheduler_opts is None else json.dumps(scheduler_opts),
"use_host_network": use_host_network,
},
}
data = await api_session.get().Admin._query(query, variables)
Expand Down
1 change: 1 addition & 0 deletions src/ai/backend/client/output/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
FieldSpec("driver_opts", formatter=nested_dict_formatter),
FieldSpec("scheduler"),
FieldSpec("scheduler_opts", formatter=nested_dict_formatter),
FieldSpec("use_host_network"),
]
)

Expand Down
6 changes: 6 additions & 0 deletions src/ai/backend/manager/models/scaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class ScalingGroup(graphene.ObjectType):
driver_opts = graphene.JSONString()
scheduler = graphene.String()
scheduler_opts = graphene.JSONString()
use_host_network = graphene.Boolean()

@classmethod
def from_row(
Expand All @@ -280,6 +281,7 @@ def from_row(
driver_opts=row["driver_opts"],
scheduler=row["scheduler"],
scheduler_opts=row["scheduler_opts"].to_json(),
use_host_network=row["use_host_network"],
)

@classmethod
Expand Down Expand Up @@ -432,6 +434,7 @@ class CreateScalingGroupInput(graphene.InputObjectType):
driver_opts = graphene.JSONString(required=False, default={})
scheduler = graphene.String(required=True)
scheduler_opts = graphene.JSONString(required=False, default={})
use_host_network = graphene.Boolean(required=False, default=False)


class ModifyScalingGroupInput(graphene.InputObjectType):
Expand All @@ -442,6 +445,7 @@ class ModifyScalingGroupInput(graphene.InputObjectType):
driver_opts = graphene.JSONString(required=False)
scheduler = graphene.String(required=False)
scheduler_opts = graphene.JSONString(required=False)
use_host_network = graphene.Boolean(required=False)


class CreateScalingGroup(graphene.Mutation):
Expand Down Expand Up @@ -473,6 +477,7 @@ async def mutate(
"driver_opts": props.driver_opts,
"scheduler": props.scheduler,
"scheduler_opts": ScalingGroupOpts.from_json(props.scheduler_opts),
"use_host_network": bool(props.use_host_network),
}
insert_query = sa.insert(scaling_groups).values(data)
return await simple_db_mutate_returning_item(
Expand Down Expand Up @@ -512,6 +517,7 @@ async def mutate(
set_if_set(
props, data, "scheduler_opts", clean_func=lambda v: ScalingGroupOpts.from_json(v)
)
set_if_set(props, data, "use_host_network")
update_query = sa.update(scaling_groups).values(data).where(scaling_groups.c.name == name)
return await simple_db_mutate(cls, info.context, update_query)

Expand Down