Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 package state | 1 package state |
2 | 2 |
3 import ( | 3 import ( |
4 "errors" | 4 "errors" |
5 "fmt" | 5 "fmt" |
6 "labix.org/v2/mgo" | 6 "labix.org/v2/mgo" |
7 "labix.org/v2/mgo/bson" | 7 "labix.org/v2/mgo/bson" |
8 "labix.org/v2/mgo/txn" | 8 "labix.org/v2/mgo/txn" |
9 "launchpad.net/goyaml" | 9 "launchpad.net/goyaml" |
10 "launchpad.net/juju-core/charm" | 10 "launchpad.net/juju-core/charm" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 | 684 |
685 // Config returns the configuration node for the service. | 685 // Config returns the configuration node for the service. |
686 func (s *Service) Config() (config *Settings, err error) { | 686 func (s *Service) Config() (config *Settings, err error) { |
687 config, err = readSettings(s.st, s.settingsKey()) | 687 config, err = readSettings(s.st, s.settingsKey()) |
688 if err != nil { | 688 if err != nil { |
689 return nil, fmt.Errorf("cannot get configuration of service %q: %v", s, err) | 689 return nil, fmt.Errorf("cannot get configuration of service %q: %v", s, err) |
690 } | 690 } |
691 return config, nil | 691 return config, nil |
692 } | 692 } |
693 | 693 |
694 // Set changes a service's configuration values. | 694 // SetConfig changes a service's configuration values. |
695 // Values set to the empty string will be deleted. | 695 // Values set to the empty string will be deleted. |
696 func (s *Service) Set(options map[string]string) error { | 696 func (s *Service) SetConfig(options map[string]string) error { |
fwereade
2013/04/10 16:24:24
I think I would prefer SetConfig... or even a free
rog
2013/04/10 17:40:35
done.
| |
697 unvalidated := make(map[string]string) | 697 unvalidated := make(map[string]string) |
698 var remove []string | 698 var remove []string |
699 for k, v := range options { | 699 for k, v := range options { |
700 if v == "" { | 700 if v == "" { |
701 remove = append(remove, k) | 701 remove = append(remove, k) |
702 } else { | 702 } else { |
703 unvalidated[k] = v | 703 unvalidated[k] = v |
704 } | 704 } |
705 } | 705 } |
706 charm, _, err := s.Charm() | 706 charm, _, err := s.Charm() |
(...skipping 20 matching lines...) Expand all Loading... | |
727 // 4. Delete any removed keys. | 727 // 4. Delete any removed keys. |
728 if len(remove) > 0 { | 728 if len(remove) > 0 { |
729 for _, k := range remove { | 729 for _, k := range remove { |
730 cfg.Delete(k) | 730 cfg.Delete(k) |
731 } | 731 } |
732 } | 732 } |
733 _, err = cfg.Write() | 733 _, err = cfg.Write() |
734 return err | 734 return err |
735 } | 735 } |
736 | 736 |
737 // SetYAML is like Set except that the | 737 // SetConfigYAML is like Set except that the |
738 // configuration data is specified in YAML format. | 738 // configuration data is specified in YAML format. |
739 func (s *Service) SetYAML(yamlData []byte) error { | 739 func (s *Service) SetConfigYAML(yamlData []byte) error { |
fwereade
2013/04/10 16:24:24
SetServiceConfigYAML?
rog
2013/04/10 17:40:35
SetConfigYAML
| |
740 // TODO(rog) should this function interpret null as delete? | 740 // TODO(rog) should this function interpret null as delete? |
741 // TODO(rog) this is wrong. See lp#1167465 | |
741 var options map[string]string | 742 var options map[string]string |
742 if err := goyaml.Unmarshal(yamlData, &options); err != nil { | 743 if err := goyaml.Unmarshal(yamlData, &options); err != nil { |
fwereade
2013/04/10 16:24:24
This is broken. According to python, the yaml is a
rog
2013/04/10 17:40:35
lp#1167465
| |
743 return err | 744 return err |
744 } | 745 } |
745 if options == nil { | 746 if options == nil { |
746 // YAML will unfortunately succeed if we try to | 747 // YAML will unfortunately succeed if we try to |
747 // unmarshal into an inappropriate data type, | 748 // unmarshal into an inappropriate data type, |
748 // so check that we actually have got a map. | 749 // so check that we actually have got a map. |
749 return fmt.Errorf("malformed YAML data") | 750 return fmt.Errorf("malformed YAML data") |
750 } | 751 } |
751 » return s.Set(options) | 752 » return s.SetConfig(options) |
752 } | 753 } |
753 | 754 |
754 // strip removes from validated, any keys which are not also present in unvalida ted. | 755 // strip removes from validated, any keys which are not also present in unvalida ted. |
755 func strip(validated map[string]interface{}, unvalidated map[string]string) map[ string]interface{} { | 756 func strip(validated map[string]interface{}, unvalidated map[string]string) map[ string]interface{} { |
756 for k := range validated { | 757 for k := range validated { |
757 if _, ok := unvalidated[k]; !ok { | 758 if _, ok := unvalidated[k]; !ok { |
758 delete(validated, k) | 759 delete(validated, k) |
759 } | 760 } |
760 } | 761 } |
761 return validated | 762 return validated |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 // | 860 // |
860 // Note: We're not using the settingsDoc for this because changing | 861 // Note: We're not using the settingsDoc for this because changing |
861 // just the ref count is not considered a change worth reporting | 862 // just the ref count is not considered a change worth reporting |
862 // to watchers and firing config-changed hooks. | 863 // to watchers and firing config-changed hooks. |
863 // | 864 // |
864 // There is and implicit _id field here, which mongo creates, which is | 865 // There is and implicit _id field here, which mongo creates, which is |
865 // always the same as the settingsDoc's id. | 866 // always the same as the settingsDoc's id. |
866 type settingsRefsDoc struct { | 867 type settingsRefsDoc struct { |
867 RefCount int | 868 RefCount int |
868 } | 869 } |
LEFT | RIGHT |