示例#1
0
文件: resource.go 项目: docker/docker
// DetachNetwork deletes a network attachment.
func (r *resourceAllocator) DetachNetwork(ctx context.Context, aID string) error {
	return r.agent.withSession(ctx, func(session *session) error {
		client := api.NewResourceAllocatorClient(session.conn.ClientConn)
		_, err := client.DetachNetwork(ctx, &api.DetachNetworkRequest{
			AttachmentID: aID,
		})

		return err
	})
}
示例#2
0
文件: resource.go 项目: docker/docker
// AttachNetwork creates a network attachment.
func (r *resourceAllocator) AttachNetwork(ctx context.Context, id, target string, addresses []string) (string, error) {
	var taskID string
	if err := r.agent.withSession(ctx, func(session *session) error {
		client := api.NewResourceAllocatorClient(session.conn.ClientConn)
		r, err := client.AttachNetwork(ctx, &api.AttachNetworkRequest{
			Config: &api.NetworkAttachmentConfig{
				Target:    target,
				Addresses: addresses,
			},
			ContainerID: id,
		})
		if err != nil {
			return err
		}
		taskID = r.AttachmentID
		return nil
	}); err != nil {
		return "", err
	}

	return taskID, nil
}