Skip to content

Commit 712db8d

Browse files
committed
rework copy disk for use with agent
1 parent b6350a1 commit 712db8d

15 files changed

Lines changed: 435 additions & 114 deletions

examples/bootstraps/centos.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
sudo yum install -y epel-release
1+
sudo yum install -y epel-release deltarpm
22
sudo yum install -y qemu-kvm libvirt-devel libvirt libvirt-python wget gcc python-devel qemu-system-x86 genisoimage
33
sudo service libvirtd restart
44
sudo groupadd libvirt
55
sudo usermod --append --groups kvm `whoami`
66
sudo usermod --append --groups libvirt `whoami`
7+
sudo usermod --append --groups qemu `whoami`
8+
9+
# check nested virtualization
10+
virt-host-validate
711

812
# cloudify part
913
sudo yum install -y python-virtualenv python-pip git python-netifaces
14+
1015
# env create
1116
CREATEPATH=/opt/centos-libvirt
1217
sudo rm -rf $CREATEPATH
@@ -17,10 +22,29 @@ virtualenv $CREATEPATH
1722
cd $CREATEPATH
1823
source bin/activate
1924
pip install pip --upgrade
20-
pip install cloudify
25+
pip install cloudify==4.3
2126
cfy profile use local
2227

23-
git clone https://github.com/cloudify-incubator/cloudify-libvirt-plugin.git -b master
28+
# enable zram, better to enable, we will run many hungry hosts
29+
git clone https://github.com/mystilleef/FedoraZram.git
30+
sudo cp FedoraZram/{zramstart,zramstat,zramstop} /usr/sbin/
31+
sudo chown root:root /usr/sbin/zram*
32+
sudo chmod 755 /usr/sbin/zram*
33+
34+
sudo cp FedoraZram/mkzram.service /lib/systemd/system
35+
sudo chown root:root /lib/systemd/system/mkzram.service
36+
sudo chmod 644 /lib/systemd/system/mkzram.service
37+
38+
sudo cp FedoraZram/zram /etc/sysconfig
39+
sudo chown root:root /etc/sysconfig/zram
40+
sudo chmod 644 /etc/sysconfig/zram
41+
42+
sudo systemctl daemon-reload
43+
sudo systemctl enable mkzram.service
44+
sudo systemctl start mkzram.service
45+
46+
# run real create
47+
git clone https://github.com/cloudify-incubator/cloudify-libvirt-plugin.git -b virt-cloud
2448
pip install -e cloudify-libvirt-plugin
2549

26-
cfy install cloudify-libvirt-plugin/examples/vm_fabric.amd64.yaml --install-plugins
50+
cfy install cloudify-libvirt-plugin/examples/vm_ssh.amd64.yaml --install-plugins --task-retries 20 --task-retry-interval 30

examples/bootstraps/ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ cfy profile use local
1616
git clone https://github.com/cloudify-incubator/cloudify-libvirt-plugin.git -b master
1717
pip install -e cloudify-libvirt-plugin
1818

19-
cfy install cloudify-libvirt-plugin/examples/vm_fabric.amd64.yaml --install-plugins
19+
cfy install cloudify-libvirt-plugin/examples/vm_ssh.amd64.yaml --install-plugins

examples/cluster.yaml

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,56 @@ imports:
1010
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-libvirt-plugin/0.5.0/plugin.yaml
1111

1212
inputs:
13+
# agent settings
14+
agent_user:
15+
default: { get_secret: agent_user }
1316

17+
# you should use such key for kvm host
18+
agent_public_key:
19+
default: { get_secret: agent_key_public }
20+
21+
disk_size:
22+
default: 24GB
23+
24+
agent_private_key:
25+
default: { get_secret: agent_private_key }
26+
27+
# cluster(kvm) settings
1428
cluster_user:
1529
type: string
1630
description: >
1731
Cluster user name.
32+
default: { get_secret: libvirt_cluster_user }
1833

1934
cluster_key:
2035
type: string
2136
description: >
2237
SSH key for cluster user.
38+
default: { get_secret: libvirt_cluster_key }
39+
40+
manager_network:
41+
type: string
42+
description: >
43+
Manager network.
44+
default: { get_secret: libvirt_common_network }
2345

