Artificial SMB File Sharing Protocol Resource Library#

This page has all the information specific to the SMB file sharing protocol resource libary.

SMB pyproject.toml Dependencies#

To add SMB support to your adapter, run the command

uv add artificial-smb-resource-library==0.0.*

Your pyproject.toml file should now include artificial-smb-resource-library in the project dependencies section:

[project]
dependencies = [
  "artificial-smb-resource-library==0.0.*",
]

Venus Adapter config.yaml File#

config.yaml#
log:
  level: "DEBUG"
  loggerLevels:
    - logger: "tutorial"
      level: "DEBUG"

artificial:
  host: your-instance.artificial.com
  lab: lab_1a2b3c-4d5e-6f7g-8h9i-123456abcdef

adapter:
  name: SmbTutorialAdapter
  remoteConfig: True
  allowAnySequenceId: True # Useful when running in a local dev container
  1. Update the artificial section to the correct host and lab. Consult the corresponding step in Hardware-Specific Adapter Setup for how to do this.

Note

When you configure the adapter in LabOps, enter the ip address as just the server name or ip address, no http:// needed. Also, fill in the username and password.

SMB adapter/main/plugin.py File#

adapter/main/plugin.py file#
from artificial.adapter_common import ActionModulePlugin, action_modules
from artificial.adapter_common.plugin import PluginContext, plugin_config
from artificial.logging import get_logger
from artificial.smb.actions import SMBActions
from artificial.smb.config.config import SMBConfig

logger = get_logger(__name__)

@action_modules(SMBActions)
class AdapterPlugin(ActionModulePlugin):
    cfg = plugin_config(SMBConfig)

    async def setup(self, pctx: PluginContext) -> None:
        self.add_module(SMBActions(self.cfg))

SMB Adapter adapter/main/__main__.py File#

Copy the following list of actors into the file in place of the example actors.

actors = [
    ActorConfig(id='smb', abilities={'smb': 1}),
]

SMB Sample Workflow#

This workflow will get the list of files at the given path and display that in Artificial. For path enter only the shared file path, no server name needed, e.g. smb\test.

After copying this code into a file, remember to replace the lab_guid in the workflow heading with the one from your Lab (most easily found by opening the Lab in Artificial and looking in the browser address bar). Consult Adding and Running a Simple Connectivity Test Workflow for more info.

from artificial.workflows.decorators import parameter, workflow
from artificial.workflows.runtime import show_info
from stubs.stubs_actions import get_files


@parameter('smb_folder_path', {'required': True, 'uiTitle': 'Folder Path'})
@workflow('Simple SMB Test Workflow', 'simple_smb_workflow', 'lab_3d1485d1-020b-40cd-8acd-c2226eea164d')
async def simple_smb_workflow(smb_folder_path: str) -> None:
    files = await get_files(smb_folder_path=smb_folder_path)
    filestring = 'The files at that path are: '
    for file in files:
        filestring += file + ', '
    await show_info(filestring)
    await show_info('Congratulations, you successfully ran the SMB workflow!', 'Hardware Success')

Full SMB API#

class SMBConfig(smbuser: str, smbpass: str, ipaddress: str)#
ipaddress: str#
smbpass: str#
smbuser: str#
classmethod testing(**kwargs: Any) SMBConfig#

Uninitialized config for testing purposes

class SMBActions(cfg: SMBConfig)#
async async_io_custom_executor(
function: Callable,
*args: Any,
**kwargs: Any,
) Any#
async create_directory(
actx: ActionExecutionContext,
smb_folder_path: str,
) str#
async get_files(
_: ActionExecutionContext,
smb_folder_path: str,
) List[str]#
async path_exists(
actx: ActionExecutionContext,
smb_folder_path: str,
) bool#
async read_file(
actx: ActionExecutionContext,
smb_folder_path: str,
file_name: str,
) bytes#
async write_file(
actx: ActionExecutionContext,
smb_folder_path: str,
file_name: str,
contents: str | bytes,
) None#
async write_request_input_file(
actx: ActionExecutionContext,
smb_folder_path: str,
file_name: str,
contents_b64: str,
) None#