-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Azure/pr-xml-regions
Support promotion to more than two regions
- Loading branch information
Showing
55 changed files
with
2,236 additions
and
162 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,175 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"text/template" | ||
"encoding/xml" | ||
"fmt" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
"github.com/codegangsta/cli" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
type certificate struct { | ||
StoreLocation string `xml:"StoreLocation,omitempty"` | ||
StoreName string `xml:"StoreName,omitempty"` | ||
ThumbprintRequired bool `xml:"ThumbprintRequired,omitempty"` | ||
ThumbprintAlgorithm string `xml:"ThumbprintAlgorithm,omitempty"` | ||
} | ||
|
||
// NOTE(@boumenot): there is probably a better way to express this. If | ||
// you know please share... | ||
// | ||
// The only difference between ExtensionImage and ExtensionImageGlobal is the | ||
// Regions element. This element can be in three different states to my | ||
// knowledge. | ||
// | ||
// 1. not defined | ||
// 2. <Regions>Region1;Region2</Regions> | ||
// 3. <Regions></Regions> | ||
// | ||
// Case (1) occurs when an extension is first published. Case(2) occurs when | ||
// an extension is promoted to one or two regions. Case (3) occurs when an | ||
// extension is published to all regions. | ||
// | ||
// I do not know how to express all three cases using Go's XML serializer. | ||
// | ||
type extensionImage struct { | ||
XMLName string `xml:"ExtensionImage"` | ||
NS string `xml:"xmlns,attr"` | ||
ProviderNameSpace string `xml:"ProviderNameSpace"` | ||
Type string `xml:"Type"` | ||
Version string `xml:"Version"` | ||
Label string `xml:"Label"` | ||
HostingResources string `xml:"HostingResources"` | ||
MediaLink string `xml:"MediaLink"` | ||
Certificate *certificate `xml:"Certificate,omitempty"` | ||
PublicConfigurationSchema string `xml:"PublicConfigurationSchema,omitempty"` | ||
PrivateConfigurationSchema string `xml:"PrivateConfigurationSchema,omitempty"` | ||
Description string `xml:"Description"` | ||
BlockRoleUponFailure string `xml:"BlockRoleUponFailure,omitempty"` | ||
IsInternalExtension bool `xml:"IsInternalExtension"` | ||
Eula string `xml:"Eula,omitempty"` | ||
PrivacyURI string `xml:"PrivacyUri,omitempty"` | ||
HomepageURI string `xml:"HomepageUri,omitempty"` | ||
IsJSONExtension bool `xml:"IsJsonExtension,omitempty"` | ||
CompanyName string `xml:"CompanyName,omitempty"` | ||
SupportedOS string `xml:"SupportedOS,omitempty"` | ||
Regions string `xml:"Regions,omitempty"` | ||
} | ||
|
||
type extensionImageGlobal struct { | ||
XMLName string `xml:"ExtensionImage"` | ||
NS string `xml:"xmlns,attr"` | ||
ProviderNameSpace string `xml:"ProviderNameSpace"` | ||
Type string `xml:"Type"` | ||
Version string `xml:"Version"` | ||
Label string `xml:"Label"` | ||
HostingResources string `xml:"HostingResources"` | ||
MediaLink string `xml:"MediaLink"` | ||
Certificate *certificate `xml:"Certificate,omitempty"` | ||
PublicConfigurationSchema string `xml:"PublicConfigurationSchema,omitempty"` | ||
PrivateConfigurationSchema string `xml:"PrivateConfigurationSchema,omitempty"` | ||
Description string `xml:"Description"` | ||
BlockRoleUponFailure string `xml:"BlockRoleUponFailure,omitempty"` | ||
IsInternalExtension bool `xml:"IsInternalExtension"` | ||
Eula string `xml:"Eula,omitempty"` | ||
PrivacyURI string `xml:"PrivacyUri,omitempty"` | ||
HomepageURI string `xml:"HomepageUri,omitempty"` | ||
IsJSONExtension bool `xml:"IsJsonExtension,omitempty"` | ||
CompanyName string `xml:"CompanyName,omitempty"` | ||
SupportedOS string `xml:"SupportedOS,omitempty"` | ||
Regions string `xml:"Regions"` | ||
} | ||
|
||
type extensionManifest interface { | ||
Marshal() ([]byte, error) | ||
} | ||
|
||
func isGuestAgent(providerNameSpace string) bool { | ||
return "Microsoft.OSTCLinuxAgent" == providerNameSpace | ||
} | ||
|
||
func newExtensionImageManifest(filename string, regions []string) (extensionManifest, error) { | ||
b, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var manifest extensionImage | ||
err = xml.Unmarshal(b, &manifest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
manifest.Regions = strings.Join(regions, ";") | ||
|
||
if !isGuestAgent(manifest.ProviderNameSpace) { | ||
manifest.IsInternalExtension = false | ||
} else { | ||
log.Debug("VM agent namespace detected, IsInternalExtension ignored") | ||
} | ||
|
||
return &manifest, nil | ||
} | ||
|
||
func newExtensionImageGlobalManifest(filename string) (extensionManifest, error) { | ||
b, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var manifest extensionImageGlobal | ||
err = xml.Unmarshal(b, &manifest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
manifest.IsInternalExtension = !isGuestAgent(manifest.ProviderNameSpace) | ||
return &manifest, nil | ||
} | ||
|
||
func (ext *extensionImage) Marshal() ([]byte, error) { | ||
return xml.Marshal(*ext) | ||
} | ||
|
||
func (ext *extensionImageGlobal) Marshal() ([]byte, error) { | ||
return xml.Marshal(*ext) | ||
} | ||
|
||
func newExtensionManifest(c *cli.Context) { | ||
cl := mkClient(checkFlag(c, flMgtURL.Name), checkFlag(c, flSubsID.Name), checkFlag(c, flSubsCert.Name)) | ||
storageRealm := checkFlag(c, flStorageRealm.Name) | ||
storageAccount := checkFlag(c, flStorageAccount.Name) | ||
extensionPkg := checkFlag(c, flPackage.Name) | ||
|
||
var p struct { | ||
Namespace, Name, Version, BlobURL, Label, Description, Eula, Privacy, Homepage, Company, OS string | ||
} | ||
flags := []struct { | ||
ref *string | ||
fl string | ||
}{ | ||
{&p.Namespace, flNamespace.Name}, | ||
{&p.Name, flName.Name}, | ||
{&p.Version, flVersion.Name}, | ||
{&p.Label, "label"}, | ||
{&p.Description, "description"}, | ||
{&p.Eula, "eula-url"}, | ||
{&p.Privacy, "privacy-url"}, | ||
{&p.Homepage, "homepage-url"}, | ||
{&p.Company, "company"}, | ||
{&p.OS, "supported-os"}, | ||
} | ||
for _, f := range flags { | ||
*f.ref = checkFlag(c, f.fl) | ||
} | ||
|
||
// Upload extension blob | ||
blobURL, err := uploadBlob(cl, storageRealm, storageAccount, extensionPkg) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Debugf("Extension package uploaded to: %s", blobURL) | ||
p.BlobURL = blobURL | ||
|
||
// doing a text template is easier and let us create comments (xml encoder can't) | ||
// that are used as placeholders later on. | ||
manifestXML := `<?xml version="1.0" encoding="utf-8" ?> | ||
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | ||
<!-- WARNING: Ordering of fields matter in this file. --> | ||
<ProviderNameSpace>{{.Namespace}}</ProviderNameSpace> | ||
<Type>{{.Name}}</Type> | ||
<Version>{{.Version}}</Version> | ||
<Label>{{.Label}}</Label> | ||
<HostingResources>VmRole</HostingResources> | ||
<MediaLink>{{.BlobURL}}</MediaLink> | ||
<Description>{{.Description}}</Description> | ||
<IsInternalExtension>true</IsInternalExtension> | ||
<Eula>{{.Eula}}</Eula> | ||
<PrivacyUri>{{.Privacy}}</PrivacyUri> | ||
<HomepageUri>{{.Homepage}}</HomepageUri> | ||
<IsJsonExtension>true</IsJsonExtension> | ||
<CompanyName>{{.Company}}</CompanyName> | ||
<SupportedOS>{{.OS}}</SupportedOS> | ||
<!--%REGIONS%--> | ||
</ExtensionImage> | ||
` | ||
tpl, err := template.New("manifest").Parse(manifestXML) | ||
if err != nil { | ||
log.Fatalf("template parse error: %v", err) | ||
|
||
manifest := extensionImage{ | ||
ProviderNameSpace: checkFlag(c, flNamespace.Name), | ||
Type: checkFlag(c, flName.Name), | ||
Version: checkFlag(c, flVersion.Name), | ||
Label: "label", | ||
Description: "description", | ||
IsInternalExtension: true, | ||
MediaLink: blobURL, | ||
Eula: "eula-url", | ||
PrivacyURI: "privacy-url", | ||
HomepageURI: "homepage-url", | ||
IsJSONExtension: true, | ||
CompanyName: "company", | ||
SupportedOS: "supported-os", | ||
} | ||
if err = tpl.Execute(os.Stdout, p); err != nil { | ||
log.Fatalf("template execute error: %v", err) | ||
|
||
bs, err := xml.MarshalIndent(manifest, "", " ") | ||
if err != nil { | ||
log.Fatalf("xml marshall error: %v", err) | ||
} | ||
|
||
fmt.Println(string(bs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure"> | ||
<ProviderNameSpace>Microsoft.OSCTExtensions</ProviderNameSpace> | ||
<Type>CustomScriptForLinux</Type> | ||
<Version>4.3.2.1</Version> | ||
<Label>Microsoft Azure Custom Script Extension for Linux Virtual Machines</Label> | ||
<HostingResources>VmRole</HostingResources> | ||
<MediaLink>http://localhost/extension.zip</MediaLink> | ||
<Description>Please consider using Microsoft.Azure.Extensions.CustomScript instead.</Description> | ||
<IsInternalExtension>true</IsInternalExtension> | ||
<Eula>https://github.com/Azure/azure-linux-extensions/blob/master/LICENSE-2_0.txt</Eula> | ||
<PrivacyUri>http://www.microsoft.com/privacystatement/en-us/OnlineServices/Default.aspx</PrivacyUri> | ||
<HomepageUri>https://github.com/Azure/azure-linux-extensions</HomepageUri> | ||
<IsJsonExtension>true</IsJsonExtension> | ||
<CompanyName>Microsoft</CompanyName> | ||
<SupportedOS>Linux</SupportedOS> | ||
<Regions>South Central US</Regions> | ||
</ExtensionImage> |
Oops, something went wrong.