From d7167cfbdfc82ca0ed8e552d8047a6bcf99b9a5b Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Mon, 28 Nov 2022 22:06:49 +0000 Subject: [PATCH] Add templates for ussuri some extra repros for software deployment --- heat_templates/ussuri/compute_node.yaml | 159 ++++++++++ heat_templates/ussuri/hpc.yaml | 292 ++++++++++++++++++ heat_templates/ussuri/params.yaml | 5 + heat_templates/ussuri/sd_params.yaml | 2 + .../ussuri/software_deployment.yaml | 63 ++++ 5 files changed, 521 insertions(+) create mode 100644 heat_templates/ussuri/compute_node.yaml create mode 100644 heat_templates/ussuri/hpc.yaml create mode 100644 heat_templates/ussuri/params.yaml create mode 100644 heat_templates/ussuri/sd_params.yaml create mode 100644 heat_templates/ussuri/software_deployment.yaml diff --git a/heat_templates/ussuri/compute_node.yaml b/heat_templates/ussuri/compute_node.yaml new file mode 100644 index 0000000..69db7bf --- /dev/null +++ b/heat_templates/ussuri/compute_node.yaml @@ -0,0 +1,159 @@ +heat_template_version: 2013-05-23 + +description: > + HOT template to deploy one compute node into an xisting neutron tenant network and + assign floating IP address to the server so they are routable from the + public network. + +parameters: + host_prefix: + type: string + description: The hostname will be prefixed by this string + key_name: + type: string + description: Name of keypair to assign to servers + image: + type: string + description: Name of image to use for servers + flavor: + type: string + description: Flavor to use for servers + public_net_id: + type: string + description: > + ID of public network for which floating IP addresses will be allocated + private_net_id: + type: string + description: ID of private network into which servers get deployed + private_subnet_id: + type: string + description: ID of private sub network into which servers get deployed + master_node_ip: + type: string + description: IP address of the Master node. + +resources: + + node_wait_handle: + type: "AWS::CloudFormation::WaitConditionHandle" + + node_wait_condition: + type: "AWS::CloudFormation::WaitCondition" + depends_on: + - compute_node + properties: + Handle: + get_resource: node_wait_handle + Timeout: "1200" + + secgroup_all_open: + type: "OS::Neutron::SecurityGroup" + properties: + rules: + - protocol: icmp + - protocol: tcp + - protocol: udp + + compute_node: + type: OS::Nova::Server + properties: + name: + get_param: host_prefix + image: + get_param: image + flavor: + get_param: flavor + key_name: + get_param: key_name + user_data_format: RAW + user_data: + str_replace: + template: | + #!/bin/sh + + yum -y remove NetworkManager + chkconfig network on + + cat > /etc/yum.repos.d/torque.repo << EOF + [torque] + name=torque + baseurl=http://192.168.95.200/install/post/otherpkgs/el7/torque + enabled=1 + gpgcheck=0 + EOF + + yum -y install torque-client + + chkconfig trqauthd on + chkconfig pbs_mom on + + echo $MASTER_NODE_IP > /var/spool/torque/server_name + + cat > /var/spool/torque/mom_priv/config << EOF + \$logevent 0x1ff + + \$pbsserver $MASTER_NODE_IP + EOF + + myip=$(ip addr show eth0 | awk '$1 == "inet" {print $2}' | cut -f1 -d/) + myip_last_octet=${myip##*.} + + hostname $HOST_PREFIX${myip_last_octet} + + echo $myip $HOST_PREFIX${myip_last_octet} >> /etc/hosts + + service trquathd restart + service pbs_mom restart + + groupadd -g 4001 testuser + useradd -g 4001 -u 4001 -m testuser + + cat > /tmp/wait-data << EOF + { + "Status" : "SUCCESS", + "Reason" : "Setup Complete", + "UniqueId" : "None", + "Data" : "OK" + } + EOF + curl -T /tmp/wait-data '$WAIT_HANDLE' + params: + "$MASTER_NODE_IP": + get_param: master_node_ip + "$WAIT_HANDLE": + get_resource: node_wait_handle + "$HOST_PREFIX": + get_param: host_prefix + networks: + - port: + get_resource: compute_node_eth0 + + compute_node_eth0: + type: OS::Neutron::Port + properties: + network_id: + get_param: private_net_id + fixed_ips: + - subnet_id: + get_param: private_subnet_id + security_groups: + - get_resource: secgroup_all_open + + compute_floating_ip: + type: OS::Neutron::FloatingIP + properties: + floating_network_id: + get_param: public_net_id + port_id: + get_resource: compute_node_eth0 + +outputs: + compute_node_name: + description: The name of the compute node + value: { get_attr: [ compute_node, instance_name ] } + compute_node_ip: + description: IP address of compute node in private network + value: { get_attr: [ compute_node_eth0, fixed_ips, 0, ip_address ] } + compute_node_external_ip: + description: Floating IP address of compute node in public network + value: { get_attr: [ compute_floating_ip, floating_ip_address ] } diff --git a/heat_templates/ussuri/hpc.yaml b/heat_templates/ussuri/hpc.yaml new file mode 100644 index 0000000..ad95916 --- /dev/null +++ b/heat_templates/ussuri/hpc.yaml @@ -0,0 +1,292 @@ +heat_template_version: 2013-05-23 + +description: > + This template will boot a HPC cluster with one or more compute + nodes (as specified by the number_of_compute_nodes parameter, which + defaults to "10"). + +parameters: + + # + # REQUIRED PARAMETERS + # + key_name: + type: string + description: name of ssh key to be provisioned on our server + + public_net_id: + type: string + description: uuid of a network to use for floating ip addresses + + # + # OPTIONAL PARAMETERS + # + image: + type: string + default: centos7 + description: glance image used to boot the server + + host_prefix: + type: string + default: compute + description: The prefix of the hostname of the compute node + + flavor: + type: string + default: m1.small + description: flavor to use when booting the server + + dns_nameserver: + type: string + description: address of a dns nameserver reachable in your environment + default: 8.8.8.8 + + number_of_compute_nodes: + type: string + description: how many compute nodes to spawn + default: 10 + +resources: + + master_wait_handle: + type: "AWS::CloudFormation::WaitConditionHandle" + + master_wait_condition: + type: "AWS::CloudFormation::WaitCondition" + depends_on: + - master_node + properties: + Handle: + get_resource: master_wait_handle + Timeout: "1200" + + ###################################################################### + # + # network resources. allocate a network and router for our server. + # it would also be possible to take advantage of existing network + # resources (and have the deployer provide network and subnet ids, + # etc, as parameters), but I wanted to minmize the amount of + # configuration necessary to make this go. + fixed_net: + type: "OS::Neutron::Net" + + # This is the subnet on which we will deploy our server. + fixed_subnet: + type: "OS::Neutron::Subnet" + properties: + cidr: 10.0.9.0/24 + network_id: { get_resource: fixed_net } + dns_nameservers: [{ get_param: dns_nameserver }] + + # create a router attached to the external network provided as a + # parameter to this stack. + extrouter: + type: "OS::Neutron::Router" + properties: + external_gateway_info: + network: + get_param: public_net_id + + # attached fixed_subnet to our extrouter router. + extrouter_inside: + type: "OS::Neutron::RouterInterface" + properties: + router_id: + get_resource: extrouter + subnet_id: { get_resource: fixed_subnet } + + ###################################################################### + # + # security groups. we need to permit network traffic of various + # sorts. + # + + secgroup_base: + type: "OS::Neutron::SecurityGroup" + properties: + rules: + - protocol: icmp + - protocol: tcp + port_range_min: 22 + port_range_max: 22 + + secgroup_compute: + type: "OS::Neutron::SecurityGroup" + properties: + rules: + - protocol: tcp + port_range_min: 22 + port_range_max: 22 + - protocol: tcp + port_range_min: 4001 + port_range_max: 4001 + - protocol: tcp + port_range_min: 15000 + port_range_max: 15004 + + ###################################################################### + # + # databases server. this sets up a MySQL server + # + master_node: + type: "OS::Nova::Server" + depends_on: + - extrouter_inside + properties: + name: master + image: + get_param: image + flavor: + get_param: flavor + key_name: + get_param: key_name + networks: + - port: + get_resource: master_node_eth0 + user_data_format: RAW + user_data: + str_replace: + template: | + #!/bin/bash + + yum -y upgrade + + cat > /etc/yum.repos.d/torque.repo << EOF + [torque] + name=torque + baseurl=http://192.168.95.200/install/post/otherpkgs/el7/torque + enabled=1 + gpgcheck=0 + EOF + + yum -y install torque-server torque-scheduler + + chkconfig trqauthd on + chkconfig pbs_server on + chkconfig pbs_sched on + + myip=$(ip addr show eth0 | awk '$1 == "inet" {print $2}' | cut -f1 -d/) + myip_last_octet=${myip##*.} + echo $myip `hostname` >> /etc/hosts + + mkdir -p /var/spool/torque/server_priv + echo $myip > /var/spool/torque/server_name + rm -rf /var/spool/torque/server_priv/nodes + mkdir -p /var/spool/torque/checkpoint + + pbs_server -t create -f + service trqauthd restart + service pbs_server restart + service pbs_sched restart + + IFS="," read -a array1 <<< "$COMP_NODE_ADDRESSES" + IFS="," read -a array2 <<< "$COMP_NODE_NAMES" + + length=${#array1[@]} + + for ((i=0;i<$length;i++)); do + comp_ip=${array1[$i]} + comp_ip_last_octet=${comp_ip##*.} + comp_name=$HOST_PREFIX${comp_ip_last_octet} + echo -e "$comp_ip $comp_name" >> /etc/hosts + qmgr -c "c n $comp_name" + pbsnodes -c $comp_name + done + + qmgr -c "c q testq" + qmgr -c "s q testq queue_type=e" + qmgr -c "s q testq enabled=t" + qmgr -c "s q testq started=t" + qmgr -c "s s scheduling=true" + qmgr -c "s s default_queue=testq" + + groupadd -g 4001 testuser + useradd -g 4001 -u 4001 -m testuser + + cat > ~testuser/torque.script << EOF + #!/bin/bash + #PBS -S /bin/bash + #PBS -N test.job + #PBS -l nodes=1:ppn=1 + + echo Starting Job, sleeping ... + sleep 1200 + echo Done + EOF + + chown testuser:testuser ~testuser/torque.script + + cat > /tmp/wait-data << EOF + { + "Status" : "SUCCESS", + "Reason" : "Setup Complete", + "UniqueId" : "None", + "Data" : "OK" + } + EOF + curl -T /tmp/wait-data '$WAIT_HANDLE' + params: + # NB: For this to work you need a version of Heat that + # includes https://review.openstack.org/#/c/121139/ + "$COMP_NODE_ADDRESSES": + "Fn::Join": [ ",", [{ get_attr: [compute_nodes, compute_node_ip] }] ] + "$COMP_NODE_NAMES": + "Fn::Join": [ "," , [{ get_attr: [compute_nodes, compute_node_name] }] ] + "$WAIT_HANDLE": + get_resource: master_wait_handle + "$HOST_PREFIX": + get_param: host_prefix + + master_node_eth0: + type: "OS::Neutron::Port" + properties: + network_id: + get_resource: fixed_net + security_groups: + - get_resource: secgroup_base + - get_resource: secgroup_compute + fixed_ips: + - subnet_id: + get_resource: fixed_subnet + + master_node_floating: + type: "OS::Neutron::FloatingIP" + depends_on: + - extrouter_inside + properties: + floating_network_id: + get_param: public_net_id + port_id: + get_resource: master_node_eth0 + + compute_nodes: + type: "OS::Heat::ResourceGroup" + depends_on: + - extrouter_inside + properties: + count: {get_param: number_of_compute_nodes} + resource_def: + type: compute_node.yaml + properties: + host_prefix: {get_param: host_prefix} + key_name: {get_param: key_name} + image: {get_param: image} + flavor: {get_param: flavor} + private_net_id: {get_resource: fixed_net} + private_subnet_id: {get_resource: fixed_subnet} + public_net_id: {get_param: public_net_id} + master_node_ip: {get_attr: [master_node_eth0, fixed_ips, 0, ip_address]} + +outputs: + + master_node_external: + value: {get_attr: [master_node_floating, floating_ip_address]} + + compute_nodes_ips: + value: {get_attr: [compute_nodes, compute_node_ip]} + + compute_node_names: + value: {get_attr: [compute_nodes, compute_node_name]} + + compute_node_external: + value: {get_attr: [compute_nodes, compute_node_external_ip]} diff --git a/heat_templates/ussuri/params.yaml b/heat_templates/ussuri/params.yaml new file mode 100644 index 0000000..c41fef5 --- /dev/null +++ b/heat_templates/ussuri/params.yaml @@ -0,0 +1,5 @@ +parameters: + key_name: demo_key + flavor: hpc_node + number_of_compute_nodes: 10 + public_net_id: 90407899-5321-43d1-8e37-3e7207100c87 diff --git a/heat_templates/ussuri/sd_params.yaml b/heat_templates/ussuri/sd_params.yaml new file mode 100644 index 0000000..6c63789 --- /dev/null +++ b/heat_templates/ussuri/sd_params.yaml @@ -0,0 +1,2 @@ +parameters: + network: 0da3753f-b863-4bef-973e-5c827b0be26a diff --git a/heat_templates/ussuri/software_deployment.yaml b/heat_templates/ussuri/software_deployment.yaml new file mode 100644 index 0000000..35dfd7d --- /dev/null +++ b/heat_templates/ussuri/software_deployment.yaml @@ -0,0 +1,63 @@ +heat_template_version: 2018-08-31 + +parameters: + + image: + type: string + default: bionic + + flavor: + type: string + default: m1.small + + network: + type: string + default: d486570f-55aa-4516-b5c2-ae766e07d626 + +resources: + + config: + type: OS::Heat::SoftwareConfig + properties: + group: script + inputs: + - name: foo + - name: bar + outputs: + - name: result + config: | + #!/bin/sh -x + echo "Writing to /tmp/$bar" + echo $foo > /tmp/$bar + echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server $deploy_server_id during $deploy_action" > $heat_outputs_path.result + echo "Written to /tmp/$bar" + echo "Output to stderr" 1>&2 + + deployment: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: config + server: + get_resource: server + input_values: + foo: fooooo + bar: baaaaa + + server: + type: OS::Nova::Server + properties: + image: {get_param: image} + flavor: {get_param: flavor} + #key_name: {get_param: key_name} + networks: + - network: {get_param: network} + user_data_format: SOFTWARE_CONFIG + +outputs: + result: + value: + get_attr: [deployment, result] + stdout: + value: + get_attr: [deployment, deploy_stdout]