Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2276)

Side by Side Diff: environs/config/config.go

Issue 94410043: Use lxc clone by default (Closed)
Patch Set: Use lxc clone by default Created 9 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package config 4 package config
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "io/ioutil" 8 "io/ioutil"
9 "os" 9 "os"
10 "os/exec" 10 "os/exec"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if oldToolsURL := cfg.defined["tools-url"]; oldToolsURL != nil && oldToo lsURL.(string) != "" { 251 if oldToolsURL := cfg.defined["tools-url"]; oldToolsURL != nil && oldToo lsURL.(string) != "" {
252 _, newToolsSpecified := cfg.ToolsURL() 252 _, newToolsSpecified := cfg.ToolsURL()
253 // Ensure the new attribute name "tools-metadata-url" is set. 253 // Ensure the new attribute name "tools-metadata-url" is set.
254 if !newToolsSpecified { 254 if !newToolsSpecified {
255 cfg.defined["tools-metadata-url"] = oldToolsURL 255 cfg.defined["tools-metadata-url"] = oldToolsURL
256 } 256 }
257 } 257 }
258 // Even if the user has edited their environment yaml to remove the depr ecated tools-url value, 258 // Even if the user has edited their environment yaml to remove the depr ecated tools-url value,
259 // we still want it in the config for upgrades. 259 // we still want it in the config for upgrades.
260 cfg.defined["tools-url"], _ = cfg.ToolsURL() 260 cfg.defined["tools-url"], _ = cfg.ToolsURL()
261
262 // Copy across lxc-use-clone to lxc-clone.
263 if lxcUseClone, ok := cfg.defined["lxc-use-clone"]; ok {
264 _, newValSpecified := cfg.LXCUseClone()
265 // Ensure the new attribute name "lxc-clone" is set.
266 if !newValSpecified {
267 cfg.defined["lxc-clone"] = lxcUseClone
268 }
269 }
270
261 // Update the provider type from null to manual. 271 // Update the provider type from null to manual.
262 if cfg.Type() == "null" { 272 if cfg.Type() == "null" {
263 cfg.defined["type"] = "manual" 273 cfg.defined["type"] = "manual"
264 } 274 }
265 } 275 }
266 276
267 // Validate ensures that config is a valid configuration. If old is not nil, 277 // Validate ensures that config is a valid configuration. If old is not nil,
268 // it holds the previous environment configuration for consideration when 278 // it holds the previous environment configuration for consideration when
269 // validating changes. 279 // validating changes.
270 func Validate(cfg, old *Config) error { 280 func Validate(cfg, old *Config) error {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 703
694 // TestMode indicates if the environment is intended for testing. 704 // TestMode indicates if the environment is intended for testing.
695 // In this case, accessing the charm store does not affect statistical 705 // In this case, accessing the charm store does not affect statistical
696 // data of the store. 706 // data of the store.
697 func (c *Config) TestMode() bool { 707 func (c *Config) TestMode() bool {
698 return c.defined["test-mode"].(bool) 708 return c.defined["test-mode"].(bool)
699 } 709 }
700 710
701 // LXCUseClone reports whether the LXC provisioner should create a 711 // LXCUseClone reports whether the LXC provisioner should create a
702 // template and use cloning to speed up container provisioning. 712 // template and use cloning to speed up container provisioning.
703 func (c *Config) LXCUseClone() bool { 713 func (c *Config) LXCUseClone() (bool, bool) {
704 » v, _ := c.defined["lxc-use-clone"].(bool) 714 » v, ok := c.defined["lxc-clone"].(bool)
705 » return v 715 » return v, ok
716 }
717
718 // LXCUseCloneAUFS reports whether the LXC provisioner should create a
719 // lxc clone using aufs if available.
720 func (c *Config) LXCUseCloneAUFS() (bool, bool) {
721 » v, ok := c.defined["lxc-clone-aufs"].(bool)
722 » return v, ok
706 } 723 }
707 724
708 // UnknownAttrs returns a copy of the raw configuration attributes 725 // UnknownAttrs returns a copy of the raw configuration attributes
709 // that are supposedly specific to the environment type. They could 726 // that are supposedly specific to the environment type. They could
710 // also be wrong attributes, though. Only the specific environment 727 // also be wrong attributes, though. Only the specific environment
711 // implementation can tell. 728 // implementation can tell.
712 func (c *Config) UnknownAttrs() map[string]interface{} { 729 func (c *Config) UnknownAttrs() map[string]interface{} {
713 newAttrs := make(map[string]interface{}) 730 newAttrs := make(map[string]interface{})
714 for k, v := range c.unknown { 731 for k, v := range c.unknown {
715 newAttrs[k] = v 732 newAttrs[k] = v
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 "ftp-proxy": schema.String(), 791 "ftp-proxy": schema.String(),
775 "no-proxy": schema.String(), 792 "no-proxy": schema.String(),
776 "apt-http-proxy": schema.String(), 793 "apt-http-proxy": schema.String(),
777 "apt-https-proxy": schema.String(), 794 "apt-https-proxy": schema.String(),
778 "apt-ftp-proxy": schema.String(), 795 "apt-ftp-proxy": schema.String(),
779 "bootstrap-timeout": schema.ForceInt(), 796 "bootstrap-timeout": schema.ForceInt(),
780 "bootstrap-retry-delay": schema.ForceInt(), 797 "bootstrap-retry-delay": schema.ForceInt(),
781 "bootstrap-addresses-delay": schema.ForceInt(), 798 "bootstrap-addresses-delay": schema.ForceInt(),
782 "test-mode": schema.Bool(), 799 "test-mode": schema.Bool(),
783 "proxy-ssh": schema.Bool(), 800 "proxy-ssh": schema.Bool(),
784 » "lxc-use-clone": schema.Bool(), 801 » "lxc-clone": schema.Bool(),
802 » "lxc-clone-aufs": schema.Bool(),
785 803
786 // Deprecated fields, retain for backwards compatibility. 804 // Deprecated fields, retain for backwards compatibility.
787 » "tools-url": schema.String(), 805 » "tools-url": schema.String(),
806 » "lxc-use-clone": schema.Bool(),
788 } 807 }
789 808
790 // alwaysOptional holds configuration defaults for attributes that may 809 // alwaysOptional holds configuration defaults for attributes that may
791 // be unspecified even after a configuration has been created with all 810 // be unspecified even after a configuration has been created with all
792 // defaults filled out. 811 // defaults filled out.
793 // 812 //
794 // This table is not definitive: it specifies those attributes which are 813 // This table is not definitive: it specifies those attributes which are
795 // optional when the config goes through its initial schema coercion, 814 // optional when the config goes through its initial schema coercion,
796 // but some fields listed as optional here are actually mandatory 815 // but some fields listed as optional here are actually mandatory
797 // with NoDefaults and are checked at the later Validate stage. 816 // with NoDefaults and are checked at the later Validate stage.
(...skipping 10 matching lines...) Expand all
808 "bootstrap-retry-delay": schema.Omit, 827 "bootstrap-retry-delay": schema.Omit,
809 "bootstrap-addresses-delay": schema.Omit, 828 "bootstrap-addresses-delay": schema.Omit,
810 "rsyslog-ca-cert": schema.Omit, 829 "rsyslog-ca-cert": schema.Omit,
811 "http-proxy": schema.Omit, 830 "http-proxy": schema.Omit,
812 "https-proxy": schema.Omit, 831 "https-proxy": schema.Omit,
813 "ftp-proxy": schema.Omit, 832 "ftp-proxy": schema.Omit,
814 "no-proxy": schema.Omit, 833 "no-proxy": schema.Omit,
815 "apt-http-proxy": schema.Omit, 834 "apt-http-proxy": schema.Omit,
816 "apt-https-proxy": schema.Omit, 835 "apt-https-proxy": schema.Omit,
817 "apt-ftp-proxy": schema.Omit, 836 "apt-ftp-proxy": schema.Omit,
837 "lxc-clone": schema.Omit,
818 838
819 // Deprecated fields, retain for backwards compatibility. 839 // Deprecated fields, retain for backwards compatibility.
820 » "tools-url": "", 840 » "tools-url": "",
841 » "lxc-use-clone": schema.Omit,
821 842
822 // For backward compatibility reasons, the following 843 // For backward compatibility reasons, the following
823 // attributes default to empty strings rather than being 844 // attributes default to empty strings rather than being
824 // omitted. 845 // omitted.
825 // TODO(rog) remove this support when we can 846 // TODO(rog) remove this support when we can
826 // remove upgrade compatibility with versions prior to 1.14. 847 // remove upgrade compatibility with versions prior to 1.14.
827 "admin-secret": "", // TODO(rog) omit 848 "admin-secret": "", // TODO(rog) omit
828 "ca-private-key": "", // TODO(rog) omit 849 "ca-private-key": "", // TODO(rog) omit
829 "image-metadata-url": "", // TODO(rog) omit 850 "image-metadata-url": "", // TODO(rog) omit
830 "tools-metadata-url": "", // TODO(rog) omit 851 "tools-metadata-url": "", // TODO(rog) omit
831 852
832 "default-series": "", 853 "default-series": "",
833 854
834 // For backward compatibility only - default ports were 855 // For backward compatibility only - default ports were
835 // not filled out in previous versions of the configuration. 856 // not filled out in previous versions of the configuration.
836 "state-port": DefaultStatePort, 857 "state-port": DefaultStatePort,
837 "api-port": DefaultAPIPort, 858 "api-port": DefaultAPIPort,
838 "syslog-port": DefaultSyslogPort, 859 "syslog-port": DefaultSyslogPort,
839 // Authentication string sent with requests to the charm store 860 // Authentication string sent with requests to the charm store
840 "charm-store-auth": "", 861 "charm-store-auth": "",
841 // Previously image-stream could be set to an empty value 862 // Previously image-stream could be set to an empty value
842 » "image-stream": "", 863 » "image-stream": "",
843 » "test-mode": false, 864 » "test-mode": false,
844 » "proxy-ssh": false, 865 » "proxy-ssh": false,
845 » "lxc-use-clone": false, 866 » "lxc-clone-aufs": false,
846 } 867 }
847 868
848 func allowEmpty(attr string) bool { 869 func allowEmpty(attr string) bool {
849 return alwaysOptional[attr] == "" 870 return alwaysOptional[attr] == ""
850 } 871 }
851 872
852 var defaults = allDefaults() 873 var defaults = allDefaults()
853 874
854 // allDefaults returns a schema.Defaults that contains 875 // allDefaults returns a schema.Defaults that contains
855 // defaults to be used when creating a new config with 876 // defaults to be used when creating a new config with
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // of an environment. 917 // of an environment.
897 var immutableAttributes = []string{ 918 var immutableAttributes = []string{
898 "name", 919 "name",
899 "type", 920 "type",
900 "firewall-mode", 921 "firewall-mode",
901 "state-port", 922 "state-port",
902 "api-port", 923 "api-port",
903 "bootstrap-timeout", 924 "bootstrap-timeout",
904 "bootstrap-retry-delay", 925 "bootstrap-retry-delay",
905 "bootstrap-addresses-delay", 926 "bootstrap-addresses-delay",
906 » "lxc-use-clone", 927 » "lxc-clone",
928 » "lxc-clone-aufs",
907 } 929 }
908 930
909 var ( 931 var (
910 withDefaultsChecker = schema.FieldMap(fields, defaults) 932 withDefaultsChecker = schema.FieldMap(fields, defaults)
911 noDefaultsChecker = schema.FieldMap(fields, alwaysOptional) 933 noDefaultsChecker = schema.FieldMap(fields, alwaysOptional)
912 ) 934 )
913 935
914 // ValidateUnknownAttrs checks the unknown attributes of the config against 936 // ValidateUnknownAttrs checks the unknown attributes of the config against
915 // the supplied fields and defaults, and returns an error if any fails to 937 // the supplied fields and defaults, and returns an error if any fails to
916 // validate. Unknown fields are warned about, but preserved, on the basis 938 // validate. Unknown fields are warned about, but preserved, on the basis
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1030
1009 // AptProxyConfigMap returns a map suitable to be applied to a Config to update 1031 // AptProxyConfigMap returns a map suitable to be applied to a Config to update
1010 // proxy settings. 1032 // proxy settings.
1011 func AptProxyConfigMap(proxy osenv.ProxySettings) map[string]interface{} { 1033 func AptProxyConfigMap(proxy osenv.ProxySettings) map[string]interface{} {
1012 settings := make(map[string]interface{}) 1034 settings := make(map[string]interface{})
1013 addIfNotEmpty(settings, "apt-http-proxy", proxy.Http) 1035 addIfNotEmpty(settings, "apt-http-proxy", proxy.Http)
1014 addIfNotEmpty(settings, "apt-https-proxy", proxy.Https) 1036 addIfNotEmpty(settings, "apt-https-proxy", proxy.Https)
1015 addIfNotEmpty(settings, "apt-ftp-proxy", proxy.Ftp) 1037 addIfNotEmpty(settings, "apt-ftp-proxy", proxy.Ftp)
1016 return settings 1038 return settings
1017 } 1039 }
OLDNEW
« container/lxc/lxc.go ('K') | « environs/config.go ('k') | environs/config/config_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b