// AddDockerResource adds a docker resource against id.
777047
func (c FakeClient) AddDockerResource(id *charm.URL, resourceName string, imageName, digest string) (revision int, err error) {
	return -1, nil
}
646382
func (s *Service) CreateSource(ctx context.Context, src *platform.Source) error {
	src.ID = s.IDGenerator.ID()
	if err := s.PutSource(ctx, src); err != nil {
		return &platform.Error{
			Err: err,
		}
	}
	return nil
}
591815
func (s *Staert) AddSource(src Source) {
	s.sources = append(s.sources, src)
}
1196733
func NewResource(rl v1.ResourceList) *Resource {
	r := &Resource{}
	r.Add(rl)
	return r
}
170729
func (rco RunContainerOptions) asDockerCreateContainerOptions() dockertypes.ContainerCreateConfig {
	config := rco.asDockerConfig()
	hostConfig := rco.asDockerHostConfig()
	return dockertypes.ContainerCreateConfig{
		Name:       containerName(rco.Image),
		Config:     &config,
		HostConfig: &hostConfig,
	}
}
1001447
func (s *Server) UpdateContainerResources(ctx context.Context, req *pb.UpdateContainerResourcesRequest) (resp *pb.UpdateContainerResourcesResponse, err error) {
	const operation = "update_container_resources"
	defer func() {
		recordOperation(operation, time.Now())
		recordError(operation, err)
	}()
	logrus.Debugf("UpdateContainerResources %+v", req)

	c, err := s.GetContainerFromShortID(req.GetContainerId())
	if err != nil {
		return nil, err
	}
	state := c.State()
	if !(state.Status == oci.ContainerStateRunning || state.Status == oci.ContainerStateCreated) {
		return nil, fmt.Errorf("container %s is not running or created state: %s", c.ID(), state.Status)
	}

	resources := toOCIResources(req.GetLinux())
	if err := s.Runtime().UpdateContainer(c, resources); err != nil {
		return nil, err
	}
	return &pb.UpdateContainerResourcesResponse{}, nil
}
600494
func ParseFullDockerRegistryURL(s string) (*DockerRegistryURL, error) {
	s = handleSchemelessQuayRegistries(s)

	registryURL := &DockerRegistryURL{
		Scheme: "https",
	}

	u, err := url.Parse(s)
	if err != nil {
		return nil, err
	}

	if u.Scheme == "" || u.Host == "" {
		return registryURL, fmt.Errorf("Registry URL must provide a scheme and host: %q", s)
	}

	registryURL.Scheme = u.Scheme
	registryURL.Userinfo = u.User

	host, port, err := splitHostPort(u.Host)
	if err != nil {
		return nil, err
	}
	registryURL.Host = host
	registryURL.Port = port

	// Parse everything after <scheme>://<host>:<port>
	err = registryURL.parsePath(u.Path)
	if err != nil {
		return nil, err
	}
	return registryURL, nil
}
456354
func (dh *Client) CreateContainer(options *docker.ContainerConfig, name string) (containerId string, e error) {
	imageId := options.Image

	// Verify image available on host.
	_, e = dh.ImageHistory(imageId)
	if e != nil && e.Error() == "resource not found" {
		if e = dh.PullImage(imageId); e != nil {
			return "", e
		}
	}

	imgDetails, err := dh.ImageDetails(imageId)
	if err != nil {
		return "", err
	}
	options.Env = append(options.Env, "DOCKER_IMAGE="+imgDetails.Id)

	container := &docker.Container{}
	u := dh.Address + "/containers/create"

	if name != "" {
		u += "?name=" + name
	}

	if _, e = dh.postJSON(u, options, container); e != nil {
		return "", fmt.Errorf("failed creating container: %s", e.Error())
	}
	return container.Id, e
}
648342
func NewSourceRepositoryForDockerfile(contents string) (*SourceRepository, error) {
	s := &SourceRepository{
		ignoreRepository: true,
		strategy:         newapp.StrategyDocker,
	}
	err := s.AddDockerfile(contents)
	return s, err
}
1133999
func (r *SearchRequest) FetchSource(fetchSource bool) *SearchRequest {
	r.searchSource = r.searchSource.FetchSource(fetchSource)
	return r
}
1314239
func (configMgr *ConfigurationManager) AddSource(source core.ConfigSource, priority int) error {
	if source == nil || source.GetSourceName() == "" {
		err := errors.New("nil or invalid source supplied")
		openlogging.GetLogger().Error("nil or invalid source supplied: " + err.Error())
		return err
	}

	configMgr.sourceMapMux.Lock()
	sourceName := source.GetSourceName()

	_, ok := configMgr.Sources[sourceName]
	if ok {
		err := errors.New("duplicate source supplied")
		openlogging.GetLogger().Error("duplicate source supplied: " + err.Error())
		configMgr.sourceMapMux.Unlock()
		return err
	}

	configMgr.Sources[sourceName] = source
	configMgr.sourceMapMux.Unlock()

	err := configMgr.pullSourceConfigs(sourceName)
	if err != nil {
		err = fmt.Errorf("fail to load configuration of %s source: %s", sourceName, err)
		openlogging.Error(err.Error())
		return err
	}
	openlogging.Info("invoke dynamic handler:" + source.GetSourceName())
	go source.DynamicConfigHandler(configMgr)

	return nil
}
1248212
func (d *DockerMonitor) addHandler(event Event, handler EventHandler) {
	d.handlers[event] = handler
}
815076
func (c *CustomResourceProvisioner) add(resourceName string, p customresources.Provisioner) {
	// Wrap the provisioner with timeouts.
	p = customresources.WithTimeout(p, ProvisioningTimeout, ProvisioningGraceTimeout)
	c.Provisioners[resourceName] = withMetrics(p)
}
117679
func (r *SourceRepository) AddDockerfile(contents string) error {
	dockerfile, err := NewDockerfile(contents)
	if err != nil {
		return err
	}
	if r.info == nil {
		r.info = &SourceRepositoryInfo{}
	}
	r.info.Dockerfile = dockerfile
	r.SetStrategy(newapp.StrategyDocker)
	r.forceAddDockerfile = true
	return nil
}
1023815
func (t *Template) AddResource(resource NamedResource) {
	if _, ok := t.Resources[resource.Name]; ok {
		panic(fmt.Sprintf("%s is already defined in the template", resource.Name))
	}
	t.Resources[resource.Name] = resource.Resource
}
619307
func (pdev podDevices) addContainerAllocatedResources(podUID, contName string, allocatedResources map[string]sets.String) {
	containers, exists := pdev[podUID]
	if !exists {
		return
	}
	resources, exists := containers[contName]
	if !exists {
		return
	}
	for resource, devices := range resources {
		allocatedResources[resource] = allocatedResources[resource].Union(devices.deviceIds)
	}
}
1035769
func NewDockerClient(host, certPath string) (*docker.Client, error) {
	if certPath != "" {
		cert := certPath + "/cert.pem"
		key := certPath + "/key.pem"
		ca := certPath + "/ca.pem"
		return docker.NewTLSClient(host, cert, key, ca)
	}

	return docker.NewClient(host)
}