Devdeep Singh 36b8b357e6 Changes to attach the system vm iso when booting the virtual router - part 1.
Copy the iso to the secondary storage and let the hypervisor agent know of its
location during setup. The agent will copy it over once it handles the setup
command.
Changes for attaching the systemvm iso to virtual router will booting it -
part 2. The agent copies over the systemvm iso during setup. When a
virtual router is being booted it attaches the iso to it.
Hyperv unit tests for  the agent. Unit tests are written using NSubstitute and XUnit and
they test the create, stop and start commands in the agent.
Fix to make sure the hyperv agent and the funcitonal tests are working after the unit tests update.
Fixing the warnings while running unit tests for hyper agent.
Added a new switch for functional tests.
Update the unit test to create a fake vhd file on the fly and run the test. The file is removed when the test completes.
Fix for functional tests. The test was failing to build on java 1.6.
Fix to bring up SSVM and Console Proxy systemvms
Fix to discover the seeded template to bring up the systemvm's for the first startup and fixed UNC path isues
Fixed the UNC path for copying the files from CIFS, and from seeded template
Fixed the issues for ssvm and cpvm to wait until it gets configured and then return the status. Made checksum method to return true.
Fixed HypervDirectConnect resource to figure out the status of systemvms, Need to fix this issue by connecting to public/control ip instead of local ip
checksum is failing for the copied system vm images, currently bypassing.
2013-11-04 18:48:54 +05:30

133 lines
5.2 KiB
C#

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.SelfHost;
using System.Web.Http;
using log4net;
using HypervResource;
namespace CloudStack.Plugin.AgentShell
{
public partial class AgentService : ServiceBase
{
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
static extern bool AllocConsole();
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
static extern bool FreeConsole();
HttpSelfHostServer server;
private static ILog logger = LogManager.GetLogger(typeof(AgentService));
public AgentService()
{
logger.Info("Starting CloudStack agent");
InitializeComponent();
UriBuilder baseUri = new UriBuilder("http", AgentSettings.Default.private_ip_address, AgentSettings.Default.port);
var config = new HttpSelfHostConfiguration(baseUri.Uri);
// Allow ActionName to be applied to methods in ApiController, which allows it to serve multiple POST URLs
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{action}",
new { action = RouteParameter.Optional }
);
// Load controller assemblies that we want to config to route to.
ConfigServerResource();
AssertControllerAssemblyAvailable(config, typeof(HypervResourceController), "Cannot load Controller of type" + typeof(HypervResourceController));
server = new HttpSelfHostServer(config);
}
public static void ConfigServerResource()
{
// For simplicity, ServerResource config and settings file are tightly coupled.
// An alternative is to pass a dictionary to the server resource and let it find
// required settings. In contrast, the approach below is strongly typed and makes
// use of VisualStudio settings designer. The designer allows us to avoid
// accessing config using their key strings.
HypervResourceControllerConfig rsrcCnf = new HypervResourceControllerConfig();
rsrcCnf.PrivateIpAddress = AgentSettings.Default.private_ip_address;
rsrcCnf.GatewayIpAddress = AgentSettings.Default.gateway_ip_address;
rsrcCnf.RootDeviceReservedSpaceBytes = AgentSettings.Default.RootDeviceReservedSpaceBytes;
rsrcCnf.RootDeviceName = AgentSettings.Default.RootDeviceName;
rsrcCnf.ParentPartitionMinMemoryMb = AgentSettings.Default.dom0MinMemory;
rsrcCnf.LocalSecondaryStoragePath = AgentSettings.Default.local_secondary_storage_path;
rsrcCnf.systemVmIso = null;
// Side effect: loads the assembly containing HypervResourceController, which
// allows HttpSelfHostServer to route requests to the controller.
HypervResourceController.Configure(rsrcCnf);
}
// TODO: update to examine not the assembly resolver, but the list of available controllers themselves!
private static bool AssertControllerAssemblyAvailable(HttpSelfHostConfiguration config, Type controllerType, string errorMessage)
{
var assemblies = config.Services.GetAssembliesResolver().GetAssemblies();
foreach (var assembly in assemblies)
{
string name = assembly.GetName().Name;
if (controllerType.Assembly.GetName().Name.Equals(name))
{
logger.DebugFormat("Controller {0} is available", controllerType.Name);
return true;
}
}
logger.Error(errorMessage);
throw new AgentShellException(errorMessage);
}
protected override void OnStart(string[] args)
{
server.OpenAsync().Wait();
}
protected override void OnStop()
{
server.CloseAsync().Wait();
}
internal void RunConsole(string[] args)
{
OnStart(args);
AllocConsole();
Console.WriteLine("Service running ... press <ENTER> to stop");
Console.ReadLine();
FreeConsole();
OnStop();
}
}
}