Created
October 24, 2013 21:03
-
-
Save underscorephil/7144932 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace SLAPI_TEST | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
String username = ""; | |
String apiKey = "”; | |
authenticate authenticate = new authenticate(); | |
authenticate.username = username; | |
authenticate.apiKey = apiKey; | |
SoftLayer_AccountService accountService = new SoftLayer_AccountService(); | |
accountService.authenticateValue = authenticate; | |
SoftLayer_Virtual_GuestService guestService = new SoftLayer_Virtual_GuestService(); | |
guestService.authenticateValue = authenticate; | |
Console.WriteLine("What string to search for?"); | |
string hostnameString = Console.ReadLine(); | |
Console.WriteLine("Are you sure you want to delete any instance whos hostname contains " + hostnameString + "?"); | |
Console.WriteLine("Enter yes or no"); | |
string confirm = Console.ReadLine(); | |
if (confirm != "yes") | |
{ | |
Environment.Exit(0); | |
} | |
SoftLayer_Virtual_Guest[] guests = new SoftLayer_Virtual_Guest[1]; | |
guests = accountService.getVirtualGuests(); | |
List<int> guestsToDelete = new List<int>(); | |
foreach (SoftLayer_Virtual_Guest guest in guests) | |
{ | |
if (guest.hostname.Contains(hostnameString)) | |
{ | |
guestsToDelete.Add(Convert.ToInt32(guest.id)); | |
} | |
else | |
{ | |
continue; | |
} | |
} | |
foreach (int guestId in guestsToDelete) | |
{ | |
SoftLayer_Virtual_GuestInitParameters initParam = new SoftLayer_Virtual_GuestInitParameters(); | |
initParam.id = guestId; | |
guestService.SoftLayer_Virtual_GuestInitParametersValue = initParam; | |
bool result = guestService.deleteObject(); | |
if (result = true) | |
{ | |
Console.WriteLine(guestId + " Deleted"); | |
} | |
else | |
{ | |
Console.WriteLine(guestId + " Not Deleted"); | |
} | |
} | |
Console.WriteLine("Press return to exit"); | |
Console.ReadLine(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment