UCloud logo UCloud logo UCloud
v2025.1.0
  1. UCloud/Core
  2. 1. Introduction
  3. 2. Projects
  4. 3. Accounting
  5. 4. Orchestration
  6. UCloud/IM for Slurm-based HPC
  7. 5. Installation
  8. 6. Architecture and Networking
  9. 7. User and Project Management
  10. 8. Filesystem Integration
    1. 8.1. Inter-provider file transfers
  11. 9. Slurm Integration
    1. 9.1. Application Management
    2. 9.2. Built-in Applications
  12. 10. Reference
    1. 10.1. Configuration
    2. 10.2. CLI
  13. 11. Appendix
    1. 11.1. Built-in Application Index
  14. UCloud/IM for Kubernetes
  15. 12. Installation
  16. 13. Architecture and Networking
  17. 14. Filesystem Integration
  18. 15. Compute Jobs
    1. 15.1. Public Links
    2. 15.2. Public IPs
    3. 15.3. License Servers
    4. 15.4. SSH Servers
  19. 16. Integrated applications
    1. 16.1. Syncthing
    2. 16.2. Integrated terminal
  20. 17. UCX applications
    1. 17.1. Hello world
    2. 17.2. Data binding
    3. 17.3. UI events
    4. 17.4. Component reference
    5. 17.5. API reference
  21. 18. Reference
    1. 18.1. Configuration
    2. 18.2. CLI
  22. H: Procedures
  23. 19. H: Procedures
  24. 20. H: Introduction
  25. 21. H: Auditing
  26. 22. H: Auditing scenario
  27. 23. H: GitHub actions
  28. 24. H: Deployment
  29. 25. H: 3rd party dependencies (risk assesment)
  1. Links
  2. Source Code
  3. Releases

API reference

This page focuses on the high-level APIs used by UCX applications:

  • ucloud.dk/shared/pkg/ucx/ucxsvc (recommended helpers)
  • ucloud.dk/shared/pkg/ucx/ucxapi (typed RPC calls)

ucxsvc high-level helpers

ucxsvc wraps common stack workflows and resource orchestration.

Stack lifecycle

FunctionPurpose
StackCreate(app, id)Allocate a new stack context and labels/mount metadata
StackWriteFile(stack, path, data)Write stack file with default permissions
StackWriteFileEx(stack, path, data, mode)Write stack file with explicit permissions
StackWriteInitScript(stack, script)Write init script and return labels for VM/job creation
StackConfirmAndOpen(stack)Confirm stack and open it in frontend

Error handling for stack helpers is controlled by the stack state itself. When a stack operation fails, ucxsvc marks stack.Ok = false and sends a user-facing failure message. After this, stack helper calls become safe no-ops, so it is generally safe to keep calling the helper functions in sequence.

If you prefer explicit early exit, check stack.Ok and return immediately:

if !stack.Ok {
    return
}

Resources created as part of a stack are automatically cleaned up if StackConfirmAndOpen(stack) is not called within two minutes of stack creation. As a result, stack flows must end by calling StackConfirmAndOpen(stack). Note that StackConfirmAndOpen(stack) will itself only confirm the stack creation if the internal Ok property is true and it is thus safe to call it without checking the Ok property prior to calling it.

Each stack also has a state directory created automatically by StackCreate(...). StackWriteFile(...) and StackWriteFileEx(...) write files into this directory and are ideal for small initialization scripts and configuration files.

The mount location is controlled by stack.MountPath and can be changed before creating jobs/VMs. By default, stack.MountPath is /etc/ucloud-stack.

Unless explicitly disabled (SkipStackState in VirtualMachineSpec), the state directory is mounted read+write on all jobs/VMs created through stack helpers.

File ownership and permissions in the state directory default to ucloud:ucloud with directory mode 0770. StackWriteFile(...) writes files with default mode 0660 and StackWriteFileEx(...) allows overriding file mode.

StackWriteFile(...) is limited to 64 KiB per file. For more advanced setup logic, prefer init scripts plus custom application/VM images.

