Skip to content
Closed
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
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
apply: always
mode: all
---
# Exordos Core Agent Guide

## 1. Think Before Coding
Expand Down
8 changes: 4 additions & 4 deletions exordos_core/agent/universal/clients/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class GCRestApiBackendClient(rest.RestApiBackendClient):
def __init__(
self,
http_client: http.CollectionBaseClient,
collection_map: tp.Dict[str, str],
collection_map: dict[str, str],
project_id: sys_uuid.UUID,
) -> None:
super().__init__(http_client=http_client, collection_map=collection_map)
self._project_id = str(project_id)

def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def create(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Creates the resource. Returns the created resource."""
# Inject mandatory fields
resource.value["uuid"] = str(resource.uuid)
Expand All @@ -48,7 +48,7 @@ def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:

return super().create(resource)

def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def update(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Update the resource. Returns the updated resource."""
# FIXME(akremenetsky): Not the best implementation
# Remove popential RO fields
Expand All @@ -61,6 +61,6 @@ def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:

return super().update(resource)

def list(self, kind: str) -> tp.List[tp.Dict[str, tp.Any]]:
def list(self, kind: str) -> list[dict[str, tp.Any]]:
"""Lists all resources by kind."""
return super().list(kind, project_id=self._project_id)
10 changes: 5 additions & 5 deletions exordos_core/agent/universal/drivers/secret/backend/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
) -> None:
self._dns_client = dns_client
self._admin_email = admin_email
self._client_acme: tp.Optional[acme_lib_client.ClientV2] = None
self._client_acme: acme_lib_client.ClientV2 | None = None
self._private_key = acme.get_or_create_client_private_key(private_key_path)

def _get_or_create_acme_client(self) -> acme_lib_client.ClientV2:
Expand All @@ -54,7 +54,7 @@ def _get_or_create_acme_client(self) -> acme_lib_client.ClientV2:
)
return self._client_acme

