Beispiel #1
0
    public async Async.Task SendMessage(string name, string message, StorageType storageType, TimeSpan?visibilityTimeout = null, TimeSpan?timeToLive = null)
    {
        var queue = await GetQueueClient(name, storageType);

        try {
            await queue.SendMessageAsync(message, visibilityTimeout : visibilityTimeout, timeToLive : timeToLive);
        } catch (Exception ex) {
            _log.Exception(ex, $"Failed to send message {message}");
            throw;
        }
    }
Beispiel #2
0
    public async Async.Task <IDictionary <Guid, string> > ListInstanceIds(Guid name)
    {
        _log.Verbose($"get instance IDs for scaleset {name}");
        var results = new Dictionary <Guid, string>();
        VirtualMachineScaleSetResource res;

        try {
            var r = await GetVmssResource(name).GetAsync();

            res = r.Value;
        } catch (Exception ex) when(ex is RequestFailedException)
        {
            _log.Verbose($"vm does not exist {name}");
            return(results);
        }

        if (res is null)
        {
            _log.Verbose($"vm does not exist {name}");
            return(results);
        }
        else
        {
            try {
                await foreach (var instance in res !.GetVirtualMachineScaleSetVms().AsAsyncEnumerable())
                {
                    if (instance is not null)
                    {
                        Guid key;
                        if (Guid.TryParse(instance.Data.VmId, out key))
                        {
                            results[key] = instance.Data.InstanceId;
                        }
                        else
                        {
                            _log.Error($"failed to convert vmId {instance.Data.VmId} to Guid");
                        }
                    }
                }
            } catch (Exception ex) when(ex is RequestFailedException || ex is CloudException)
            {
                _log.Exception(ex, $"vm does not exist {name}");
            }
        }
        return(results);
    }
Beispiel #3
0
    public async Task <bool> DeleteDisk(string resourceGroup, string name)
    {
        try {
            _logTracer.Info($"deleting disks {resourceGroup} : {name}");
            var disk = await _creds.GetResourceGroupResource().GetDiskAsync(name);

            if (disk != null)
            {
                await disk.Value.DeleteAsync(WaitUntil.Started);

                return(true);
            }
        } catch (Exception e) {
            _logTracer.Error($"unable to delete disk: {name} {e.Message}");
            _logTracer.Exception(e);
        }
        return(false);
    }