1 Building Manageable Apps: Admin Scripting & Automation Jeffrey Snover Management Architect...

Post on 29-Jan-2016

222 views 0 download

Tags:

Transcript of 1 Building Manageable Apps: Admin Scripting & Automation Jeffrey Snover Management Architect...

1

Building Manageable Apps: Admin Scripting & AutomationJeffrey SnoverManagement ArchitectMicrosoft Corporationjsnover@microsoft.com

Session Code: ARC-334

2

Make the connection

Base ServicesBase Services

KernelKernel

Hardware Abstraction LayerHardware Abstraction Layer

Base Operating System Services

CLR

Health & InstrumentationHealth & Instrumentation

Management Services

System.Management.InstrumentationSystem.Management.Instrumentation

System.ManagementSystem.Management

System.DiagnosticsSystem.Diagnostics

System.Diagnostics.EventsSystem.Diagnostics.Events

System.Management.MonitoringSystem.Management.Monitoring

Task & AutomationTask & Automation

System.Management.TaskSchedulerSystem.Management.TaskScheduler

System.Management.AutomationSystem.Management.Automation

System.Management.TaskScheduler.UISystem.Management.TaskScheduler.UI

Settings & ConfigurationSettings & Configuration

System.Configuration.SettingsSystem.Configuration.Settings

3

Windows

DSI Architecture (ARC230)Design for OperationsDSI Architecture (ARC230)Design for Operations

Dynamic System Services

SDMStore

Dynamic Data CenterSTORAGESTORAGESERVERSSERVERS NETWORKINGNETWORKING

Settings ARC333

Tasks ARC334

Health ARC332

Hardware

ManagedNode

ManagedSystem

ManagementTools

DevTools

LocalNodeMgm

t

System Level Management

Remote

Node Mgmt

Your Application

Your System

DefinitionSDM

Service

4

Task-Based ManagementTask-Based Management

Abstractions match activities of the userAdd a user – canonical example

Create account in ADCreate home directoryAdd to GroupsCustomer-specific setup…

Surfaced to enable automationRequires command line access!

Abstractions match activities of the userAdd a user – canonical example

Create account in ADCreate home directoryAdd to GroupsCustomer-specific setup…

Surfaced to enable automationRequires command line access!

5

IntroductionIntroduction

Weak cmd shellWeak languagespotty coverage

GUI focusHard to automate

SDK FocusProgrammers

Weak cmd shellWeak languagespotty coverage

GUI focusHard to automate

SDK FocusProgrammers

Foundation for task-based managementFocused on power users and adminsProvides:

Interactive shellCmdletsUtilitiesScripting language Remote scripting

Foundation for task-based managementFocused on power users and adminsProvides:

Interactive shellCmdletsUtilitiesScripting language Remote scripting

Solution: MSHProblem

6

MSH ElementsMSH Elements

Core conceptsPipelines and utilitiesParameters and confirmation Records and errorsNavigation

Core conceptsPipelines and utilitiesParameters and confirmation Records and errorsNavigation

7

Core ConceptsCore Concepts

Command line scripting languageBest of sh/ksh, Perl/Ruby, DCL/CL

Commands are classes (Cmdlets)Hosting model

Command line scripting languageBest of sh/ksh, Perl/Ruby, DCL/CL

Commands are classes (Cmdlets)Hosting model

8

…using

public class{ public override void { (Process.GetProcesses()); }}

System.Management.Automation

Commands Are ClassesCommands Are Classes

GetPs : Cmdlet

[CmdletDeclaration("get", "ps")]

WriteObjects

StartProcessing()

9

Cmdlets Or …What Do I Get For 5 Lines Of Code?

James TruherMSH Program Managerjimtru@microsoft.com

10

How It Works How It Works

AutoRegistration

Parser maps to your DLL

MSH manages the DLL and Class lifecycle

AutoRegistration

Parser maps to your DLL

MSH manages the DLL and Class lifecycle

11

Pipeline And Utilities ConceptsPipeline And Utilities Concepts

1. Pipelines are Cmdlets passing structured objects

2. Reflection-based utility Cmdlets

1. Pipelines are Cmdlets passing structured objects

2. Reflection-based utility Cmdlets

12

Pipeline & Utilities Or…Was That All I Got For 5 Lines Of Code?

James TruherMSH Program Managerjimtru@microsoft.com

13