def get(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def get(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Get the resource value in dictionary format."""
try:
cert = driver_dm.Certificate.objects.get_one(
Expand All @@ -67,7 +67,7 @@ def get(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:

return cert.to_resource_value()

def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def create(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Creates the resource. Returns the created resource."""
try:
self.get(resource)
Expand Down Expand Up @@ -95,7 +95,7 @@ def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
driver_cert.save()
return driver_cert.to_resource_value()

def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def update(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Update the resource. Returns the updated resource."""
try:
cert = driver_dm.Certificate.objects.get_one(
Expand Down Expand Up @@ -135,7 +135,7 @@ def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
driver_cert.save()
return driver_cert.to_resource_value()

def list(self, kind: str, **kwargs) -> tp.List[tp.Dict[str, tp.Any]]:
def list(self, kind: str, **kwargs) -> list[dict[str, tp.Any]]:
"""Lists all resources by kind."""
certs = driver_dm.Certificate.objects.get_all()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class DatabasePasswordBackendClient(base.AbstractBackendClient):
"""Secret Backend client based on SQL database."""

def get(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def get(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Get the resource value in dictionary format."""
try:
driver_password = driver_dm.Password.objects.get_one(
Expand All @@ -61,7 +61,7 @@ def _gen_password(self, password: secret_dm.Password) -> str:
else:
return password.value

def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def create(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Creates the resource. Returns the created resource."""
try:
self.get(resource)
Expand Down Expand Up @@ -95,7 +95,7 @@ def create(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
driver_password.save()
return driver_password.meta

def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:
def update(self, resource: models.Resource) -> dict[str, tp.Any]:
"""Update the resource. Returns the updated resource."""

target = secret_dm.Password.from_ua_resource(resource)
Expand All @@ -116,7 +116,7 @@ def update(self, resource: models.Resource) -> tp.Dict[str, tp.Any]:

return actual.meta

def list(self, kind: str, **kwargs) -> tp.List[tp.Dict[str, tp.Any]]:
def list(self, kind: str, **kwargs) -> list[dict[str, tp.Any]]:
"""Lists all resources by kind."""
secrets = driver_dm.Password.objects.get_all()
return [s.meta for s in secrets]
Expand Down
3 changes: 1 addition & 2 deletions exordos_core/agent/universal/drivers/secret/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# under the License.

import logging
import typing as tp

from gcl_certbot_plugin import clients as dns_clients
from gcl_sdk.agents.universal.drivers import direct
Expand Down Expand Up @@ -58,6 +57,6 @@ def __init__(

super().__init__(storage=storage, client=client)

def get_capabilities(self) -> tp.List[str]:
def get_capabilities(self) -> list[str]:
"""Returns a list of capabilities supported by the driver."""
return ["certificate"]
4 changes: 2 additions & 2 deletions exordos_core/agent/universal/drivers/secret/dm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Secret(
default=sc.SecretStatus.NEW.value,
)
# Some additional metadata about the secret
meta = properties.property(types.Dict(), default=lambda: {})
meta = properties.property(types.Dict(), default=dict)


class Password(Secret, orm.SQLStorableMixin):
Expand Down Expand Up @@ -109,7 +109,7 @@ def is_under_threshold(self) -> bool:
delta = self.expiration_at - datetime.datetime.now(tz=datetime.timezone.utc)
return delta.days < self.meta["expiration_threshold"]

def to_resource_value(self) -> tp.Dict[str, tp.Any]:
def to_resource_value(self) -> dict[str, tp.Any]:
expiration_at = self.expiration_at.replace(tzinfo=datetime.timezone.utc)
expiration_at = expiration_at.strftime(c.DEFAULT_DATETIME_FORMAT)

Expand Down
3 changes: 1 addition & 2 deletions exordos_core/agent/universal/drivers/secret/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# under the License.

import logging
import typing as tp

from gcl_sdk.agents.universal.drivers import direct
from gcl_sdk.agents.universal.storage import fs
Expand All @@ -38,6 +37,6 @@ def __init__(self, storage_path: str = PASSWORD_TARGET_FIELDS_STORAGE):

super().__init__(storage=storage, client=client)

def get_capabilities(self) -> tp.List[str]:
def get_capabilities(self) -> list[str]:
"""Returns a list of capabilities supported by the driver."""
return ["password"]
8 changes: 5 additions & 3 deletions exordos_core/boot_api/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import typing as tp

from gcl_sdk.agents.universal.orch_api import routes as orch_routes
from gcl_sdk.agents.universal.status_api import routes as status_routes
from restalchemy.api import routes
Expand All @@ -25,13 +27,13 @@ class NetbootRoute(routes.Route):
"""Handler for /v1/boots/ endpoint"""

__controller__ = controllers.NetBootController
__allow_methods__ = [routes.GET]
__allow_methods__: tp.ClassVar[list] = [routes.GET]


class UniversalAgentsRoute(orch_routes.UniversalAgentsRoute):
"""Handler for /v1/agents/ endpoint"""

__allow_methods__ = [
__allow_methods__: tp.ClassVar[list] = [
routes.GET,
routes.CREATE,
routes.UPDATE,
Expand All @@ -43,7 +45,7 @@ class ApiEndpointRoute(routes.Route):
"""Handler for /v1/ endpoint"""

__controller__ = controllers.ApiEndpointController
__allow_methods__ = [routes.FILTER]
__allow_methods__: tp.ClassVar[list] = [routes.FILTER]

nodes = routes.route(status_routes.NodesRoute)
boots = routes.route(NetbootRoute)
Expand Down
15 changes: 8 additions & 7 deletions exordos_core/boot_api/dm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.


import typing as tp

from restalchemy.dm import types
Expand All @@ -25,7 +26,7 @@


class MachineNetboot(models.Machine):
__custom_properties__ = {
__custom_properties__: tp.ClassVar[dict] = {
"gc_host": types.String(max_length=255),
"gc_boot_api": types.String(max_length=255),
"kernel": types.AllowNone(types.String(max_length=255)),
Expand All @@ -36,8 +37,8 @@ def __init__(
self,
gc_host: str = LOCAL_GC_HOST,
gc_boot_api: str = LOCAL_GC_BOOT_API,
kernel: tp.Optional[str] = None,
initrd: tp.Optional[str] = None,
kernel: str | None = None,
initrd: str | None = None,
*args,
**kwargs,
):
Expand All @@ -49,8 +50,8 @@ def restore_from_storage(
cls,
gc_host: str = LOCAL_GC_HOST,
gc_boot_api: str = LOCAL_GC_BOOT_API,
kernel: tp.Optional[str] = None,
initrd: tp.Optional[str] = None,
kernel: str | None = None,
initrd: str | None = None,
**kwargs,
):
obj = super().restore_from_storage(**kwargs)
Expand All @@ -61,8 +62,8 @@ def set_netboot_params(
self,
gc_host: str,
gc_boot_api: str,
kernel: tp.Optional[str],
initrd: tp.Optional[str],
kernel: str | None,
initrd: str | None,
) -> None:
self.gc_host = gc_host
self.gc_boot_api = gc_boot_api
Expand Down
19 changes: 8 additions & 11 deletions exordos_core/bootstrap/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ def add_core_set(
continue

p = compute_models.Port.restore_from_simple_view(
**dict(
subnet=str(c.MAIN_SUBNET_UUID),
source=spec["stand"]["network"]["name"],
node=str(node.uuid),
ipv4=port["ip"],
mac=port["mac"],
status="ACTIVE",
project_id=str(c.SERVICE_PROJECT_ID),
)
subnet=str(c.MAIN_SUBNET_UUID),
source=spec["stand"]["network"]["name"],
node=str(node.uuid),
ipv4=port["ip"],
mac=port["mac"],
status="ACTIVE",
project_id=str(c.SERVICE_PROJECT_ID),
)
p.insert()
return node_set
Expand Down Expand Up @@ -291,7 +289,7 @@ def init_secrets(
default_user.secret_hash = admin_secret_hash
default_user.save()

return None
return


def _net_range(network: ipaddress.IPv4Network, start_offset: int) -> str:
Expand Down Expand Up @@ -328,7 +326,6 @@ def apply_flat_network(stand: dict[str, tp.Any]) -> None:
network.insert()
LOG.info("Created network %s", network.uuid)

#
main_net = ipaddress.ip_network(stand["network"]["cidr"])
boot_net = ipaddress.ip_network(stand["boot_network"]["cidr"])

Expand Down
2 changes: 1 addition & 1 deletion exordos_core/cmd/boot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main():
wsgi_app=app.build_wsgi_application(),
host=CONF[DOMAIN].bind_host,
port=CONF[DOMAIN].bind_port,
bjoern_kwargs=dict(reuse_port=True),
bjoern_kwargs={"reuse_port": True},
)

service.add_setup(
Expand Down
1 change: 0 additions & 1 deletion exordos_core/cmd/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def _apply_flat_network(stand: dict[str, tp.Any]) -> None:
network.insert()
LOG.info("Created network %s", network.uuid)

#
main_net = ipaddress.ip_network(stand["network"]["cidr"])
boot_net = ipaddress.ip_network(stand["boot_network"]["cidr"])

Expand Down
2 changes: 1 addition & 1 deletion exordos_core/cmd/bootstrap_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@


def _persisted_path(dst_path: str) -> str:
dst_path = dst_path[1:] if dst_path.startswith("/") else dst_path
dst_path = dst_path.removeprefix("/")
return os.path.join(c.DATA_DIR, dst_path)


Expand Down
2 changes: 1 addition & 1 deletion exordos_core/cmd/orch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
wsgi_app=app.build_wsgi_application(),
host=CONF[DOMAIN].bind_host,
port=CONF[DOMAIN].bind_port,
bjoern_kwargs=dict(reuse_port=True),
bjoern_kwargs={"reuse_port": True},
)

service.add_setup(
Expand Down
2 changes: 1 addition & 1 deletion exordos_core/cmd/status_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main():
wsgi_app=app.build_wsgi_application(),
host=CONF[DOMAIN].bind_host,
port=CONF[DOMAIN].bind_port,
bjoern_kwargs=dict(reuse_port=True),
bjoern_kwargs={"reuse_port": True},
)

service.add_setup(
Expand Down
2 changes: 1 addition & 1 deletion exordos_core/cmd/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def main():
),
host=CONF[DOMAIN].bind_host,
port=CONF[DOMAIN].bind_port,
bjoern_kwargs=dict(reuse_port=True),
bjoern_kwargs={"reuse_port": True},
)

service.add_setup(
Expand Down
20 changes: 8 additions & 12 deletions exordos_core/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,31 @@
# under the License.

import logging
import typing as tp

from oslo_config import cfg

from exordos_core import version
from exordos_core.common import constants

LOG = logging.getLogger(__name__)

GLOBAL_SERVICE_NAME = constants.GLOBAL_SERVICE_NAME
_CONFIG_NOT_FOUND_MESSAGE = (
"Unable to find configuration file in the"
" default search paths (~/.%(service_name)s/, ~/,"
" /etc/%(service_name)s/, /etc/) and the '--config-file' option!"
% {"service_name": GLOBAL_SERVICE_NAME}
f"Unable to find configuration file in the"
f" default search paths (~/.{GLOBAL_SERVICE_NAME}/, ~/,"
f" /etc/{GLOBAL_SERVICE_NAME}/, /etc/) and the '--config-file' option!"
)


def parse(args, conf: tp.Optional[cfg.ConfigOpts] = None):
def parse(args, conf: cfg.ConfigOpts | None = None):
if not conf:
conf = cfg.CONF

conf(
args=args,
project=GLOBAL_SERVICE_NAME,
version="%s %s"
% (
GLOBAL_SERVICE_NAME.capitalize(),
version.version_info,
),
version=f"{GLOBAL_SERVICE_NAME.capitalize()} {version.version_info}",
)
if not conf.config_file:
logging.warning(_CONFIG_NOT_FOUND_MESSAGE)
LOG.warning(_CONFIG_NOT_FOUND_MESSAGE)
return conf.config_file
Loading
Loading