UCloud logo UCloud logo UCloud
v2026.3.0
  1. UCloud/Core
  2. 1. Introduction
  3. 2. Projects
  4. 3. Accounting
  5. 4. Orchestration
  6. 5. Frontend
  7. UCloud/IM for Slurm-based HPC
  8. 6. Installation
  9. 7. Architecture and Networking
  10. 8. User and Project Management
  11. 9. Filesystem Integration
    1. 9.1. Inter-provider file transfers
  12. 10. Slurm Integration
    1. 10.1. Application Management
    2. 10.2. Built-in Applications
  13. 11. Reference
    1. 11.1. Configuration
    2. 11.2. CLI
  14. 12. Appendix
    1. 12.1. Built-in Application Index
  15. UCloud/IM for Kubernetes
  16. 13. Installation
  17. 14. Architecture and Networking
  18. 15. Filesystem Integration
  19. 16. Compute Jobs
    1. 16.1. Public Links
    2. 16.2. Public IPs
    3. 16.3. License Servers
    4. 16.4. SSH Servers
    5. 16.5. Job Audit Log
    6. 16.6. Virtual machines
  20. 17. Integrated applications
    1. 17.1. Syncthing
    2. 17.2. Integrated terminal
  21. 18. UCX applications
    1. 18.1. Hello world
    2. 18.2. Data binding
    3. 18.3. UI events
    4. 18.4. Component reference
    5. 18.5. API reference
  22. 19. Reference
    1. 19.1. Configuration
    2. 19.2. CLI
  23. Branding for UCloud
  24. 20. Branding and identity for UCloud
  25. H: Procedures
  26. 21. H: Procedures
  27. 22. H: Introduction
  28. 23. H: Auditing
  29. 24. H: Auditing scenario
  30. 25. H: GitHub actions
  31. 26. H: Deployment
  32. 27. 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, stackType)Allocate a new stack context and labels/mount metadata
StackFromJob(app, job)Reconstruct stack context from a job with stack labels
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
StackCopyFile(stack, fileName)Ask frontend to copy stack file contents to clipboard
StackDownloadFile(stack, fileName)Ask frontend to download stack file
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, "Kubernetes")
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)

Reconstructing stack context in job-connected UCX

If your job session includes stack labels, reconstruct the stack directly from SysHello job context:

type app struct {
    // ...
    Stack *ucxsvc.Stack `ucx:"-"`
}

func (app *app) OnSysHello(payload string) {
    var req orcapi.AppUcxConnectJobProviderRequest
    if err := json.Unmarshal([]byte(payload), &req); err != nil {
        return
    }

    stack, ok := ucxsvc.StackFromJob(app, req.Job)
    if ok {
        app.Stack = stack
    }
}

StackFromJob(...) resolves mount path from job file attachments when available and falls back to /etc/ucloud-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
RouterPushPage(app, path)Programmatically push UCX router path (p)

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
StackRefreshutil.Emptyutil.Empty
StackCopyFileucxapi.StackDownloadFileRequestutil.Empty
StackDownloadFileucxapi.StackDownloadFileRequestutil.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
RouterPushPageFrontend-only: push route path (p query parameter)

RouterPushPage has the same effect as clicking ucx.Link(...). It is implemented by the stack page frontend and only available in job-connected UCX sessions.

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