Exemplo n.º 1
0
        public async Task <HttpResponseMessage> PerformServerAction([FromBody] ServerActionRequest request, [FromUri] string tenant_id, [FromUri] string server_id)
        {
            if (request.CreateImage != null)
            {
                // Get base image
                var servers = await _computeClient.GetDeployedServers();

                if (servers == null)
                {
                    return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError));
                }

                var server = servers.First(s => s.id == server_id);
                if (server == null)
                {
                    return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
                }
                HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
                response.Headers.Add("Location", UrlGenerator.GetImageUri(Request.RequestUri.Host, tenant_id, server.sourceImageId));

                return(response);
            }
            if (request.ChangePassword != null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
            }
        }
        public async Task <ServerImageListResponse> GetServerImagesDetailed(string tenant)
        {
            var remoteImageCollection = await _computeClient.GetImages("AU1");

            List <Models.image.ServerImage> images = new List <Models.image.ServerImage>();

            foreach (var image in remoteImageCollection)
            {
                images.Add(
                    new Models.image.ServerImage()
                {
                    Id          = image.id,
                    CreatedDate = image.deployedTime.ToString("s"),
                    Links       = new RestLink[]
                    {
                        new RestLink(UrlGenerator.GetImageUri(tenant, image.id), RestLink.Self)
                    },
                    MinDisk     = 1,                         // No equivalent?
                    MinRam      = image.machineSpecification.memoryMb,
                    Name        = image.name,
                    UpdatedDate = image.deployedTime.ToString("s")
                });
            }

            return(new ServerImageListResponse()
            {
                Images = images.ToArray()
            });
        }
        public async Task <ServerImageResponse> GetServerImage(string tenant, string image)
        {
            var images = await _computeClient.GetImages("AU1");

            var selectedImage = images.First(i => i.id == image);

            if (selectedImage == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return(new ServerImageResponse()
            {
                Image = new Models.image.ServerImage()
                {
                    Id = selectedImage.id,
                    CreatedDate = selectedImage.deployedTime.ToString("s"),
                    Links = new[]
                    {
                        new RestLink(UrlGenerator.GetImageUri(tenant, image), RestLink.Self)
                    },
                    MinDisk = 1,                     // No equivalent?
                    MinRam = selectedImage.machineSpecification.memoryMb,
                    Name = selectedImage.name,
                    UpdatedDate = selectedImage.deployedTime.ToString("s")
                }
            });
        }
        public async Task <BaseServerImageListResponse> GetServerImages(string tenant)
        {
            var remoteImageCollection = await _computeClient.GetImages("AU1");

            List <BaseServerImage> images = new List <BaseServerImage>();

            foreach (var image in remoteImageCollection)
            {
                images.Add(
                    new BaseServerImage()
                {
                    Id    = image.id,
                    Links = new[]
                    {
                        new RestLink(UrlGenerator.GetImageUri(tenant, image.id), RestLink.Self)
                    },
                    Name = image.name
                });
            }

            return(new BaseServerImageListResponse()
            {
                Images = images.ToArray()
            });
        }
Exemplo n.º 5
0
 public ServerDetail CaaSServerToServerDetail(ServerWithBackupType server, string tenant_id)
 {
     return(new ServerDetail()
     {
         AccessIPv4 = server.privateIp,
         AccessIPv6 = "", // IPv6 not supported at present
         CreatedDate = server.created.ToString("s"),
         HostId = server.name,
         Id = Guid.Parse(server.id),
         Image = new ServerImage()
         {
             Id = server.sourceImageId,
             Links = new RestLink[]
             {
                 new RestLink(
                     UrlGenerator.GetImageUri(Request.RequestUri.Host, tenant_id, server.sourceImageId),
                     RestLink.Bookmark
                     )
             }
         },
         IpAddressCollection = new IPAddressCollection()
         {
             PrivateAddresses = new IPAddress[]
             {
                 new IPAddress(server.privateIp)
             },
             PublicAddresses = new IPAddress[]
             {
                 new IPAddress(server.publicIp)
             }
         },
         Flavor = new Flavor(),
         Name = server.name,
         Links = new RestLink[]
         {
             new RestLink(ServerController.GetServerUri(Request.RequestUri.Host, tenant_id, server.id), RestLink.Self)
         },
         UserId = Request.GetRequestContext().Principal.Identity.Name,
         TenantId = tenant_id,
         Metadata = new
         {
             MyServerName = server.name
         },                           // TODO: decide what metadata should be shown.
         Status = ServerStatus.Active // TODO : Map CaaS status.
     });
 }