-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com> # Conflicts: # ocaml/sdk-gen/powershell/gen_powershell_binding.ml
- Loading branch information
Showing
2 changed files
with
201 additions
and
80 deletions.
There are no files selected for viewing
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
173 changes: 173 additions & 0 deletions
173
ocaml/sdk-gen/powershell/templates/Remove-XenObject.mustache
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,173 @@ | ||
/* | ||
* Copyright (c) Cloud Software Group, Inc. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1) Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2) Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
|
||
using System; | ||
using System.Management.Automation; | ||
using XenAPI; | ||
|
||
namespace Citrix.XenServer.Commands | ||
{ | ||
[Cmdlet(VerbsCommon.Remove, "Xen{{class_name}}", SupportsShouldProcess = true)] | ||
{{#async}} | ||
[OutputType(typeof(XenAPI.Task))] | ||
{{/async}} | ||
[OutputType(typeof(void))] | ||
public class RemoveXen{{class_name}} : XenServerCmdlet | ||
{ | ||
#region Cmdlet Parameters | ||
[Parameter] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
[Parameter(ParameterSetName = "XenObject", Mandatory = true, ValueFromPipeline = true, Position = 0)] | ||
public {{type}} {{property}} { get; set; } | ||
|
||
[Parameter(ParameterSetName = "Ref", Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)] | ||
[Alias("opaque_ref")] | ||
public XenRef<{{type}}> Ref { get; set; } | ||
|
||
{{#has_uuid}} | ||
[Parameter(ParameterSetName = "Uuid", Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)] | ||
public Guid Uuid { get; set; } | ||
|
||
{{/has_uuid}} | ||
{{#has_name}} | ||
[Parameter(ParameterSetName = "Name", Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)] | ||
[Alias("name_label")] | ||
public string Name { get; set; } | ||
|
||
{{/has_name}} | ||
{{#async}} | ||
protected override bool GenerateAsyncParam => true; | ||
|
||
{{/async}} | ||
#endregion | ||
|
||
#region Cmdlet Methods | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
GetSession(); | ||
string {{type_local}} = Parse{{class_name}}(); | ||
|
||
ProcessRecordDestroy({{type_local}}); | ||
|
||
UpdateSessions(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
private string Parse{{class_name}}() | ||
{ | ||
string {{type_local}} = null; | ||
|
||
if ({{property}} != null) | ||
{ | ||
{{type_local}} = (new XenRef<{{type}}>({{property}})).opaque_ref; | ||
} | ||
{{#has_uuid}} | ||
else if (Uuid != Guid.Empty) | ||
{ | ||
var xenRef = {{type}}.get_by_uuid(session, Uuid.ToString()); | ||
if (xenRef != null) | ||
{{type_local}} = xenRef.opaque_ref; | ||
} | ||
{{/has_uuid}} | ||
{{#has_name}} | ||
else if (Name != null) | ||
{ | ||
var xenRefs = {{type}}.get_by_name_label(session, Name); | ||
if (xenRefs.Count == 1) | ||
{{type_local}} = xenRefs[0].opaque_ref; | ||
else if (xenRefs.Count > 1) | ||
ThrowTerminatingError(new ErrorRecord( | ||
new ArgumentException(string.Format("More than one {{type}} with name label {0} exist", Name)), | ||
string.Empty, | ||
ErrorCategory.InvalidArgument, | ||
Name)); | ||
} | ||
{{/has_name}} | ||
else if (Ref != null) | ||
{ | ||
{{type_local}} = Ref.opaque_ref; | ||
} | ||
else | ||
{ | ||
ThrowTerminatingError(new ErrorRecord( | ||
new ArgumentException("At least one of the parameters '{{property}}', 'Ref', 'Uuid' must be set"), | ||
string.Empty, | ||
ErrorCategory.InvalidArgument, | ||
{{property}})); | ||
} | ||
|
||
return {{type_local}}; | ||
} | ||
|
||
private void ProcessRecordDestroy(string {{type_local}}) | ||
{ | ||
if (!ShouldProcess({{type_local}}, "{{wire_class_name}}.destroy")) | ||
return; | ||
|
||
{{#async}} | ||
RunApiCall(() => | ||
{ | ||
if (_context is XenServerCmdletDynamicParameters conTxt && conTxt.Async) | ||
{ | ||
taskRef = {{type}}.async_destroy(session, {{type_local}}); | ||
|
||
if (PassThru) | ||
{ | ||
XenAPI.Task taskObj = null; | ||
if (taskRef != "OpaqueRef:NULL") | ||
{ | ||
taskObj = XenAPI.Task.get_record(session, taskRef.opaque_ref); | ||
taskObj.opaque_ref = taskRef.opaque_ref; | ||
} | ||
|
||
WriteObject(taskObj, true); | ||
} | ||
} | ||
else | ||
{ | ||
{{type}}.destroy(session, {{type_local}}); | ||
} | ||
}); | ||
{{/async}} | ||
{{^async}} | ||
RunApiCall(() => {{type}}.destroy(session, {{type_local}})); | ||
{{/async}} | ||
} | ||
|
||
#endregion | ||
} | ||
} |