ovf.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014-2015 VMware, Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ovf
  15. import (
  16. "encoding/xml"
  17. "log"
  18. )
  19. type environment struct {
  20. Platform platform `xml:"PlatformSection"`
  21. Properties []property `xml:"PropertySection>Property"`
  22. }
  23. type platform struct {
  24. Kind string `xml:"Kind"`
  25. Version string `xml:"Version"`
  26. Vendor string `xml:"Vendor"`
  27. Locale string `xml:"Locale"`
  28. }
  29. type property struct {
  30. Key string `xml:"key,attr"`
  31. Value string `xml:"value,attr"`
  32. }
  33. type OvfEnvironment struct {
  34. Platform platform
  35. Properties map[string]string
  36. }
  37. func ReadEnvironment(doc []byte) *OvfEnvironment {
  38. var env environment
  39. if err := xml.Unmarshal(doc, &env); err != nil {
  40. log.Fatalln(err)
  41. }
  42. dict := make(map[string]string)
  43. for _, p := range env.Properties {
  44. dict[p.Key] = p.Value
  45. }
  46. return &OvfEnvironment{Properties: dict,
  47. Platform: env.Platform}
  48. }