SclObject

Trait SclObject 

Source
pub trait SclObject:
    Clone
    + DeserializeOwned
    + Eq
    + Ord
    + PartialEq
    + PartialOrd
    + Serialize {
    const PREFIX: &'static str;

    // Required methods
    fn name(&self) -> &SclName;
    fn metadata(&self) -> &MetaData;
    fn metadata_mut(&mut self) -> &mut MetaData;
    fn referenced_db_keys(&self) -> Vec<String>;
    fn validate_fields_before_create(&self) -> Result<()>;
    fn validate_fields_before_update(
        current_db_state: &Self,
        proposed_new_state: &Self,
    ) -> Result<()>;

    // Provided methods
    fn uuid(&self) -> Uuid { ... }
    fn separation_context(&self) -> Option<&SclName> { ... }
    fn api_endpoint<'a>(
        sc: impl Into<Option<&'a str>>,
        name: impl Into<Option<&'a str>>,
    ) -> String { ... }
    fn get_api_endpoint(&self) -> String { ... }
    fn db_key<'a>(
        sc: impl Into<Option<&'a str>>,
        name: impl Into<Option<&'a str>>,
    ) -> String { ... }
    fn get_db_key(&self) -> String { ... }
}
Expand description

This trait is implemented by all SCL API objects to provide uniform access to common properties of the objects.

Required Associated Constants§

Source

const PREFIX: &'static str

Constant prefix to identify the objects root.

The prefix is used for both API endpoint and DB key construction and must start with a "/".

Required Methods§

Source

fn name(&self) -> &SclName

Returns the SclName of the SclObject.

Source

fn metadata(&self) -> &MetaData

Providing access to MetaData is essential for our optimistic concurrency control.

Source

fn metadata_mut(&mut self) -> &mut MetaData

Providing access to MetaData is essential for our optimistic concurrency control.

Source

fn referenced_db_keys(&self) -> Vec<String>

Returns all DB keys the object is referencing / depending on.

Source

fn validate_fields_before_create(&self) -> Result<()>

Checks if all fields (except references to other SclObjects) are legal initial fields. Should be called before a create operation.

Source

fn validate_fields_before_update( current_db_state: &Self, proposed_new_state: &Self, ) -> Result<()>

Checks if a proposed updated is valid. Should be called before a regular (not related to finalizers / deletion) update operation.

Provided Methods§

Source

fn uuid(&self) -> Uuid

Source

fn separation_context(&self) -> Option<&SclName>

Returns the SclName of the separation context if the SclObject is connected to one, otherwise default None.

Source

fn api_endpoint<'a>( sc: impl Into<Option<&'a str>>, name: impl Into<Option<&'a str>>, ) -> String

Returns the API endpoint for a SclObject.

§Examples
use scl_lib::api_objects::{Controller, SclObject, VirtualMachine, Volume};

assert_eq!(VirtualMachine::api_endpoint("sc-01", "vm-01"), "/scs/sc-01/vms/vm-01");
assert_eq!(Controller::api_endpoint(None, "ctrl-01"), "/controllers/ctrl-01");
assert_eq!(Volume::api_endpoint("sc-01", None), "/scs/sc-01/volumes");
Source

fn get_api_endpoint(&self) -> String

Returns the API endpoint of the SclObject.

§Examples
use std::convert::TryFrom;
use scl_lib::api_objects::{Controller, ControllerKind, SclName, SclObject};

let ctrl = Controller::new(
    SclName::try_from("ctrl-01".to_string()).unwrap(),
    ControllerKind::VmController);

assert_eq!(ctrl.get_api_endpoint(), "/controllers/ctrl-01");
Source

fn db_key<'a>( sc: impl Into<Option<&'a str>>, name: impl Into<Option<&'a str>>, ) -> String

Returns the database key for a SclObject.

§Examples
use scl_lib::api_objects::{Controller, SclObject, VirtualMachine, Volume};

assert_eq!(VirtualMachine::db_key("sc-01", "vm-01"), "/vms/sc-01/vm-01");
assert_eq!(Controller::db_key(None, "ctrl-01"), "/controllers/ctrl-01");
assert_eq!(Volume::db_key("sc-01", None), "/volumes/sc-01");
Source

fn get_db_key(&self) -> String

Returns the database key of the SclObject.

§Examples
use std::convert::TryFrom;
use scl_lib::api_objects::{Controller, ControllerKind, SclName, SclObject};

let ctrl = Controller::new(
    SclName::try_from("ctrl-01".to_string()).unwrap(),
    ControllerKind::VmController);

assert_eq!(ctrl.get_db_key(), "/controllers/ctrl-01");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl SclObject for AvailableVlanTags

Source§

const PREFIX: &'static str = "/vars/vlan-tags"

Source§

impl SclObject for Controller

Source§

const PREFIX: &'static str = "/controllers"

Source§

impl SclObject for Node

Source§

const PREFIX: &'static str = "/nodes"

Source§

impl SclObject for Router

Source§

const PREFIX: &'static str = "/routers"

Source§

impl SclObject for SeparationContext

Source§

const PREFIX: &'static str = "/scs"

Source§

impl SclObject for VirtualMachine

Source§

const PREFIX: &'static str = "/vms"

Source§

impl SclObject for Volume

Source§

const PREFIX: &'static str = "/volumes"