Connectors

Connectors can be defined to allow two nodes to be linked. While it's up to the plugin itself to maintain the list of connectors typically the engine plugin will interpret and honour the links.

The properties which defined a connector are listed below.

  • name - connector name shown in the interface
  • type - type used to validate connections
  • accepts - array of ConnectionType that the connector accepts
  • props - object for storing metadata about the connector

Defining connectors

To define the connectors which are generated when the prototype is created you must return them in the createPrototype method for your plugin.

import { Export, IAppModel, createAppModel, createConnectorModel } from '@icepanel/core'

@Export()
static createPrototype(prototype: IPrototypeModel, name: string): IAppModel {
  return {
    ...createAppModel(),
    engine: {
      image: 'httpd:latest'
    },
    connectors: [
      {
        ...createConnectorModel(),
        name: 'network',
        type: 'network'
      },
      {
        ...createConnectorModel(),
        name: 'public-html',
        type: 'mount',
        props: {
          path: '/usr/local/apache2/htdocs/'
        }
      }
    ]
  }
}

Connector links

The prototype and environment models both contain an array of links which have been made. Links are directional and have both an origin and target property. Both target and origin both contain the id of the node they are linked to as well as the id for the individual connector the link has been created on.

const volumeConnector = this.model.connectors.find(o => o.type === 'mount')
if (volumeConnector) {
  const link = this.environmentModel.links.find(o => o.target.connector === volumeConnector.id)
  if (link) {
    const volumeId = link.origin.id
    const volumeConnector = link.origin.connector
    console.log(`the mount point is connected to volume ${volumeId} on connector ${volumeConnector}`)
  }
}