License file added; Copyright header for source files added

This commit is contained in:
v-vlshch 2014-06-27 10:38:42 -07:00
Родитель 66cc1e1317
Коммит 8364ba3e17
39 изменённых файлов: 321 добавлений и 133 удалений

4
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,4 @@
Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
// A driver is able to talk to HyperV and perform certain

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
@ -149,6 +153,27 @@ func (d *HypervPS4Driver) setExecutionPolicy() error {
return err
}
func (d *HypervPS4Driver) VerifyPSAzureModule() error {
log.Printf("Enter method: %s", "VerifyPSAzureModule")
versionCmd := "Invoke-Command -scriptblock { function foo(){try{ $commands = Get-Command -Module Azure;if($commands.Length -eq 0){return $false} }catch{return $false}; return $true} foo}"
cmd := exec.Command(d.HypervManagePath, versionCmd)
cmdOut, err := cmd.Output()
if err != nil {
return err
}
res := strings.TrimSpace(string(cmdOut))
if(res== "False"){
err := fmt.Errorf("%s", "Azure PowerShell not found. Try this link to install Azure PowerShell: http://go.microsoft.com/?linkid=9811175&clcid=0x409.")
return err
}
return nil
}
func (d *HypervPS4Driver) HypervManage(block string) error {
log.Printf("Executing HypervManage: %#v", block)

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -0,0 +1,57 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"regexp"
"strings"
)
type StepAcceptEula struct {
}
func (s *StepAcceptEula) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
errorMsg := "EULA agreement step error: %s"
ans, err := ui.Ask("<TODO:validate text with Snesha> Do you accept the EULA? (type 'Yes' if you accept): ")
if err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
eulaAnswer := strings.TrimSpace(ans)
if len(eulaAnswer) == 0 {
err := fmt.Errorf("Your answer is empty and Packer has to exit.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}else {
pattern := "^[Yy][Ee][Ss]$"
value := eulaAnswer
match, _ := regexp.MatchString(pattern, value)
if !match {
err := fmt.Errorf("You should accept the EULA or Packer has to exit.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *StepAcceptEula) Cleanup(state multistep.StateBag) {
// do nothing
}

Просмотреть файл

@ -0,0 +1,85 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"bytes"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
"log"
"strings"
)
type StepCheckRemoting struct {
}
func (s *StepCheckRemoting) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
comm := state.Get("communicator").(packer.Communicator)
var err error
errorMsg := "Error step CheckRemoting: %s"
// check the remote connection is ready
{
var cmd packer.RemoteCmd
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
magicWord := "ready"
var blockBuffer bytes.Buffer
blockBuffer.WriteString("{ Write-Host '"+ magicWord +"' }")
cmd.Command = "-ScriptBlock " + blockBuffer.String()
cmd.Stdout = stdout
cmd.Stderr = stderr
count := 5
var duration time.Duration = 1
sleepTime := time.Minute * duration
ui.Say("Checking PS remoting is ready...")
for count > 0 {
err = comm.Start(&cmd)
if err != nil {
err := fmt.Errorf(errorMsg, "Remote connection failed")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
stderrString := strings.TrimSpace(stderr.String())
stdoutString := strings.TrimSpace(stdout.String())
log.Printf("stdout: %s", stdoutString)
log.Printf("stderr: %s", stderrString)
if stdoutString == magicWord {
break;
}
log.Println(fmt.Sprintf("Waiting %v minutes for the remote connection to get ready...", uint(duration)))
time.Sleep(sleepTime)
count--
}
if count == 0 {
err := fmt.Errorf(errorMsg, "Remote connection failed")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *StepCheckRemoting) Cleanup(state multistep.StateBag) {
// do nothing
}

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
@ -98,14 +102,14 @@ func (s *StepCreateExternalSwitch) Cleanup(state multistep.StateBag) {
var err error = nil
errMsg := "Error deleting external switch: %s"
// connect the vm to the old switch
if s.oldSwitchName == "" {
ui.Error(fmt.Sprintf("Error deleting external switch: %s", "the old switch name is empty"))
ui.Error(fmt.Sprintf(errMsg, "the old switch name is empty"))
return
}
errMsg := "Error deleting external switch: %s"
var blockBuffer bytes.Buffer
blockBuffer.WriteString("Invoke-Command -scriptblock {")
blockBuffer.WriteString("$sn='" + s.oldSwitchName + "';")
@ -120,6 +124,8 @@ func (s *StepCreateExternalSwitch) Cleanup(state multistep.StateBag) {
return
}
state.Put("SwitchName", s.oldSwitchName)
blockBuffer.Reset()
blockBuffer.WriteString("Invoke-Command -scriptblock {")
blockBuffer.WriteString("$sn='" + s.SwitchName + "';")

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
@ -8,11 +12,11 @@ import (
"github.com/MSOpenTech/packer-hyperv/packer/communicator/powershell"
)
type StepRemoteSession struct {
type StepSetRemoting struct {
comm packer.Communicator
}
func (s *StepRemoteSession) Run(state multistep.StateBag) multistep.StepAction {
func (s *StepSetRemoting) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
@ -59,6 +63,6 @@ func (s *StepRemoteSession) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}
func (s *StepRemoteSession) Cleanup(state multistep.StateBag) {
func (s *StepSetRemoting) Cleanup(state multistep.StateBag) {
// do nothing
}

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (
@ -9,6 +13,7 @@ import (
"github.com/mitchellh/multistep"
hypervcommon "github.com/MSOpenTech/packer-hyperv/packer/builder/hyperv/common"
// msbldcommon "github.com/MSOpenTech/packer-hyperv/packer/builder/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"regexp"
@ -37,7 +42,6 @@ type iso_config struct {
RawSingleISOUrl string `mapstructure:"iso_url"`
SleepTimeMinutes time.Duration `mapstructure:"wait_time_minutes"`
ProductKey string `mapstructure:"product_key"`
AcceptEULA string `mapstructure:"accept_eula"`
common.PackerConfig `mapstructure:",squash"`
hypervcommon.OutputConfig `mapstructure:",squash"`
@ -70,22 +74,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...)
warnings := make([]string, 0)
eulaAnswer := strings.TrimSpace(b.config.AcceptEULA)
if len(eulaAnswer) == 0 {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("accept_eula: The option can't be missed or empty or Packer has to exit."))
}else {
pattern := "^[Yy][Ee][Ss]$"
value := eulaAnswer
match, _ := regexp.MatchString(pattern, value)
if !match {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("accept_eula: '%v'. The value should be 'Yes' or Packer has to exit.", eulaAnswer))
}
}
log.Println(fmt.Sprintf("%s: '%v'", "AcceptEULA", b.config.AcceptEULA))
if b.config.DiskSizeGB == 0 {
b.config.DiskSizeGB = 40
}
@ -230,6 +218,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// state.Put("vmName", "PackerFull")
steps := []multistep.Step{
// new(hypervcommon.StepAcceptEula),
new(hypervcommon.StepCreateTempDir),
&hypervcommon.StepOutputDir{
Force: b.config.PackerForce,
@ -248,9 +237,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&hypervcommon.StepSleep{ Minutes: b.config.SleepTimeMinutes, ActionName: "Installing" },
new(hypervcommon.StepConfigureIp),
new(hypervcommon.StepRemoteSession),
new(hypervcommon.StepSetRemoting),
new(common.StepProvision),
new(StepInstallProductKey),
// new(hypervcommon.StepConfigureIp),
// new(hypervcommon.StepSetRemoting),
// new(hypervcommon.StepCheckRemoting),
// new(msbldcommon.StepSysprep),
}
// Run the steps.

Просмотреть файл

@ -1,98 +0,0 @@
package iso
import (
"fmt"
"os"
hypervcommon "github.com/MSOpenTech/packer-hyperv/packer/builder/hyperv/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
)
// Config is the configuration structure for the builder.
type Config struct {
common.PackerConfig `mapstructure:",squash"`
// hypervcommon.ExportConfig `mapstructure:",squash"`
// vboxcommon.FloppyConfig `mapstructure:",squash"`
hypervcommon.OutputConfig `mapstructure:",squash"`
// hypervcommon.RunConfig `mapstructure:",squash"`
// hypervcommon.SSHConfig `mapstructure:",squash"`
// hypervcommon.ShutdownConfig `mapstructure:",squash"`
// hypervcommon.VBoxManageConfig `mapstructure:",squash"`
// hypervcommon.VBoxVersionConfig `mapstructure:",squash"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
ImportOpts string `mapstructure:"import_opts"`
tpl *packer.ConfigTemplate
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
md, err := common.DecodeConfig(c, raws...)
if err != nil {
return nil, nil, err
}
c.tpl, err = packer.NewConfigTemplate()
if err != nil {
return nil, nil, err
}
c.tpl.UserVars = c.PackerUserVars
// Defaults
if c.VMName == "" {
c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName)
}
// Prepare the errors
errs := common.CheckUnusedConfig(md)
// errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(c.tpl)...)
// errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...)
// errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...)
// errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...)
// errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(c.tpl)...)
// errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(c.tpl)...)
// errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(c.tpl)...)
templates := map[string]*string{
"source_path": &c.SourcePath,
"vm_name": &c.VMName,
"import_opts": &c.ImportOpts,
}
for n, ptr := range templates {
var err error
*ptr, err = c.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if c.SourcePath == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
} else {
if _, err := os.Stat(c.SourcePath); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("source_path is invalid: %s", err))
}
}
// Warnings
var warnings []string
if c.ShutdownCommand == "" {
warnings = append(warnings,
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
"will forcibly halt the virtual machine, which may result in data loss.")
}
// Check for any errors.
if errs != nil && len(errs.Errors) > 0 {
return nil, warnings, errs
}
return c, warnings, nil
}

Просмотреть файл

@ -1,3 +0,0 @@
package iso
const FileAsStringBase64Win2012 string = ""

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (
@ -124,7 +128,8 @@ func (s *StepInstallProductKey) Run(state multistep.StateBag) multistep.StepActi
new(hypervcommon.StepDisableVlan),
new(hypervcommon.StepRebootVm),
new(hypervcommon.StepConfigureIp),
new(hypervcommon.StepRemoteSession),
new(hypervcommon.StepSetRemoting),
new(hypervcommon.StepCheckRemoting),
new(hypervcommon.StepExecuteOnlineActivation),
}
@ -136,7 +141,8 @@ func (s *StepInstallProductKey) Run(state multistep.StateBag) multistep.StepActi
new(hypervcommon.StepDisableVlan),
new(hypervcommon.StepRebootVm),
new(hypervcommon.StepConfigureIp),
new(hypervcommon.StepRemoteSession),
new(hypervcommon.StepSetRemoting),
new(hypervcommon.StepCheckRemoting),
&hypervcommon.StepExecuteOnlineActivationFull{Pk:pk},
}

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package iso
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package powershell
import (

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package main
import (

Просмотреть файл

@ -1 +1,5 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package main

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package main
import (

Просмотреть файл

@ -1 +1,5 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package main

Просмотреть файл

@ -1,3 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package powershell
import (