Skip to content

Commit b5255f8

Browse files
committed
kvm interface, auto scheduler
1 parent c0987a5 commit b5255f8

20 files changed

+61
-33
lines changed

README.md

+36-15
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,35 @@
3636
- VIF: virtual interface, the eth on VM
3737
- SR: storage repository, the storage pool on server
3838

39-
# Create KVM VMS
40-
1. Auto schedual the target vm to a available server, this is only available on dev env
39+
# Create KVM VMs Auto Schedule
4140

42-
> lain3_node.py --role=rolename --cluster=<test|xyz|kvm>
41+
Note: `schedule_node.py` can auto schedule the wanted vm to a available server
42+
you can list the supported role with `--list-roles`, if there is no role you want, you can define a new one
43+
in `etc/Nodeconfig.json`, each role is a dict defined the cpu, memory, etc. You can define `k8s-master`,
44+
`k8s-node`, `etcd` template as you want.
45+
46+
for example:
47+
48+
```
49+
"jenkins": {
50+
"cpu": 8,
51+
"memory": 32,
52+
"template": "template",
53+
"disk_size": 100,
54+
"add_disk_num": 2
55+
}
56+
```
57+
58+
## 1. Auto schedual the target vm to a available server
59+
60+
> schedule_node.py --role=rolename --cluster=<dev|test|prod>
61+
62+
> Note: user can define the vm-name rule at function `generate_vmname_key(role, cluster)` in file `lib/Utils/schedule.py`
4363
44-
2. manually given the target vm-name, host and vm-ip. Product env should use this command
64+
## 2. manually given the target vm-name, host and vm-ip.
4565

46-
> lain3_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip
66+
> schedule_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip
67+
4768
# Create multiple VMs from xml config
4869
- `setup_vms.py --validate xmlFile` Validate the given xml file
4970
- `setup_vms.py --create xmlFile` Do the create up according to the xml file
@@ -102,13 +123,13 @@ Create VMs with xml just need to write a xml config following the xml-example. B
102123
- `--list-network` List the bridge/switch network in the host
103124
- `--list-SR` List the storage repository infor in the host
104125

105-
##### 1). <b>**Create a new VM with a template:**<b>
126+
##### 2.1). <b>**Create a new VM with a template:**<b>
106127
- `-c VM_NAME, --create=VM_NAME` Create a new VM with a template.
107128
- `-t TEMPLATE, --templ=TEMPLATE` Template used to create a new VM.
108129

109-
> create_vm.py -c "test_vm" -t "CentOS 7.2 for Lain"
130+
> create_vm.py -c "test_vm" -t "CentOS 7.2 Template"
110131
111-
##### 2). <b>**Create a new VM with a given IP: if a IP specified**<b>
132+
##### 2.2). <b>**Create a new VM with a given IP: if a IP specified**<b>
112133
- `--vif=VIF_INDEX` The index of virtual interface on which configure will be
113134
- `--device=DEVICE` The target physic NIC name with an associated network VIF attach(ed) to
114135
- `--network=NETWORK` The target bridge/switch network which VIF connect(ed) to
@@ -122,15 +143,15 @@ Create VMs with xml just need to write a xml config following the xml-example. B
122143
**neither *--device* nor *--network*, the default manage network will be used**
123144
> create_vm.py -c "test2" -t "CentOS 7.2 template" --ip=192.168.1.100 --vif=0
124145
125-
##### 3). <b>**Create a new VM with given max cpu cores and current cpu cores:**<b>
146+
##### 2.3). <b>**Create a new VM with given max cpu cores and current cpu cores:**<b>
126147
- `--cpu-max=MAX_CORES` Config the max VCPU cores.
127148
- `--cpu-cores=CPU_CORES` Config the number of startup VCPUs for the new created VM
128149

129150
> create_vm.py -c "test2" -t "CentOS 7.2 template" --cpu-core=2 --cpu-max=4
130151
131152
   The max cpu cores can be configured when VM is power off only, and it affect the upper limit when set the cpu cores lively
132153