How It WorksHow It Worksget/process | where “handlecount –gt 500” | sort handlecount | format/table

GetP

roc

ess

Cla

ss

Common MSH Parser

MSH Pipeline ProcessorW

here

C

lass

Sort

Cla

ss

Form

at

Cla

ss

14

CLIs And GUIsCLIs And GUIs

Not either/orAdmins need more than GUIs typically deliver

Planning & reviewGuaranteed consistencyMassive productivity

You need to support both

Not either/orAdmins need more than GUIs typically deliver

Planning & reviewGuaranteed consistencyMassive productivity

You need to support both

Background

15

Composable ManagementComposable Management

Traditional ModelA | B | CTight coupling between

Parse, Get, Process, Output

Relies on parsing text

.NET allows us to do betterFiner grain pipelineObjects instead of text

Traditional ModelA | B | CTight coupling between

Parse, Get, Process, Output

Relies on parsing text

.NET allows us to do betterFiner grain pipelineObjects instead of text

Background

16

CostBenefits

# of Functions

TraditionalModel

EconomicsEconomics

Costs: Dev Test Training

MSH Common Enginecombined with Utility Cmdlets

New Model

Background

17

Glide PathGlide Path

ShowScript

Reflection

Background

GUI

Cmd

VS

18

MMC or…How Do GUIs Work With This?

Mark HongMMC Dev Leadmarkhong@microsoft.com

19

Parameter And ConfirmationConcepts

Parameter And ConfirmationConcepts

Common parser

Driven by fields/properties + attributes

Use Confirmation model

Common parser

Driven by fields/properties + attributes

Use Confirmation model

20

Parameters And ConfirmationParameters And Confirmation[CommandDeclaration("stop", "ps")]public class StopPs: Cmdlet{

public string ProcessName; public override void ProcessRecord() { Process [ ]ps; ps = Process.GetProcessesByName(ProcessName); foreach (Process p in ps) {

{ p.Kill(); } } }}

[CommandDeclaration("stop", "ps")]public class StopPs: Cmdlet{

public string ProcessName; public override void ProcessRecord() { Process [ ]ps; ps = Process.GetProcessesByName(ProcessName); foreach (Process p in ps) {

{ p.Kill(); } } }}

