Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
632cb1d3
Commit
632cb1d3
authored
Feb 01, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate ansible k8s
parent
9bd8d5fa
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
3 deletions
+31
-3
install_k8s.yml
ansible_playbooks/install_k8s.yml
+2
-0
ToscaHelper.java
.../main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
+4
-1
ansible_service.py
deployer/service/ansible_service.py
+7
-2
k8s_service.py
deployer/service/k8s_service.py
+7
-0
tosca.py
deployer/service/tosca.py
+7
-0
DRIPService.java
...er/src/main/java/nl/uva/sne/drip/service/DRIPService.java
+3
-0
Consumer.java
...r/src/main/java/nl/uva/sne/drip/provisioner/Consumer.java
+1
-0
No files found.
ansible_playbooks/install_k8s.yml
View file @
632cb1d3
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
-
gnupg2
-
gnupg2
-
software-properties-common
-
software-properties-common
-
python3-pip
-
python3-pip
-
python-pip
-
virtualenv
-
name
:
Add Docker GPG apt Key
-
name
:
Add Docker GPG apt Key
apt_key
:
apt_key
:
...
...
commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
View file @
632cb1d3
...
@@ -27,6 +27,8 @@ import java.util.ArrayList;
...
@@ -27,6 +27,8 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.Credential
;
...
@@ -82,6 +84,7 @@ public class ToscaHelper {
...
@@ -82,6 +84,7 @@ public class ToscaHelper {
FileUtils
.
writeByteArrayToFile
(
toscaTemplateFile
,
ymlStr
.
getBytes
());
FileUtils
.
writeByteArrayToFile
(
toscaTemplateFile
,
ymlStr
.
getBytes
());
String
resp
=
api
.
uploadToscaTemplate
(
toscaTemplateFile
);
String
resp
=
api
.
uploadToscaTemplate
(
toscaTemplateFile
);
id
=
Integer
.
valueOf
(
resp
);
id
=
Integer
.
valueOf
(
resp
);
Logger
.
getLogger
(
ToscaHelper
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Uploaded ToscaTemplate to sure-tosca service got back id: "
+
id
);
}
}
public
List
<
Map
<
String
,
Object
>>
getProvisionInterfaceDefinitions
(
List
<
String
>
toscaInterfaceTypes
)
throws
ApiException
{
public
List
<
Map
<
String
,
Object
>>
getProvisionInterfaceDefinitions
(
List
<
String
>
toscaInterfaceTypes
)
throws
ApiException
{
...
@@ -214,7 +217,7 @@ public class ToscaHelper {
...
@@ -214,7 +217,7 @@ public class ToscaHelper {
nodes
.
put
(
node
.
getName
(),
node
.
getNodeTemplate
());
nodes
.
put
(
node
.
getName
(),
node
.
getNodeTemplate
());
return
toscaTemplate
;
return
toscaTemplate
;
}
}
public
Map
<
String
,
Object
>
getProvisionerInterfaceFromVMTopology
(
NodeTemplateMap
vmTopologyMap
)
{
public
Map
<
String
,
Object
>
getProvisionerInterfaceFromVMTopology
(
NodeTemplateMap
vmTopologyMap
)
{
return
(
Map
<
String
,
Object
>)
vmTopologyMap
.
getNodeTemplate
().
getInterfaces
().
get
(
"CloudsStorm"
);
return
(
Map
<
String
,
Object
>)
vmTopologyMap
.
getNodeTemplate
().
getInterfaces
().
get
(
"CloudsStorm"
);
}
}
...
...
deployer/service/ansible_service.py
View file @
632cb1d3
...
@@ -66,6 +66,7 @@ def write_inventory_file(tmp_path, vms):
...
@@ -66,6 +66,7 @@ def write_inventory_file(tmp_path, vms):
print
(
'ansible_ssh_private_key_file='
+
ansible_ssh_private_key_file_path
,
file
=
k8s_hosts_file
)
print
(
'ansible_ssh_private_key_file='
+
ansible_ssh_private_key_file_path
,
file
=
k8s_hosts_file
)
print
(
'ansible_ssh_common_args=
\'
-o StrictHostKeyChecking=no
\'
'
,
file
=
k8s_hosts_file
)
print
(
'ansible_ssh_common_args=
\'
-o StrictHostKeyChecking=no
\'
'
,
file
=
k8s_hosts_file
)
print
(
'ansible_ssh_user='
+
ansible_ssh_user
,
file
=
k8s_hosts_file
)
print
(
'ansible_ssh_user='
+
ansible_ssh_user
,
file
=
k8s_hosts_file
)
logger
.
info
(
"Returning inventory file at: "
+
str
(
k8s_hosts_path
))
return
k8s_hosts_path
return
k8s_hosts_path
...
@@ -87,15 +88,19 @@ def write_playbooks_from_tosca_interface(interfaces, tmp_path):
...
@@ -87,15 +88,19 @@ def write_playbooks_from_tosca_interface(interfaces, tmp_path):
playbook_paths
=
[]
playbook_paths
=
[]
for
interface_name
in
interfaces
:
for
interface_name
in
interfaces
:
playbook_paths
=
playbook_paths
+
write_playbooks
(
tmp_path
,
interfaces
[
interface_name
])
playbook_paths
=
playbook_paths
+
write_playbooks
(
tmp_path
,
interfaces
[
interface_name
])
logger
.
info
(
"Returning playbook paths file at: "
+
str
(
playbook_paths
))
return
playbook_paths
return
playbook_paths
def
run
(
inventory_path
,
playbook_path
):
def
run
(
inventory_path
,
playbook_path
):
logger
.
info
(
"Executing playbook: "
+
str
(
playbook_path
))
p
=
Popen
([
"ansible-playbook"
,
"-i"
,
inventory_path
,
playbook_path
],
stdin
=
PIPE
,
stdout
=
PIPE
,
p
=
Popen
([
"ansible-playbook"
,
"-i"
,
inventory_path
,
playbook_path
],
stdin
=
PIPE
,
stdout
=
PIPE
,
stderr
=
PIPE
)
stderr
=
PIPE
)
output
,
err
=
p
.
communicate
()
output
,
err
=
p
.
communicate
()
print
(
output
.
decode
(
'utf-8'
))
# print(output.decode('utf-8'))
print
(
err
.
decode
(
'utf-8'
))
# print(err.decode('utf-8'))
logger
.
info
(
"Playbook output: "
+
str
(
output
.
decode
(
'utf-8'
)))
logger
.
info
(
"Playbook err: "
+
str
(
err
.
decode
(
'utf-8'
)))
rc
=
p
.
returncode
rc
=
p
.
returncode
return
output
,
err
return
output
,
err
...
...
deployer/service/k8s_service.py
View file @
632cb1d3
from
_ast
import
mod
import
yaml
import
yaml
yaml
.
Dumper
.
ignore_aliases
=
lambda
*
args
:
True
yaml
.
Dumper
.
ignore_aliases
=
lambda
*
args
:
True
...
@@ -68,6 +70,11 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
...
@@ -68,6 +70,11 @@ def write_ansible_k8s_files(tosca_template_json, tmp_path):
deployments
=
k8s_definitions
[
'deployments'
]
deployments
=
k8s_definitions
[
'deployments'
]
i
=
0
i
=
0
tasks
=
[]
tasks
=
[]
pip_task
=
{
'name'
:
'install kubernetes'
}
modules
=
[
'setuptools'
,
'kubernetes'
,
'pkg_resources'
]
pip
=
{
'name'
:
modules
}
pip_task
[
'pip'
]
=
pip
tasks
.
append
(
pip_task
)
for
services_def
in
services
:
for
services_def
in
services
:
task
=
{
'name'
:
'Create a Service object'
+
str
(
i
)}
task
=
{
'name'
:
'Create a Service object'
+
str
(
i
)}
k8s
=
{
'state'
:
'present'
,
'definition'
:
services_def
}
k8s
=
{
'state'
:
'present'
,
'definition'
:
services_def
}
...
...
deployer/service/tosca.py
View file @
632cb1d3
import
logging
logger
=
logging
.
getLogger
(
__name__
)
def
get_interfaces
(
tosca_template_json
):
def
get_interfaces
(
tosca_template_json
):
node_templates
=
tosca_template_json
[
'topology_template'
][
'node_templates'
]
node_templates
=
tosca_template_json
[
'topology_template'
][
'node_templates'
]
for
node_name
in
node_templates
:
for
node_name
in
node_templates
:
if
node_templates
[
node_name
][
'type'
]
==
'tosca.nodes.ARTICONF.Orchestrator.Kubernetes'
:
if
node_templates
[
node_name
][
'type'
]
==
'tosca.nodes.ARTICONF.Orchestrator.Kubernetes'
:
logger
.
info
(
"Returning interfaces from tosca_template: "
+
str
(
node_templates
[
node_name
][
'interfaces'
]))
return
node_templates
[
node_name
][
'interfaces'
]
return
node_templates
[
node_name
][
'interfaces'
]
...
@@ -11,4 +17,5 @@ def get_vms(tosca_template_json):
...
@@ -11,4 +17,5 @@ def get_vms(tosca_template_json):
for
node_name
in
node_templates
:
for
node_name
in
node_templates
:
if
node_templates
[
node_name
][
'type'
]
==
'tosca.nodes.ARTICONF.VM.Compute'
:
if
node_templates
[
node_name
][
'type'
]
==
'tosca.nodes.ARTICONF.VM.Compute'
:
vms
[
node_name
]
=
node_templates
[
node_name
]
vms
[
node_name
]
=
node_templates
[
node_name
]
logger
.
info
(
"Returning VMs from tosca_template: "
+
str
(
vms
))
return
vms
return
vms
manager/src/main/java/nl/uva/sne/drip/service/DRIPService.java
View file @
632cb1d3
...
@@ -111,6 +111,7 @@ public class DRIPService {
...
@@ -111,6 +111,7 @@ public class DRIPService {
}
}
}
}
Logger
.
getLogger
(
ToscaHelper
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Added credetials to ToscaTemplate"
);
return
toscaTemplate
;
return
toscaTemplate
;
}
}
...
@@ -160,8 +161,10 @@ public class DRIPService {
...
@@ -160,8 +161,10 @@ public class DRIPService {
private
ToscaTemplate
initExecution
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
,
IOException
,
ApiException
{
private
ToscaTemplate
initExecution
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
,
IOException
,
ApiException
{
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
Logger
.
getLogger
(
DRIPService
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Found ToscaTemplate with id: "
+
id
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
helper
.
uploadToscaTemplate
(
toscaTemplate
);
helper
.
uploadToscaTemplate
(
toscaTemplate
);
return
toscaTemplate
;
return
toscaTemplate
;
}
}
...
...
provisioner/src/main/java/nl/uva/sne/drip/provisioner/Consumer.java
View file @
632cb1d3
...
@@ -69,6 +69,7 @@ public class Consumer extends DefaultConsumer {
...
@@ -69,6 +69,7 @@ public class Consumer extends DefaultConsumer {
.
build
();
.
build
();
Message
message
=
objectMapper
.
readValue
(
new
String
(
body
,
"UTF-8"
),
Message
.
class
);
Message
message
=
objectMapper
.
readValue
(
new
String
(
body
,
"UTF-8"
),
Message
.
class
);
logger
.
log
(
Level
.
INFO
,
"Got Request: '{'0'}'{0}"
,
message
.
getToscaTemplate
());
String
tempInputDirPath
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
"Input-"
+
Long
.
toString
(
System
.
nanoTime
())
+
File
.
separator
;
String
tempInputDirPath
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
"Input-"
+
Long
.
toString
(
System
.
nanoTime
())
+
File
.
separator
;
File
tempInputDir
=
new
File
(
tempInputDirPath
);
File
tempInputDir
=
new
File
(
tempInputDirPath
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment