Share via


Update (PUT/MERGE) Modules

Update using the HTTP PUT/MERGE operation.

Code Examples

Request

Method Request URI HTTP Version

MERGE

HTTPS://<HOST>:<PORT>/00000000-0000-0000-0000-000000000000/Modules(guid'<GUID>')

HTTP/1.1

Request URI Parameters

URI Parameter Description

NAME

Required. The unique identifier value (ModuleID) for a Module entity.

Request URI Example

Example URI

MERGE https://sma-server:9090/00000000-0000-0000-0000-000000000000/Modules(guid'159fb0d4-8c32-4388-8944-a7ac07678d18') HTTP/1.1

Request Headers

For more information about the common request headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.

Request Body

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <id>https://sma-server:9090/00000000-0000-0000-0000-000000000000/Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')</id>
  <category term="Orchestrator.ResourceModel.Module" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <title />
  <updated>2014-04-18T19:16:26Z</updated>
  <author>
    <name />
  </author>
  <m:properties>
    <d:CreationTime m:type="Edm.DateTime">2014-04-18T17:50:47.393</d:CreationTime>
    <d:LastModifiedTime m:type="Edm.DateTime">2014-04-18T17:50:47.5</d:LastModifiedTime>
    <d:ModuleID m:type="Edm.Guid">41c96c1b-d3ab-43bf-a506-a658811684cd</d:ModuleID>
    <d:ModuleName>Azure-Portable</d:ModuleName>
    <d:TenantID m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:TenantID>
    <d:Version m:type="Edm.Int32">1</d:Version>
  </m:properties>
</entry>

Response

Response Codes

Response Code Description

HTTP/1.1 204 No Content

Request fulfilled.

Response Headers

For more information about the common response headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.

Response Body

The PUT/MERGE operation has no response body.

Code Examples

The following example updates an existing Module, identified by the ModuleName, and updates the module using a local file.

namespace CodeSample.Microsoft.SystemCenter.SMA
{
    public class SMASamples
    {
        public static void Main()
        { 
            // Replace this with the name of your SMA web service endpoint.
            string serviceEndPoint = "https://sma-server:9090/00000000-0000-0000-0000-000000000000";                      

            // Setup the connection to SMA
            OrchestratorApi SMAService = new OrchestratorApi(new Uri(serviceEndPoint));

            // Set credentials to the default or to a specific user.
            ((DataServiceContext)SMAService).Credentials = CredentialCache.DefaultCredentials;
            //((DataServiceContext)SMAService).Credentials = new NetworkCredential("user", "pwd", "domain");

            try
            {
                // Initialize variables with base values.
                var modulePath = "C:\\SMA\\Modules\\Azure-Portable.zip";
                var moduleName = Path.GetFileNameWithoutExtension(modulePath);

                if (!File.Exists(modulePath))
                {
                    //throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, CmdletResources.FileNotFound, this.ModulePath));
                    throw new FileNotFoundException("File not found: {0}", modulePath);
                }

                // Query for the specific module identified by moduleName.
                var modules = SMAService.Modules.Where(m => m.ModuleName.Equals(moduleName, StringComparison.InvariantCultureIgnoreCase));

                // If the module doesn't exist, notify the user.
                // Note: This is specfically an update, though the functionality could be set up as create or update.
                if (modules.Count() == 0)
                {
                    Console.WriteLine("No module with the name {0} exists.", moduleName);
                    Console.ReadLine();
                }
                else
                {
  
                    //Obtain single module instance to update.
                    var module = modules.Single();

                    // Set up stream reader.
                    var moduleReader = new StreamReader(modulePath, Encoding.UTF8);
                    var zipStream = moduleReader.BaseStream;
                    var slugHeader = module.ModuleName;

                    // Update the existing module.
                    // Note: This action is queued up until the SaveChanges action is called.
                    SMAService.UpdateObject(module);
                    SMAService.SetSaveStream(module, zipStream, true, "application/octet-stream", slugHeader);

                    // Save all pending actions (client -> server communication initiated).
                    SMAService.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("An error occurred during execution.", ex);
            }
        }                 
    }
}

See Also

Concepts

Module
Modules