Example:

stack, ok := ucxsvc.StackCreate(app, app.JobName)
if !ok {
    return
}

ucxsvc.StackWriteFile(stack, "join-token.txt", util.SecureToken())

// Optional: override default mount path before creating jobs/VMs.
stack.MountPath = "/mnt/ucloud-stack"

initLabels := ucxsvc.StackWriteInitScript(stack, `
    cat /mnt/ucloud-stack/join-token.txt > /var/lib/ucloud/join-token.txt
`)

// Create a VirtualMachineCreate and passing the labels from initLabels.
// NOTE: Only one init script per job is possible. Init scripts are currently 
// only supported by virtual machines.

ucxsvc.StackConfirmAndOpen(stack)

Resource attachments

FunctionReturns
PublicIpCreate(stack)orcapi.AppParameterValue for public IP
PublicLinkCreate(stack, name)orcapi.AppParameterValue for ingress/public link
PrivateNetworkCreate(stack, name)orcapi.AppParameterValue for private network

Jobs and virtual machines

FunctionPurpose
JobCreate(stack, spec)Create a job with stack labels merged automatically
VirtualMachineCreate(stack, spec)Create VM job from VirtualMachineSpec

VirtualMachineSpec fields:

  • Product and Image select machine+app image.
  • Hostname, Attachments, Labels configure VM launch.
  • DiskSize (gigabytes) defaults to 50 if omitted.
  • SkipStackState controls automatic stack state mount attachment.

UI feedback helpers

FunctionEffect
UiSendFailure(app, msg)Show frontend error message
UiSendSuccess(app, msg)Show frontend success message

ucxapi typed RPC calls

ucxapi exposes typed ucx.Rpc[Req, Resp] calls. Standard usage:

session := *app.Session()
products, err := ucxapi.JobsRetrieveProducts.Invoke(session, util.Empty{})
if err != nil {
    ucxsvc.UiSendFailure(app, "Could not retrieve products")
    return
}

Stack RPCs

RPCRequestResponse
StackAvailablefndapi.FindByStringIdbool
StackCreateucxapi.StackCreateRequestucxapi.Stack
StackDataWriteucxapi.StackDataWriteRequestutil.Empty
StackConfirmfndapi.FindByStringIdutil.Empty
StackOpenfndapi.FindByStringIdutil.Empty

Job RPCs

RPC
JobsCreate
JobsBrowse
JobsRetrieve
JobsRename
JobsTerminate
JobsExtend
JobsSuspend
JobsUnsuspend
JobsRetrieveProducts

Networking RPCs

DomainRPCs
Public linksPublicLinksCreate, PublicLinksDelete, PublicLinksBrowse, PublicLinksRetrieve, PublicLinksUpdateLabels, PublicLinksRetrieveProducts
Public IPsPublicIpsCreate, PublicIpsDelete, PublicIpsBrowse, PublicIpsRetrieve, PublicIpsUpdateLabels, PublicIpsUpdateFirewall, PublicIpsRetrieveProducts
Private networksPrivateNetworksCreate, PrivateNetworksDelete, PrivateNetworksBrowse, PrivateNetworksRetrieve, PrivateNetworksUpdateLabels, PrivateNetworksRetrieveProducts

Storage and license RPCs

DomainRPCs
DrivesDrivesCreate, DrivesDelete, DrivesBrowse, DrivesRetrieve, DrivesRename, DrivesUpdateLabels, DrivesRetrieveProducts
LicensesLicensesCreate, LicensesDelete, LicensesBrowse, LicensesRetrieve, LicensesUpdateLabels, LicensesRetrieveProducts

UI RPCs

RPCPurpose
UiSendMessageShow a success/error message in the frontend

Notes on choosing API level

  • Use ucxsvc first for stack-oriented flows.
  • Use direct ucxapi calls when you need full control or unsupported operations.
  • Keep user-visible errors explicit (UiSendFailure) when RPC/resource operations fail.
Previous Component reference
Next Reference