Newer
Older
"code.fbi.h-da.de/cocsn/gosdn/internal/database"
"code.fbi.h-da.de/cocsn/gosdn/internal/log"
"code.fbi.h-da.de/cocsn/gosdn/internal/nucleus/interfaces"
"code.fbi.h-da.de/cocsn/gosdn/internal/restconf/util"
"crypto/tls"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"net/http"
)
//MCPClient handles requests to a Ciena MCP RESTCONF endpoint
type MCPClient struct {
transport *httptransport.Runtime
client *apiclient.ServiceTopologyTAPI
// GetConfig returns a ClientConfig struct containing
// the current configuration stat of the Ciena SBI client
func (c MCPClient) GetConfig() interfaces.ClientConfig {
return *c.config
//NewMCPClient creates a Ciena flavores TAPI client
func NewMCPClient(endpoint, username, password string, database *database.Database, config *interfaces.ClientConfig) *MCPClient {
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
// create the API client, with the transport
basicAuth := httptransport.BasicAuth(username, password)
// authenticate client
transport.DefaultAuthentication = basicAuth
buffer := new(bytes.Buffer)
transport.Consumers[runtime.JSONMime] = util.YANGConsumer{Data: buffer}
database: database,
buffer: buffer,
// GetConnections implements the TAPI Connectivity GetConnections call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
_, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil)
c.database.StoreConnections(c.buffer.String())
log.Debug(c.buffer.Next(25))
// GetLinks implements the TAPI Topology GetLinks call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
func (c *MCPClient) GetLinks() error {
defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil)
log.Debug(c.buffer.Next(25))
return err
}
// GetNodes implements the TAPI Topology GetNodes call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil)
c.database.StoreNodes(c.buffer.String())
log.Debug(c.buffer.Next(25))
// GetNodeEdgePoints implements the TAPI Topology GetNodeEdgePoints call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil)
c.database.StoreNodeEdgePoints(c.buffer.String())
log.Debug(c.buffer.Next(25))