Ejemplo n.º 1
0
        private T CreateVMContext <T>(string serviceName, NSM.Role vmRole, NSM.RoleInstance roleInstance, NSM.DeploymentGetResponse deployment)
            where T : PVM.PersistentVMRoleContext, new()
        {
            var vmContext = new T
            {
                ServiceName         = serviceName,
                DeploymentName      = deployment == null ? string.Empty : deployment.Name,
                DNSName             = deployment == null || deployment.Uri == null ? string.Empty : deployment.Uri.AbsoluteUri,
                Name                = vmRole == null ? string.Empty : vmRole.RoleName,
                AvailabilitySetName = vmRole == null ? string.Empty : vmRole.AvailabilitySetName,
                Label               = vmRole == null ? string.Empty : vmRole.Label,
                InstanceSize        = vmRole == null ? string.Empty : vmRole.RoleSize,
                InstanceStatus      = roleInstance == null ? string.Empty : roleInstance.InstanceStatus,
                IpAddress           = roleInstance == null ? string.Empty : roleInstance.IPAddress,
                PublicIPAddress     = roleInstance == null ? string.Empty
                                            : roleInstance.PublicIPs == null || !roleInstance.PublicIPs.Any() ? string.Empty
                                            : roleInstance.PublicIPs.First().Address,
                PublicIPName = roleInstance == null ? string.Empty
                                            : roleInstance.PublicIPs == null || !roleInstance.PublicIPs.Any() ? string.Empty
                                            : !string.IsNullOrEmpty(roleInstance.PublicIPs.First().Name) ? roleInstance.PublicIPs.First().Name
                                            : PersistentVMHelper.GetPublicIPName(vmRole),
                InstanceStateDetails = roleInstance == null ? string.Empty : roleInstance.InstanceStateDetails,
                PowerState           = roleInstance == null ? string.Empty : roleInstance.PowerState.ToString(),
                HostName             = roleInstance == null ? string.Empty : roleInstance.HostName,
                InstanceErrorCode    = roleInstance == null ? string.Empty : roleInstance.InstanceErrorCode,
                InstanceName         = roleInstance == null ? string.Empty : roleInstance.InstanceName,
                InstanceFaultDomain  = roleInstance == null ? string.Empty : roleInstance.InstanceFaultDomain.HasValue
                                                                                  ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                InstanceUpgradeDomain = roleInstance == null ? string.Empty : roleInstance.InstanceUpgradeDomain.HasValue
                                                                                  ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                Status                      = roleInstance == null ? string.Empty : roleInstance.InstanceStatus,
                GuestAgentStatus            = roleInstance == null ? null : Mapper.Map <PVM.GuestAgentStatus>(roleInstance.GuestAgentStatus),
                ResourceExtensionStatusList = roleInstance == null ? null : Mapper.Map <List <PVM.ResourceExtensionStatus> >(roleInstance.ResourceExtensionStatusList),
                OperationId                 = deployment == null ? string.Empty : deployment.RequestId,
                OperationStatus             = deployment == null ? string.Empty : deployment.StatusCode.ToString(),
                OperationDescription        = CommandRuntime.ToString(),
                NetworkInterfaces           = roleInstance == null ? null : Mapper.Map <PVM.NetworkInterfaceList>(roleInstance.NetworkInterfaces),
                VirtualNetworkName          = deployment == null ? null : deployment.VirtualNetworkName,
                VM = new PVM.PersistentVM
                {
                    AvailabilitySetName = vmRole == null ? string.Empty : vmRole.AvailabilitySetName,
                    Label    = vmRole == null ? string.Empty : vmRole.Label,
                    RoleName = vmRole == null ? string.Empty : vmRole.RoleName,
                    RoleSize = vmRole == null ? string.Empty : vmRole.RoleSize,
                    RoleType = vmRole == null ? string.Empty : vmRole.RoleType,
                    DefaultWinRmCertificateThumbprint = vmRole == null ? string.Empty : vmRole.DefaultWinRmCertificateThumbprint,
                    ProvisionGuestAgent         = vmRole == null ? null : vmRole.ProvisionGuestAgent,
                    ResourceExtensionReferences = vmRole == null ? null : Mapper.Map <PVM.ResourceExtensionReferenceList>(vmRole.ResourceExtensionReferences),
                    DataVirtualHardDisks        = vmRole == null ? null : Mapper.Map <Collection <PVM.DataVirtualHardDisk> >(vmRole.DataVirtualHardDisks),
                    OSVirtualHardDisk           = vmRole == null ? null : Mapper.Map <PVM.OSVirtualHardDisk>(vmRole.OSVirtualHardDisk),
                    ConfigurationSets           = vmRole == null ? null : PersistentVMHelper.MapConfigurationSets(vmRole.ConfigurationSets)
                }
            };

            return(vmContext);
        }
