Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should I import to use API ? #3343

Closed
redcap52 opened this issue Jun 16, 2019 · 5 comments
Closed

What should I import to use API ? #3343

redcap52 opened this issue Jun 16, 2019 · 5 comments
Assignees
Labels
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@redcap52
Copy link

In your docs you said that you have an API for Golang. So, what path should I import to use CreateContainer() method ?

@redcap52 redcap52 changed the title What shoul I import to use API ? What should I import to use API ? Jun 16, 2019
@mheon
Copy link
Member

mheon commented Jun 23, 2019

To confirm, we're talking about the Golang API, not the Varlink one, correct?

For the Go API:

Our core API functions live in github.com/containers/libpod, with image functions specifically available in the github.com/containers/libpod/image subpackage.

Also note that any code calling into Libpod via the Go API must contain the following bit of code somewhere early in main (necessary to make containers/storage work properly):
https://github.com/containers/libpod/blob/master/cmd/podman/main.go#L144-L146

@mheon
Copy link
Member

mheon commented Jun 23, 2019

@baude I'm fairly certain this one is Varlink, though. There's no CreateContainer endpoint in the Go code, we call it NewContainer() there.

@mheon mheon assigned baude and unassigned mheon Jun 23, 2019
@baude
Copy link
Member

baude commented Jun 24, 2019

@redcap52 can you please clarify your question here given @mheon's answer?

@towe75
Copy link
Contributor

towe75 commented Jun 27, 2019

@redcap52 maybe you want to have a look at my related question in #3445

I endet up with this working example program:

package main

import (
	"context"

	"github.com/containers/storage/pkg/reexec"
	"github.com/containers/libpod/libpod"
	"github.com/sirupsen/logrus"
)

func main() {

	if reexec.Init() {
		return
	}

	logrus.SetLevel(logrus.TraceLevel)
	logrus.Info("Getting Runtime")

	ctx := context.TODO()
	runtime, err := libpod.NewRuntime(ctx)
	if err != nil {
		logrus.Fatal("Error creating runtime", err)
		return
	}

	containers, err := runtime.GetContainers()
	if err != nil {
		logrus.Fatal("Error listing containers", err)
		return
	}

	for _, c := range(containers) {
		logrus.Info("Found container: ", c.Name())
	}

	runtime.Shutdown(false)

}

@baude it would be nice to have some small api example like this in the docs, what do you think?
Obviously it's hard to get started on this topic.

@baude
Copy link
Member

baude commented Aug 2, 2019

@redcap52 re-open as needed.

@baude baude closed this as completed Aug 2, 2019
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

4 participants