2446
cluster_host:
2547
type: string
2648
description: >
2749
LibVirt computer ip address.
50+
default: { get_secret: libvirt_cluster_host }
2851

2952
external_ip:
3053
type: string
3154
description: >
3255
List external ip's separated by comma.
56+
default: { get_secret: libvirt_cluster_external_ip }
3357

3458
external_dev:
3559
type: string
3660
description: >
3761
Device with external access (same device as used for cluster_host ip)
62+
default: { get_secret: libvirt_cluster_external_dev }
3863

3964
relationships:
4065

@@ -47,9 +72,17 @@ relationships:
4772
executor: central_deployment_agent
4873
inputs: {}
4974

75+
node_types:
76+
77+
agent_domain:
78+
derived_from: cloudify.nodes.Compute
79+
properties:
80+
use_public_ip:
81+
default: false
82+
5083
node_templates:
5184

52-
libvirt_install:
85+
vm_download:
5386
type: cloudify.nodes.WebServer
5487
interfaces:
5588
cloudify.interfaces.lifecycle:
@@ -65,14 +98,21 @@ node_templates:
6598
implementation: fabric.fabric_plugin.tasks.run_script
6699
inputs:
67100
fabric_env: *fab_env
68-
script_path: cluster/download_vm.sh
69-
CATALOG_URL: https://buildlogs.centos.org/centos/7/isos/x86_64
70-
DISK: CentOS-7-x86_64-GenericCloud-ContainerHost.qcow2
101+
script_path: scripts/download_vm.sh
102+
CATALOG_URL: https://cloud.centos.org/centos/7/images/
103+
DISK: CentOS-7-x86_64-GenericCloud-1805.qcow2
71104

72105
common_network:
73106
type: cloudify.libvirt.network
74107
properties:
75-
libvirt_auth: {concat:["qemu+ssh://", { get_input: cluster_user }, "@", { get_input: cluster_host }, "/system?sshauth=privkey&keyfile=", { get_input: cluster_key }]}
108+
libvirt_auth: &libvirt_auth
109+
concat:
110+
- "qemu+ssh://"
111+
- { get_input: cluster_user }
112+
- "@"
113+
- { get_input: cluster_host }
114+
- "/system?sshauth=privkey&keyfile="
115+
- { get_input: cluster_key }
76116
interfaces:
77117
cloudify.interfaces.lifecycle:
78118
create:
@@ -82,38 +122,62 @@ node_templates:
82122
forwards:
83123
- mode: nat
84124
ips:
85-
- address: 192.168.142.1
125+
- address: 192.168.141.1
86126
netmask: 255.255.255.0
87127
dhcp:
88-
start: 192.168.142.2
89-
end: 192.168.142.254
128+
start: 192.168.141.2
129+
end: 192.168.141.254
90130
relationships:
91-
- target: libvirt_install
131+
- target: vm_download
92132
type: cloudify.relationships.depends_on
93133

134+
cloud_init:
135+
type: cloudify.nodes.CloudInit.CloudConfig
136+
properties:
137+
resource_config:
138+
groups:
139+
- { get_input: agent_user }
140+
users:
141+
- name: { get_input: agent_user }
142+
# group with same name as username required for agent running
143+
primary_group: { get_input: agent_user }
144+
groups: wheel
145+
shell: /bin/bash
146+
sudo: ['ALL=(ALL) NOPASSWD:ALL']
147+
ssh-authorized-keys:
148+
- { get_input: agent_public_key }
149+
94150
disk_clone:
95151
type: cloudify.nodes.ApplicationServer
96152
interfaces:
97153
cloudify.interfaces.lifecycle:
98154
create:
155+
implementation: scripts/disk_prepere.py
156+
executor: central_deployment_agent
157+
inputs:
158+
disk_image: { get_attribute: [vm_download, vm_image] }
159+
cloud_init: { get_attribute: [cloud_init, cloud_config ] }
160+
disk_size: { get_input: disk_size }
161+
configure:
99162
implementation: fabric.fabric_plugin.tasks.run_script
100163
inputs:
101164
fabric_env: *fab_env
102-
DISK: { get_attribute: [libvirt_install, vm_image] }
103-
script_path: cluster/copy_disk.sh
165+
script_path: scripts/copy_disk.py
104166
delete:
105167
implementation: fabric.fabric_plugin.tasks.run_script
106168
inputs:
107169
fabric_env: *fab_env
108170
script_path: scripts/remove_disk.sh
109171
relationships:
110-
- target: libvirt_install
172+
- target: vm_download
173+
type: cloudify.relationships.depends_on
174+
- target: cloud_init
111175
type: cloudify.relationships.depends_on
112176