Ejemplo n.º 2
0
        public void GetRoleProcess()
        {
            OperationStatusResponse getDeploymentOperation;
            var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation);

            if (currentDeployment != null)
            {
                if (this.InstanceDetails.IsPresent)
                {
                    Collection <RoleInstanceContext> instanceContexts = new Collection <RoleInstanceContext>();
                    IList <RoleInstance>             roleInstances    = null;

                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roleInstances = currentDeployment.RoleInstances;
                    }
                    else
                    {
                        roleInstances = new List <RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (var role in roleInstances)
                    {
                        var vmRole = currentDeployment.Roles == null || !currentDeployment.Roles.Any() ? null
                                   : currentDeployment.Roles.FirstOrDefault(r => string.Equals(r.RoleName, role.RoleName, StringComparison.OrdinalIgnoreCase));

                        instanceContexts.Add(new RoleInstanceContext
                        {
                            ServiceName           = this.ServiceName,
                            OperationId           = getDeploymentOperation.Id,
                            OperationDescription  = this.CommandRuntime.ToString(),
                            OperationStatus       = getDeploymentOperation.Status.ToString(),
                            InstanceErrorCode     = role.InstanceErrorCode,
                            InstanceFaultDomain   = role.InstanceFaultDomain,
                            InstanceName          = role.InstanceName,
                            InstanceSize          = role.InstanceSize,
                            InstanceStateDetails  = role.InstanceStateDetails,
                            InstanceStatus        = role.InstanceStatus,
                            InstanceUpgradeDomain = role.InstanceUpgradeDomain,
                            RoleName        = role.RoleName,
                            IPAddress       = role.IPAddress,
                            PublicIPAddress = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Address,
                            PublicIPName    = role.PublicIPs == null || !role.PublicIPs.Any() ? null
                                                  : !string.IsNullOrEmpty(role.PublicIPs.First().Name) ? role.PublicIPs.First().Name
                                                  : PersistentVMHelper.GetPublicIPName(vmRole),
                            DeploymentID      = currentDeployment.PrivateId,
                            InstanceEndpoints = Mapper.Map <PVM.InstanceEndpointList>(role.InstanceEndpoints)
                        });
                    }

                    WriteObject(instanceContexts, true);
                }
                else
                {
                    var          roleContexts = new Collection <RoleContext>();
                    IList <Role> roles        = null;
                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roles = currentDeployment.Roles;
                    }
                    else
                    {
                        roles = new List <Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (var r in roles.Select(role => new RoleContext
                    {
                        InstanceCount = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)),
                        RoleName = role.RoleName,
                        OperationDescription = this.CommandRuntime.ToString(),
                        OperationStatus = getDeploymentOperation.Status.ToString(),
                        OperationId = getDeploymentOperation.Id,
                        ServiceName = this.ServiceName,
                        DeploymentID = currentDeployment.PrivateId
                    }))
                    {
                        roleContexts.Add(r);
                    }

                    WriteObject(roleContexts, true);
                }
            }
        }