133-
##### 4). <b>**Create a new VM with memory size:**<b>
154+
##### 2.4). <b>**Create a new VM with memory size:**<b>
134155
- `--memory=MEMORY_SIZE` Config the target memory size in GB.
135156
- `--min-mem=MIN_MEMORY` Config the min static memory size in GB.
136157
- `--max-mem=MAX_MEMORY` Config the max static memory size in GB.
@@ -144,7 +165,7 @@ Create VMs with xml just need to write a xml config following the xml-example. B
144165
- `--max-mem will set the max static memory `
145166
> create_vm.py -c "test2" -t "CentOS 7.2 template" --memory=2 --max-mem=4
146167
147-
##### 5).Add new disk to VM, the storage_name is choosed from *--list-SR*
168+
##### 2.5).Add new disk to VM, the storage_name is choosed from *--list-SR*
148169
- `--add-disk=DISK_SIZE` The disk size(GB) add to the VM
149170
- `--storage=STORAGE_NAME` The storage location where the virtual disk put
150171
> create_vm.py "test1"--add-disk=2 --storage=data2
@@ -165,7 +186,7 @@ Create VMs with xml just need to write a xml config following the xml-example. B
165186
- `--list-network` List the bridge/switch network in the host
166187
- `--list-SR` List the storage repository information in the host
167188

168-
##### 1). <b>**Config a VM's interface, add a VIF, delete a VIF, config a VIF(will delete old one if exist, otherwise create it newly), and the *--ip*, *--device*, *--network* is same as that when create vm**<b>
189+
##### 4.1). <b>**Config a VM's interface, add a VIF, delete a VIF, config a VIF(will delete old one if exist, otherwise create it newly), and the *--ip*, *--device*, *--network* is same as that when create vm**<b>
169190
- `--add-vif=ADD_INDEX` Add a virtual interface device to guest VM
170191
- `--del-vif=DEL_INDEX` Delete a virtual interface device from guest VM
171192
- `--vif=VIF_INDEX` Configure on a virtual interface device
@@ -174,17 +195,17 @@ Create VMs with xml just need to write a xml config following the xml-example. B
174195
175196
> config_vm.py "test1" --add-vif=1 --device=eth1 --ip=192.168.1.200 --netmask=255.255.255.0
176197
177-
##### 2). <b>**config a VM' cpu when it is running**<b>
198+
##### 4.2). <b>**config a VM' cpu when it is running**<b>
178199
- `--cpu-cores=CPU_CORES` Config the VCPU cores lively for a running VM or the number of startup VCPUs for a halted VM
179200

180201
> config_vm.py "test1" --cpu-core=4
181202

182-
##### 3). <b>**config a VM' memory when it is running**<b>
203+
##### 4.3). <b>**config a VM' memory when it is running**<b>
183204
- `--memory=MEMORY_SIZE` Config the target memory size in GB.
184205

185206
> config_vm.py "test1" --memory=1
186207
187-
##### 4).Add new disk to VM, the storage_name is choosed from *--list-SR*
208+
##### 4.4).Add new disk to VM, the storage_name is choosed from *--list-SR*
188209
- `--add-disk=DISK_SIZE` The disk size(GB) add to the VM
189210
- `--storage=STORAGE_NAME` The storage location where the virtual disk put
190211
> config_vm.py "test1"--add-disk=2 --storage=data2

