Session Code: ARC-334 Building Manageable Apps: Admin Scripting & Automation Jeffrey Snover Management Architect Microsoft Corporation [email protected].
Download ReportTranscript Session Code: ARC-334 Building Manageable Apps: Admin Scripting & Automation Jeffrey Snover Management Architect Microsoft Corporation [email protected].
Session Code: ARC-334 Building Manageable Apps: Admin Scripting & Automation Jeffrey Snover Management Architect Microsoft Corporation [email protected] 1 Base Operating System Services Management Services Health & Instrumentation Task & Automation System.Management System.Management.Automation System.Management.Instrumentation System.Management.TaskScheduler System.Diagnostics System.Management.TaskScheduler.UI System.Diagnostics.Events System.Management.Monitoring Settings & Configuration System.Configuration.Settings CLR Base Services Kernel Hardware Abstraction Layer 2 Make the connection DSI Architecture (ARC230) Design for Operations Management Tools Local Node Mgmt Remote Node Mgmt System Level Management Dynamic System Services Managed System SDM Service Managed Node Dev Tools Settings ARC333 Health Tasks ARC334 SDM Store Your System Definition ARC332 Your Application Windows Hardware 3 SERVERS STORAGE NETWORKING Dynamic Data Center Task-Based Management Abstractions match activities of the user Add a user – canonical example Create account in AD Create home directory Add to Groups Customer-specific setup … Surfaced to enable automation Requires command line access! 4 Introduction Problem Weak cmd shell Weak language spotty coverage GUI focus Hard to automate SDK Focus Programmers Solution: MSH Foundation for taskbased management Focused on power users and admins Provides: Interactive shell Cmdlets Utilities Scripting language Remote scripting 5 MSH Elements Core concepts Pipelines and utilities Parameters and confirmation Records and errors Navigation 6 Core Concepts Command line scripting language Best of sh/ksh, Perl/Ruby, DCL/CL Commands are classes (Cmdlets) Hosting model 7 Commands Are Classes … using System.Management.Automation [CmdletDeclaration("get", "ps")] public class GetPs : Cmdlet { public override void StartProcessing() { WriteObjects (Process.GetProcesses()); } } 8 Cmdlets Or … What Do I Get For 5 Lines Of Code? James Truher MSH Program Manager [email protected] 9 How It Works AutoRegistration Parser maps to your DLL MSH manages the DLL and Class lifecycle 10 Pipeline And Utilities Concepts 1. Pipelines are Cmdlets passing structured objects 2. Reflection-based utility Cmdlets 11 Pipeline & Utilities Or… Was That All I Got For 5 Lines Of Code? James Truher MSH Program Manager [email protected] 12 How It Works get/process | where “handlecount –gt 500” | sort handlecount | format/table Common MSH Parser Format Class Sort Class Where Class GetProces s Class MSH Pipeline Processor 13 CLIs And GUIs Background Not either/or Admins need more than GUIs typically deliver Planning & review Guaranteed consistency Massive productivity You need to support both 14 Composable Management Background Traditional Model A|B|C Tight coupling between Parse, Get, Process, Output Relies on parsing text .NET allows us to do better Finer grain pipeline Objects instead of text 15 Economics Background Traditional Model Cost Benefits Costs: Dev Test Training New Model MSH Common Engine combined with Utility Cmdlets # of Functions 16 Glide Path GUI Background ShowScript Reflection Cmd VS 17 MMC or… How Do GUIs Work With This? Mark Hong MMC Dev Lead [email protected] 18 Parameter And Confirmation Concepts Common parser Driven by fields/properties + attributes Use Confirmation model 19 Parameters And Confirmation [CommandDeclaration("stop", "ps")] public class StopPs: Cmdlet { [ParsingMandatoryParameter] [ParsingPromptString(“Name of the process")] public string ProcessName; public override void ProcessRecord() { Process [ ]ps; ps = Process.GetProcessesByName(ProcessName); foreach (Process p in ps) { if (ConfirmProcessing(p.ProcessName)) { p.Kill(); } } } } 20 Parameters/Confirmation Or… So What Do Those 3 Lines Of Code Get Me? James Truher MSH Program Manager [email protected] 21 How It Works Parameter Attributes Predicates Data Generation Parsing Data Validation Data Presentation PrerequisiteMachineRole PrerequisiteUserRole PrerequisteScript PrerequisiteUIType ParsingParameter ParsingAllowPipelineInput ParsingParameterMapping ParsingVariableLengthParameterLi st ParsingInteraction ParsingPasswordParameter ParsingPromptString ValidationRange ValidationLength ValidationCount ValidationFileAttributes ValidationNetworkAttribute ValidationPattern ExpandWildcards 22 How It Works Pseudo-code public bool ConfirmProcessing(string Action) { if (Confirm) { return Prompt(Action + “Continue [y/n/!]”); } if (Whatif) { WriteLine(“# “ + Action); return false } if (Verbose) { Writeline(Action); return true; } 23 Records And Errors Concepts 1. 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 citizens Policy driven error handling 24 Record Orientation [CommandDeclaration("format", "ps")] public class FormatPs: Command { [ParsingAllowPipelineInput] public string ProcessName; [ParsingAllowPipelineInput] public int HandleCount; public override void StartProcessing() { WriteObject(“Caution – data may be false”); } public override void ProcessRecord() { if (record++ > 5 && record < 10) WriteErrorObject(CurrentPipelineObject, new Exception("Invalid record")); } WriteObject(ProcessName + “:” + HandleCount); public override void EndProcessing() { WriteObject(“Done”)); } } 25 Records And Errors Or … Why This Isn’t Like Your Dad’s Shell James Truher MSH Program Manager [email protected] 26 How It Works StartProcessing() for each object Pipeline Convert object into a record Apply command line params ProcessRecord() EndProcessing() 27 Ubiquitous Navigation FileSystems are easy to use Navigation 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 28 Navigation Provider Concepts 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 29 Navigation 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); } .... } 30 Navigation Provider – Or What Whackball Would Treat Registry Like A Filesystem? James Truher MSH Program Manager [email protected] 31 How It Works MSH Engine Cmdlet Cmdlet Cmdlet … Core Commands (get, set, rename, move, push, pop, …) Core Command Base Classes FileSys Provider Registry Provider AD Provider 32 Longhorn 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. 33 Call To Action 1. Write managed code interfaces to your services and objects 2. Design your task model 3. Write Cmdlets for invariant actions 4. Write MSH scripts for actions which vary between customers 5. Write Navigation providers to expose namespaces 34 HAPPY BIRTHDAY To JIM TRUHER 35 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 36