113-
qemu_vm:
177+
base_vm:
114178
type: cloudify.libvirt.domain
115179
properties:
116-
libvirt_auth: {concat:["qemu+ssh://", { get_input: cluster_user }, "@", { get_input: cluster_host }, "/system?sshauth=privkey&keyfile=", { get_input: cluster_key }]}
180+
libvirt_auth: *libvirt_auth
117181
agent_config:
118182
install_method: none
119183
interfaces:
@@ -123,6 +187,7 @@ node_templates:
123187
params:
124188
vcpu: 2
125189
memory_size: 1048576
190+
domain_type: kvm
126191
networks:
127192
- network: { get_attribute: [common_network, resource_id] }
128193
dev: vnet0
@@ -133,7 +198,7 @@ node_templates:
133198
type: vm_connected_to_storage
134199

135200
floating_ip:
136-
type: cloudify.nodes.ApplicationServer
201+
type: cloudify.nodes.VirtualIP
137202
interfaces:
138203
cloudify.interfaces.lifecycle:
139204
create:
@@ -142,16 +207,16 @@ node_templates:
142207
fabric_env: *fab_env
143208
EXTERNAL_INTERFACE: { get_input: external_dev }
144209
EXTERNAL_IP: { get_input: external_ip }
145-
INTERNAL_IP: { get_attribute: [qemu_vm, ip] }
210+
INTERNAL_IP: { get_attribute: [base_vm, ip] }
146211
script_path: cluster/floating_ip.py
147212
delete:
148213
implementation: fabric.fabric_plugin.tasks.run_script
149214
inputs:
150215
fabric_env: *fab_env
151216
script_path: cluster/floating_ip_delete.py
152217
relationships:
153-
- target: qemu_vm
154-
type: cloudify.relationships.depends_on
218+
- target: base_vm
219+
type: cloudify.relationships.connected_to
155220

156221
example_node:
157222
type: cloudify.nodes.WebServer
@@ -161,8 +226,8 @@ node_templates:
161226
implementation: terminal.cloudify_terminal.tasks.run
162227
inputs:
163228
terminal_auth:
164-
user: centos
165-
password: passw0rd
229+
user: { get_input: agent_user }
230+
key_content: { get_input: agent_private_key }
166231
ip: { get_attribute: [floating_ip, external_ip] }
167232
calls:
168233
- action: uname -a

examples/cluster/copy_disk.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/cluster/download_vm.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/cluster/floating_ip_delete.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ def execute_command(command, extra_args=None):
5252

5353
if __name__ == '__main__':
5454

55-
internal_ip = ctx.instance.runtime_properties["internal_ip"]
56-
external_ip = ctx.instance.runtime_properties["external_ip"]
57-
external_interface = ctx.instance.runtime_properties["external_interface"]
55+
runtime_properties = ctx.instance.runtime_properties
56+
internal_ip = runtime_properties.get("internal_ip")
57+
external_ip = runtime_properties.get("external_ip")
58+
external_interface = runtime_properties.get("external_interface")
5859

5960
if external_ip and internal_ip and external_interface:
6061
execute_command(["sudo", "/sbin/ip", "address",

examples/cluster/libvirt_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ sudo service libvirtd restart
55
sudo groupadd libvirt
66
sudo usermod --append --groups kvm `whoami`
77
sudo usermod --append --groups libvirt `whoami`
8+
sudo usermod --append --groups qemu `whoami`
89

910
sudo service libvirtd restart

0 commit comments

Comments
 (0)