mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-03-09 13:50:13 +01:00
Attach iso to virtual machines
This commit is contained in:
@@ -366,7 +366,7 @@ class CyberTron(multi.Thread):
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, str(msg) + ' [404]')
|
||||
return 0
|
||||
|
||||
def bootVirtualMachine(self, package, vmName, vncHost, vncPort, vncPassword, webSocketPort, hostname, bridgeName, tempStatusPath):
|
||||
def bootVirtualMachine(self, package, vmName, vncHost, vncPort, vncPassword, webSocketPort, hostname, bridgeName, isoPath, tempStatusPath):
|
||||
try:
|
||||
|
||||
if logLevel.debug == True:
|
||||
@@ -376,10 +376,19 @@ class CyberTron(multi.Thread):
|
||||
|
||||
# virt-install --name 109.238.12.214 --ram 2048 --vcpus=1 --disk 109.238.12.214.qcow2 --graphics vnc,listen=localhost,port=5500 --noautoconsole --hvm --import --os-type=linux --os-variant=rhel7 --network bridge=virbr0
|
||||
|
||||
command = "sudo virt-install --name " + hostname + " --ram " + str(package.guaranteedRam) + " --vcpu " + str(package.cpuCores) + " --disk " + \
|
||||
finalImageLocation + " --graphics vnc,listen=" + vncHost + ",port=" + vncPort + ",password=" + vncPassword + \
|
||||
" --noautoconsole --hvm --import --autostart --os-type=linux " \
|
||||
+ "--network bridge=" + bridgeName
|
||||
if isoPath == None:
|
||||
|
||||
command = "sudo virt-install --name " + hostname + " --ram " + str(package.guaranteedRam) + " --vcpu " + str(package.cpuCores) + " --disk " + \
|
||||
finalImageLocation + " --graphics vnc,listen=" + vncHost + ",port=" + vncPort + ",password=" + vncPassword + \
|
||||
" --noautoconsole --hvm --import --autostart --os-type=linux " \
|
||||
+ "--network bridge=" + bridgeName
|
||||
else:
|
||||
size = package.diskSpace
|
||||
command = "sudo virt-install --name " + hostname + " --ram " + str(package.guaranteedRam) + " --vcpu " \
|
||||
+ str(package.cpuCores) + " --disk path=" + finalImageLocation + ",size=" + size + \
|
||||
" --graphics vnc,listen=" + vncHost + ",port=" + vncPort + ",password=" + vncPassword + \
|
||||
" --noautoconsole --hvm --autostart --os-type=linux " \
|
||||
+ "--network bridge=" + bridgeName + ' --cdrom=' + isoPath
|
||||
|
||||
result = call(split(command))
|
||||
|
||||
@@ -407,7 +416,6 @@ class CyberTron(multi.Thread):
|
||||
def createVirtualMachine(self, data):
|
||||
try:
|
||||
|
||||
osName = data['osName']
|
||||
vpsPackage = data['vpsPackage']
|
||||
vpsOwner = data['vpsOwner']
|
||||
vpsIP = data['vpsIP']
|
||||
@@ -429,6 +437,11 @@ class CyberTron(multi.Thread):
|
||||
except:
|
||||
initialScript = None
|
||||
|
||||
try:
|
||||
isoPath = data['isoPath']
|
||||
except:
|
||||
isoPath = None
|
||||
osName = data['osName']
|
||||
|
||||
owner = Administrator.objects.get(userName=vpsOwner)
|
||||
package = Package.objects.get(packageName=vpsPackage)
|
||||
@@ -444,22 +457,24 @@ class CyberTron(multi.Thread):
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Hostname is already taken. [404]')
|
||||
return 0, 'Hostname is already taken.'
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Starting to create virtual machine..,10')
|
||||
|
||||
logger.operationsLog('Starting to create virtual machine: ' + vpsIP, 'Info', stack()[0][3])
|
||||
if isoPath == None:
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Starting to create virtual machine..,10')
|
||||
|
||||
##
|
||||
logger.operationsLog('Starting to create virtual machine: ' + vpsIP, 'Info', stack()[0][3])
|
||||
|
||||
uploadSource = self.setupNetworkingFiles(vpsIP, osName, ip.pool, hostname, data['tempStatusPath'])
|
||||
##
|
||||
|
||||
##
|
||||
uploadSource = self.setupNetworkingFiles(vpsIP, osName, ip.pool, hostname, data['tempStatusPath'])
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'],
|
||||
'Creating virtual machine disk..,20')
|
||||
##
|
||||
|
||||
if self.setupVMDisk(hostname, osName, uploadSource, rootPassword, package, data['tempStatusPath'], sshKey, initialScript) == 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Failed to setup virtual machine disk. [404]')
|
||||
return 0
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'],
|
||||
'Creating virtual machine disk..,20')
|
||||
|
||||
if self.setupVMDisk(hostname, osName, uploadSource, rootPassword, package, data['tempStatusPath'], sshKey, initialScript) == 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Failed to setup virtual machine disk. [404]')
|
||||
return 0
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'],
|
||||
'Booting virtual machine..,80')
|
||||
@@ -481,7 +496,7 @@ class CyberTron(multi.Thread):
|
||||
|
||||
vncPassword = randomPassword.generate_pass(50)
|
||||
|
||||
if self.bootVirtualMachine(package, hostname, vncHost, str(vncPort), vncPassword, str(webSocketPort), hostname, 'virbr0', data['tempStatusPath']) == 0:
|
||||
if self.bootVirtualMachine(package, hostname, vncHost, str(vncPort), vncPassword, str(webSocketPort), hostname, 'virbr0', isoPath, data['tempStatusPath']) == 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(data['tempStatusPath'], 'Failed to boot virtual machine. [404]')
|
||||
return 0
|
||||
|
||||
|
||||
@@ -10,8 +10,20 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.goBackDisable = true;
|
||||
$scope.installationDetailsForm = false;
|
||||
$scope.installationProgress = true;
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
var statusFile;
|
||||
|
||||
$scope.installationMethod = function (method) {
|
||||
if(method === 'os'){
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
}else{
|
||||
$scope.isoBox = false;
|
||||
$scope.osBox = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.findIPs = function(){
|
||||
|
||||
$scope.tronLoading = false;
|
||||
@@ -52,8 +64,6 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.installationProgress = false;
|
||||
$scope.currentStatus = "Starting creation..";
|
||||
|
||||
|
||||
|
||||
var url = "/vps/submitVPSCreation";
|
||||
|
||||
var data = {
|
||||
@@ -66,7 +76,8 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
networkSpeed: $scope.networkSpeed,
|
||||
osName: $scope.osName,
|
||||
sshKey: $scope.sshKey,
|
||||
initialScript: $scope.initialScript
|
||||
initialScript: $scope.initialScript,
|
||||
isoPath: $scope.isoPath
|
||||
};
|
||||
|
||||
var config = {
|
||||
@@ -643,6 +654,19 @@ app.controller('manageVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.couldNotConnect = true;
|
||||
var statusFile;
|
||||
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
|
||||
$scope.installationMethod = function (method) {
|
||||
if(method === 'os'){
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
}else{
|
||||
$scope.isoBox = false;
|
||||
$scope.osBox = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.goBack = function () {
|
||||
$scope.installationDetailsForm = false;
|
||||
$scope.installationProgress = true;
|
||||
@@ -745,7 +769,8 @@ app.controller('manageVPSCTRL', function($scope, $http, $timeout) {
|
||||
hostname: $("#vpsHostname").text(),
|
||||
osName : $scope.osName,
|
||||
sshKey : $scope.sshKey,
|
||||
rootPassword: $scope.reinstallPassword
|
||||
rootPassword: $scope.reinstallPassword,
|
||||
isoPath : $scope.isoPath
|
||||
};
|
||||
|
||||
var config = {
|
||||
|
||||
@@ -10,8 +10,20 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.goBackDisable = true;
|
||||
$scope.installationDetailsForm = false;
|
||||
$scope.installationProgress = true;
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
var statusFile;
|
||||
|
||||
$scope.installationMethod = function (method) {
|
||||
if(method === 'os'){
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
}else{
|
||||
$scope.isoBox = false;
|
||||
$scope.osBox = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.findIPs = function(){
|
||||
|
||||
$scope.tronLoading = false;
|
||||
@@ -52,8 +64,6 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.installationProgress = false;
|
||||
$scope.currentStatus = "Starting creation..";
|
||||
|
||||
|
||||
|
||||
var url = "/vps/submitVPSCreation";
|
||||
|
||||
var data = {
|
||||
@@ -66,7 +76,8 @@ app.controller('createVPSCTRL', function($scope, $http, $timeout) {
|
||||
networkSpeed: $scope.networkSpeed,
|
||||
osName: $scope.osName,
|
||||
sshKey: $scope.sshKey,
|
||||
initialScript: $scope.initialScript
|
||||
initialScript: $scope.initialScript,
|
||||
isoPath: $scope.isoPath
|
||||
};
|
||||
|
||||
var config = {
|
||||
@@ -643,6 +654,19 @@ app.controller('manageVPSCTRL', function($scope, $http, $timeout) {
|
||||
$scope.couldNotConnect = true;
|
||||
var statusFile;
|
||||
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
|
||||
$scope.installationMethod = function (method) {
|
||||
if(method === 'os'){
|
||||
$scope.isoBox = true;
|
||||
$scope.osBox = false;
|
||||
}else{
|
||||
$scope.isoBox = false;
|
||||
$scope.osBox = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.goBack = function () {
|
||||
$scope.installationDetailsForm = false;
|
||||
$scope.installationProgress = true;
|
||||
@@ -745,7 +769,8 @@ app.controller('manageVPSCTRL', function($scope, $http, $timeout) {
|
||||
hostname: $("#vpsHostname").text(),
|
||||
osName : $scope.osName,
|
||||
sshKey : $scope.sshKey,
|
||||
rootPassword: $scope.reinstallPassword
|
||||
rootPassword: $scope.reinstallPassword,
|
||||
isoPath : $scope.isoPath
|
||||
};
|
||||
|
||||
var config = {
|
||||
|
||||
@@ -57,14 +57,23 @@
|
||||
</div>
|
||||
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Operating System" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div style="margin-bottom: 2%" class="col-sm-9">
|
||||
<a ng-click="installationMethod('os')" class="btn btn-border btn-alt border-green btn-link font-green" href="" title=""><span>{% trans 'Select OS' %}</span></a>
|
||||
<a ng-click="installationMethod('iso')" class="btn btn-border btn-alt border-green btn-link font-green" href="" title=""><span>{% trans 'Attach ISO' %}</span></a>
|
||||
</div>
|
||||
<label ng-hide="osBox" class="col-sm-3 control-label">{% trans "Operating System" %}</label>
|
||||
<div ng-hide="osBox" class="col-sm-6">
|
||||
<select ng-model="osName" class="form-control">
|
||||
{% for items in osNames %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<label ng-hide="isoBox" class="col-sm-3 control-label">{% trans "ISO Path" %}</label>
|
||||
<div ng-hide="isoBox" class="col-sm-6">
|
||||
<input placeholder="You will have to complete installation via console." type="text" class="form-control" ng-model="isoPath" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
|
||||
@@ -224,15 +224,23 @@
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Operating System" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div style="margin-bottom: 2%" class="col-sm-9">
|
||||
<a ng-click="installationMethod('os')" class="btn btn-border btn-alt border-green btn-link font-green" href="" title=""><span>{% trans 'Select OS' %}</span></a>
|
||||
<a ng-click="installationMethod('iso')" class="btn btn-border btn-alt border-green btn-link font-green" href="" title=""><span>{% trans 'Attach ISO' %}</span></a>
|
||||
</div>
|
||||
<label ng-hide="osBox" class="col-sm-3 control-label">{% trans "Operating System" %}</label>
|
||||
<div ng-hide="osBox" class="col-sm-6">
|
||||
<select ng-model="osName" class="form-control">
|
||||
{% for items in osNames %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<a ng-click="hideAdminTasks()" href=""><img src="{% static 'vpsManagement/close-32.png' %}"></a>
|
||||
<label ng-hide="isoBox" class="col-sm-3 control-label">{% trans "ISO Path" %}</label>
|
||||
<div ng-hide="isoBox" class="col-sm-6">
|
||||
<input placeholder="You will have to complete installation via console." type="text" class="form-control" ng-model="isoPath" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="installationDetailsForm" class="form-group">
|
||||
|
||||
Reference in New Issue
Block a user