Пример #1
0
// 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
// 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
}