[ParsingMandatoryParameter][ParsingPromptString(“Name of the process")]

if (ConfirmProcessing(p.ProcessName))

21

Parameters/Confirmation Or… So What Do Those 3 Lines Of Code Get Me?

James TruherMSH Program Managerjimtru@microsoft.com

22

How It WorksParameter AttributesHow It WorksParameter Attributes

PrerequisiteMachineRolePrerequisiteUserRolePrerequisteScriptPrerequisiteUIType ParsingParameterParsingAllowPipelineInputParsingParameterMappingParsingVariableLengthParameterListParsingInteraction

PrerequisiteMachineRolePrerequisiteUserRolePrerequisteScriptPrerequisiteUIType ParsingParameterParsingAllowPipelineInputParsingParameterMappingParsingVariableLengthParameterListParsingInteraction

ParsingPasswordParameter ParsingPromptStringValidationRange ValidationLength ValidationCount ValidationFileAttributesValidationNetworkAttribute ValidationPatternExpandWildcards

ParsingPasswordParameter ParsingPromptStringValidationRange ValidationLength ValidationCount ValidationFileAttributesValidationNetworkAttribute ValidationPatternExpandWildcards

Predicates Parsing Data ValidationData Generation Data Presentation

23

How It WorksHow It Workspublic bool ConfirmProcessing(string Action){

}

if (Confirm){ return Prompt(Action + “Continue [y/n/!]”);}

if (Whatif){ WriteLine(“# “ + Action); return false}

if (Confirm){ return Prompt(Action + “Continue [y/n/!]”);}

if (Verbose){ Writeline(Action); return true;}

if (Whatif){ WriteLine(“# “ + Action); return false}

Pseudo-code

24

Records And Errors ConceptsRecords And Errors Concepts1. MSH is Record oriented

Records come from the Cmdline or the PipeLine

Parameters define or contribute to a record

Pipeline objects are processed into Records

2. Errors are first class citizensPolicy driven error handling

1. MSH is Record orientedRecords come from the Cmdline or the PipeLine

Parameters define or contribute to a record

Pipeline objects are processed into Records

2. Errors are first class citizensPolicy driven error handling

25

[CommandDeclaration("format", "ps")]public class FormatPs: Command{ public string ProcessName; public int HandleCount; public override void StartProcessing() { WriteObject(“Caution – data may be false”); }

public override void EndProcessing() { WriteObject(“Done”)); }}

[CommandDeclaration("format", "ps")]public class FormatPs: Command{ public string ProcessName; public int HandleCount; public override void StartProcessing() { WriteObject(“Caution – data may be false”); }

public override void EndProcessing() { WriteObject(“Done”)); }}

Record OrientationRecord Orientation

public override void ProcessRecord() {

WriteObject(ProcessName + “:” + HandleCount); }

public override void ProcessRecord() {

WriteObject(ProcessName + “:” + HandleCount); }

if (record++ > 5 && record < 10)WriteErrorObject(CurrentPipelineObject,

new Exception("Invalid record"));

[ParsingAllowPipelineInput]

[ParsingAllowPipelineInput]

26

Records And Errors Or …Why This Isn’t Like Your Dad’s Shell

James TruherMSH Program Managerjimtru@microsoft.com

27

How It WorksHow It Works

StartProcessing()

for each object Pipeline

Convert object into a record Apply command line params

ProcessRecord()

EndProcessing()

StartProcessing()

for each object Pipeline

Convert object into a record Apply command line params

ProcessRecord()

EndProcessing()

28

Ubiquitous NavigationUbiquitous Navigation

FileSystems are easy to useNavigation and manipulation are universal

Other stores are hard Require domain-specific utilties and concepts

How do we make other stores easy?Interact with them like FileSystems

FileSystems are easy to useNavigation and manipulation are universal

Other stores are hard Require domain-specific utilties and concepts

How do we make other stores easy?Interact with them like FileSystems

29

Navigation Provider Concepts Navigation Provider Concepts 1. You Subclass and we provide the

CmdletsDir, cd, pushd, popd, cat, delete, rename, copy, clear,

2. Providers need to be registered

3. Requests to providers are stateless and use absolute names

1. You Subclass and we provide the Cmdlets

Dir, cd, pushd, popd, cat, delete, rename, copy, clear,

2. Providers need to be registered

3. Requests to providers are stateless and use absolute names

30

Navigation ProviderNavigation Provider

[ProviderDeclaration("REG", "Registry",ProviderCapabilityFlags.None)]public class RegistryProvider : NavigationCmdletBase{ protected override void GetItem(string path) { RegistryKey key = GetRegkeyForPath(path, false);

if (key == null) { WriteErrorObject(path,

new ArgumentException("does not exist")); } WriteObject(key); } ....}

[ProviderDeclaration("REG", "Registry",ProviderCapabilityFlags.None)]public class RegistryProvider : NavigationCmdletBase{ protected override void GetItem(string path) { RegistryKey key = GetRegkeyForPath(path, false);

if (key == null) { WriteErrorObject(path,

new ArgumentException("does not exist")); } WriteObject(key); } ....}

31

Navigation Provider – OrWhat Whackball Would TreatRegistry Like A Filesystem?

James TruherMSH Program Managerjimtru@microsoft.com

32

How It WorksHow It Works

MSH Engine

Core Command Base Classes

Core Commands(get, set, rename, move, push, pop, …)

FileSysProvider

Cmdlet Cmdlet Cmdlet …

RegistryProvider

ADProvider

33

Longhorn Command Shell (MSH) PreviewLonghorn Command Shell (MSH) Preview

Available on http://betaplace.com

Use the guest account: mshPDC Logon and password emailed within 24 hours

Download bits, SDK, samples, private newsgroup and a feedback/bug reporting environment.

Available on http://betaplace.com

Use the guest account: mshPDC Logon and password emailed within 24 hours

Download bits, SDK, samples, private newsgroup and a feedback/bug reporting environment.

34

Call To ActionCall To Action

1. Write managed code interfaces to your services and objects

2. Design your task model3. Write Cmdlets for invariant

actions4. Write MSH scripts for actions

which vary between customers5. Write Navigation providers to

expose namespaces

1. Write managed code interfaces to your services and objects

2. Design your task model3. Write Cmdlets for invariant

actions4. Write MSH scripts for actions

which vary between customers5. Write Navigation providers to

expose namespaces

35

HAPPY BIRTHDAY ToJIM TRUHER

HAPPY BIRTHDAY ToJIM TRUHER

36© 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.