etc/lain3Nodeconfig.json etc/Nodeconfig.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"master": {
2+
"k8s-master": {
33
"cpu": 8,
44
"memory": 16,
55
"template": "k8s-template"
66
},
7-
"ingress": {
7+
"k8s-ingress": {
88
"cpu": 8,
99
"memory": 16,
1010
"template": "k8s-template"
1111
},
12-
"node": {
12+
"k8s-node": {
1313
"cpu": 16,
1414
"memory": 48,
1515
"template": "k8s-template"
@@ -30,5 +30,12 @@
3030
"cpu": 4,
3131
"memory": 8,
3232
"template": "nfs-template"
33+
},
34+
"gluster": {
35+
"cpu": 4,
36+
"memory": 6,
37+
"template": "nfs-template",
38+
"disk_size": 50,
39+
"add_disk_num": 2
3340
}
3441
}

lib/Log/logging_server.py

100644100755
File mode changed.

lib/Utils/constans.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
File Name: constans.py
55
Author: longhui
66
Created Time: 2019-04-24 11:07:34
7-
Description: lain3 node for k8s cluster default config
7+
Description: different role of node with default config
88
"""
99
template_dict = {
1010

11-
"master": {"cpu": 8, "memory": 16, "template": "k8s-template"},
12-
"ingress": {"cpu": 8, "memory": 16, "template": "k8s-template"},
13-
"node": {"cpu": 16, "memory": 32, "template": "k8s-template", "disk_size": 200, "add_disk_num": 1},
11+
"k8s-master": {"cpu": 8, "memory": 16, "template": "k8s-template"},
12+
"k8s-ingress": {"cpu": 8, "memory": 16, "template": "k8s-template"},
13+
"k8s-node": {"cpu": 16, "memory": 32, "template": "k8s-template", "disk_size": 200, "add_disk_num": 1},
1414
"etcd": {"cpu": 4, "memory": 8, "template": "k8s-template", "disk_size": 100, "add_disk_num": 1},
1515
"jenkins": {"cpu": 8, "memory": 32, "template": "template", "disk_size": 100, "add_disk_num": 2},
1616
}

lib/Val/Xen/virt_driver_xen_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class XenVirtDriverTestCase(unittest.TestCase):
1414

1515
def setUp(self):
1616
self.virt_driver = XenVirtDriver(hostname="192.168.1.2", user="root", passwd="123456")
17-
self.vms = ['t2-dev16', 't2-jenkins-lain2', 't2-dev24', 't2-dev23', 't2-dev25', 't2-dev26', 't2-dev22']
17+
self.vms = ['t2-dev16', 't2-jenkins', 't2-dev24', 't2-dev23', 't2-dev25', 't2-dev26', 't2-dev22']
1818

1919
def tearDown(self):
2020
self.virt_driver.delete_handler()
@@ -29,7 +29,7 @@ def test_get_vm_list(self):
2929
self.assertEqual(vm in dst_vms, True, "%s not there" % vm)
3030

3131
def test_get_template_list(self):
32-
templates = ["CentOS 7.2 for Lain"]
32+
templates = ["CentOS 7.2 Template"]
3333
dst_templates = self.virt_driver.get_templates_list()
3434
self.assertNotEqual(dst_templates, [], "get_templates_list() return []")
3535
for templ in templates:

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
six
22
ipaddress
33
requests
4-
urllib3==1.23
4+
urllib3==1.24.2
55
chardet
66
certifi
77
idna

scripts/config_kvm_ip.sh

100644100755
File mode changed.

scripts/config_vm.py

100644100755
File mode changed.

scripts/config_xenvm_ip.sh

100644100755
File mode changed.

scripts/create_vm.py

100644100755
File mode changed.

scripts/delete_vm.py

100644100755
File mode changed.

scripts/dump_host.py

100644100755
File mode changed.

scripts/dump_vm.py

100644100755
File mode changed.

scripts/power_off.py

100644100755
File mode changed.

scripts/power_on.py

100644100755
File mode changed.

scripts/reboot_vm.py

100644100755
File mode changed.

scripts/lain3_node.py scripts/schedule_node.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4-
File Name: lain3_node.py
4+
File Name: schedule_node.py
55
Author: longhui
66
Created Time: 2019-04-24 10:44:45
7-
Description: Add lain3 node for k8s cluster
7+
Description: schedule different type of node to server, for k8s, jenkins, etcd cluster and so on
88
"""
99
import json
1010
import os
@@ -19,9 +19,9 @@
1919

2020
if __name__ == "__main__":
2121
usage = """usage: %prog [options] arg1 arg2\n
22-
lain3_node.py --role=rolename --cluster=[test|xyz|kvm]
23-
lain3_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip
24-
lain3_node.py --list-roles
22+
schedule_node.py --role=rolename --cluster=[test|xyz|kvm]
23+
schedule_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip
24+
schedule_node.py --list-roles
2525
"""
2626
parser = OptionParser(usage=usage)
2727
parser.add_option("--role", dest="rolename", help="Config the target role of vm to create.")
@@ -40,7 +40,7 @@
4040

4141
config_dict = template_dict
4242
try:
43-
config_file = os.path.join(os.path.dirname(__file__), "../etc/lain3Nodeconfig.json")
43+
config_file = os.path.join(os.path.dirname(__file__), "../etc/Nodeconfig.json")
4444
with open(config_file, "r") as f:
4545
try:
4646
config = json.load(f)
@@ -69,7 +69,7 @@
6969
log.fail("Does not support role: %s", options.rolename)
7070
exit(1)
7171

72-
# if "--cluster" is given, use command "lain3_node.py --role=rolename --cluster=cluster-name"
72+
# if "--cluster" is given, use command "schedule_node.py --role=rolename --cluster=cluster-name"
7373
if options.cluster is not None:
7474
cluster_name = options.cluster
7575
# when no input, find default server and default vmname and IP
@@ -90,7 +90,7 @@
9090
exit(1)
9191

9292
else:
93-
# use command "lain3_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip"
93+
# use command "schedule_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip"
9494
if options.hostip is None or options.new_vm_name is None or options.vm_ip is None:
9595
log.fail("'--name=new_vm_name --host=hostip --ip=vm_ip' is required when with no '--cluster'.")
9696
exit(1)

scripts/setup_k8s.sh

100644100755
File mode changed.

scripts/setup_vms.py

100644100755
File mode changed.

scripts/sync_server_info.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)