Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vnf-onboarding
OSM Packages
Commits
50d57ac1
Commit
50d57ac1
authored
Sep 23, 2020
by
lavado
Browse files
Merge branch 'add-proxy-native-relation-charms' into 'master'
Add charm example for a proxy-native relation See merge request
!90
parents
f4c5ff96
cbd63cab
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
715 additions
and
0 deletions
+715
-0
.gitmodules
.gitmodules
+9
-0
charm-packages/proxy_native_relation_ns/icons/osm.png
charm-packages/proxy_native_relation_ns/icons/osm.png
+0
-0
charm-packages/proxy_native_relation_ns/proxy_native_relation_nsd.yaml
...s/proxy_native_relation_ns/proxy_native_relation_nsd.yaml
+26
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/actions.yaml
...ve_relation_vnf/charms/simple_provides_proxy/actions.yaml
+54
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/config.yaml
...ive_relation_vnf/charms/simple_provides_proxy/config.yaml
+41
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/install
...e_relation_vnf/charms/simple_provides_proxy/hooks/install
+65
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/start
...ive_relation_vnf/charms/simple_provides_proxy/hooks/start
+65
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/upgrade-charm
...tion_vnf/charms/simple_provides_proxy/hooks/upgrade-charm
+65
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/lib/charms
...tive_relation_vnf/charms/simple_provides_proxy/lib/charms
+1
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/lib/ops
..._native_relation_vnf/charms/simple_provides_proxy/lib/ops
+1
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/metadata.yaml
...e_relation_vnf/charms/simple_provides_proxy/metadata.yaml
+30
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/charms.osm
..._relation_vnf/charms/simple_provides_proxy/mod/charms.osm
+1
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/operator
...ve_relation_vnf/charms/simple_provides_proxy/mod/operator
+1
-0
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/src/charm.py
...ve_relation_vnf/charms/simple_provides_proxy/src/charm.py
+73
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/actions.yaml
...y_native_relation_vnf/charms/simple_requires/actions.yaml
+25
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/config.yaml
...xy_native_relation_vnf/charms/simple_requires/config.yaml
+17
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/install
..._native_relation_vnf/charms/simple_requires/hooks/install
+80
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/start
...xy_native_relation_vnf/charms/simple_requires/hooks/start
+80
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/upgrade-charm
...e_relation_vnf/charms/simple_requires/hooks/upgrade-charm
+80
-0
charm-packages/proxy_native_relation_vnf/charms/simple_requires/lib/ops
.../proxy_native_relation_vnf/charms/simple_requires/lib/ops
+1
-0
No files found.
.gitmodules
View file @
50d57ac1
...
...
@@ -58,3 +58,12 @@
[submodule "charm-packages/native_k8s_charm_vnf/charms/nginx-k8s/mod/operator"]
path = charm-packages/native_k8s_charm_vnf/charms/nginx-k8s/mod/operator
url = https://github.com/canonical/operator
[submodule "charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/charms.osm"]
path = charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/charms.osm
url = https://github.com/charmed-osm/charms.osm.git
[submodule "charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/operator"]
path = charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/mod/operator
url = https://github.com/canonical/operator.git
[submodule "charm-packages/proxy_native_relation_vnf/charms/simple_requires/mod/operator"]
path = charm-packages/proxy_native_relation_vnf/charms/simple_requires/mod/operator
url = https://github.com/canonical/operator.git
charm-packages/proxy_native_relation_ns/icons/osm.png
0 → 100644
View file @
50d57ac1
54.6 KB
charm-packages/proxy_native_relation_ns/proxy_native_relation_nsd.yaml
0 → 100755
View file @
50d57ac1
nsd:nsd-catalog:
nsd
:
-
id
:
proxy_native_relation-ns
name
:
proxy_native_relation-ns
short-name
:
proxy_native_relation-ns
description
:
NS with 2 VNFs with cloudinit connected by datanet and mgmtnet VLs
version
:
'
1.0'
logo
:
osm.png
constituent-vnfd
:
-
vnfd-id-ref
:
proxy_native_relation-vnf
member-vnf-index
:
'
1'
vld
:
-
id
:
mgmtnet
name
:
mgmtnet
short-name
:
mgmtnet
type
:
ELAN
mgmt-network
:
'
true'
vim-network-name
:
osm-ext
vnfd-connection-point-ref
:
-
vnfd-id-ref
:
proxy_native_relation-vnf
member-vnf-index-ref
:
'
1'
vnfd-connection-point-ref
:
provides-mgmt
-
vnfd-id-ref
:
proxy_native_relation-vnf
member-vnf-index-ref
:
'
1'
vnfd-connection-point-ref
:
requires-mgmt
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/actions.yaml
0 → 100644
View file @
50d57ac1
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
touch
:
description
:
"
Touch
a
file
on
the
VNF."
params
:
filename
:
description
:
"
The
name
of
the
file
to
touch."
type
:
string
default
:
"
"
required
:
-
filename
# Standard OSM functions
start
:
description
:
"
Stop
the
service
on
the
VNF."
stop
:
description
:
"
Stop
the
service
on
the
VNF."
restart
:
description
:
"
Stop
the
service
on
the
VNF."
reboot
:
description
:
"
Reboot
the
VNF
virtual
machine."
upgrade
:
description
:
"
Upgrade
the
software
on
the
VNF."
# Required by charms.osm.sshproxy
run
:
description
:
"
Run
an
arbitrary
command"
params
:
command
:
description
:
"
The
command
to
execute."
type
:
string
default
:
"
"
required
:
-
command
generate-ssh-key
:
description
:
"
Generate
a
new
SSH
keypair
for
this
unit.
This
will
replace
any
existing
previously
generated
keypair."
verify-ssh-credentials
:
description
:
"
Verify
that
this
unit
can
authenticate
with
server
specified
by
ssh-hostname
and
ssh-username."
get-ssh-public-key
:
description
:
"
Get
the
public
SSH
key
for
this
unit."
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/config.yaml
0 → 100644
View file @
50d57ac1
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
options
:
ssh-hostname
:
type
:
string
default
:
"
"
description
:
"
The
hostname
or
IP
address
of
the
machine
to"
ssh-username
:
type
:
string
default
:
"
"
description
:
"
The
username
to
login
as."
ssh-password
:
type
:
string
default
:
"
"
description
:
"
The
password
used
to
authenticate."
ssh-public-key
:
type
:
string
default
:
"
"
description
:
"
The
public
key
of
this
unit."
ssh-key-type
:
type
:
string
default
:
"
rsa"
description
:
"
The
type
of
encryption
to
use
for
the
SSH
key."
ssh-key-bits
:
type
:
int
default
:
4096
description
:
"
The
number
of
bits
to
use
for
the
SSH
key."
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/install
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
sys
.
path
.
append
(
"lib"
)
from
charms.osm.sshproxy
import
SSHProxyCharm
from
ops.main
import
main
class
MySSHProxyCharm
(
SSHProxyCharm
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
super
().
on_config_changed
(
event
)
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
super
().
on_install
(
event
)
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
super
().
on_start
(
event
)
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
if
self
.
model
.
unit
.
is_leader
():
filename
=
event
.
params
[
"filename"
]
proxy
=
self
.
get_ssh_proxy
()
stdout
,
stderr
=
proxy
.
run
(
"touch {}"
.
format
(
filename
))
event
.
set_results
({
"output"
:
stdout
})
else
:
event
.
fail
(
"Unit is not leader"
)
return
if
__name__
==
"__main__"
:
main
(
MySSHProxyCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/start
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
sys
.
path
.
append
(
"lib"
)
from
charms.osm.sshproxy
import
SSHProxyCharm
from
ops.main
import
main
class
MySSHProxyCharm
(
SSHProxyCharm
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
super
().
on_config_changed
(
event
)
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
super
().
on_install
(
event
)
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
super
().
on_start
(
event
)
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
if
self
.
model
.
unit
.
is_leader
():
filename
=
event
.
params
[
"filename"
]
proxy
=
self
.
get_ssh_proxy
()
stdout
,
stderr
=
proxy
.
run
(
"touch {}"
.
format
(
filename
))
event
.
set_results
({
"output"
:
stdout
})
else
:
event
.
fail
(
"Unit is not leader"
)
return
if
__name__
==
"__main__"
:
main
(
MySSHProxyCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/hooks/upgrade-charm
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
sys
.
path
.
append
(
"lib"
)
from
charms.osm.sshproxy
import
SSHProxyCharm
from
ops.main
import
main
class
MySSHProxyCharm
(
SSHProxyCharm
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
super
().
on_config_changed
(
event
)
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
super
().
on_install
(
event
)
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
super
().
on_start
(
event
)
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
if
self
.
model
.
unit
.
is_leader
():
filename
=
event
.
params
[
"filename"
]
proxy
=
self
.
get_ssh_proxy
()
stdout
,
stderr
=
proxy
.
run
(
"touch {}"
.
format
(
filename
))
event
.
set_results
({
"output"
:
stdout
})
else
:
event
.
fail
(
"Unit is not leader"
)
return
if
__name__
==
"__main__"
:
main
(
MySSHProxyCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/lib/charms
0 → 120000
View file @
50d57ac1
../mod/charms.osm/charms/
\ No newline at end of file
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/lib/ops
0 → 120000
View file @
50d57ac1
../mod/operator/ops/
\ No newline at end of file
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/metadata.yaml
0 → 100644
View file @
50d57ac1
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
name
:
simple-ha-proxy
summary
:
A simple example proxy charm
description
:
|
Simple proxy charm is an example charm used in OSM Hackfests
series
:
-
xenial
-
bionic
peers
:
proxypeer
:
interface
:
proxypeer
provides
:
interface
:
interface
:
interface
\ No newline at end of file
charms.osm
@
3d517f5e
Subproject commit 3d517f5e42550d0b5c81aa4be20f7679020854d5
operator
@
89b51be8
Subproject commit 89b51be8588a19fcc9c93410707aeb5856dd8d8f
charm-packages/proxy_native_relation_vnf/charms/simple_provides_proxy/src/charm.py
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
sys
.
path
.
append
(
"lib"
)
from
charms.osm.sshproxy
import
SSHProxyCharm
from
ops.main
import
main
class
MySSHProxyCharm
(
SSHProxyCharm
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
self
.
framework
.
observe
(
self
.
on
.
interface_relation_changed
,
self
.
on_interface_relation_changed
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
super
().
on_config_changed
(
event
)
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
super
().
on_install
(
event
)
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
super
().
on_start
(
event
)
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
if
self
.
model
.
unit
.
is_leader
():
filename
=
event
.
params
[
"filename"
]
proxy
=
self
.
get_ssh_proxy
()
stdout
,
stderr
=
proxy
.
run
(
"touch {}"
.
format
(
filename
))
event
.
set_results
({
"output"
:
stdout
})
else
:
event
.
fail
(
"Unit is not leader"
)
return
def
on_interface_relation_changed
(
self
,
event
):
parameter
=
"Hello"
event
.
relation
.
data
[
self
.
model
.
unit
][
"parameter"
]
=
parameter
self
.
model
.
unit
.
status
=
ActiveStatus
(
"Parameter sent: {}"
.
format
(
parameter
))
if
__name__
==
"__main__"
:
main
(
MySSHProxyCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_requires/actions.yaml
0 → 100644
View file @
50d57ac1
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
touch
:
description
:
"
Touch
a
file
on
the
VNF."
params
:
filename
:
description
:
"
The
name
of
the
file
to
touch."
type
:
string
default
:
"
"
required
:
-
filename
charm-packages/proxy_native_relation_vnf/charms/simple_requires/config.yaml
0 → 100644
View file @
50d57ac1
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
options
:
{}
\ No newline at end of file
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/install
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
import
subprocess
import
logging
sys
.
path
.
append
(
"lib"
)
from
ops.charm
import
CharmBase
from
ops.main
import
main
from
ops.model
import
ActiveStatus
logger
=
logging
.
getLogger
(
__name__
)
class
MyNativeCharm
(
CharmBase
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
# Listen to relation changed
self
.
framework
.
observe
(
self
.
on
.
interface_relation_changed
,
self
.
on_interface_relation_changed
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
filename
=
event
.
params
[
"filename"
]
try
:
subprocess
.
run
([
"touch"
,
filename
],
check
=
True
)
event
.
set_results
({
"created"
:
True
,
"filename"
:
filename
})
except
subprocess
.
CalledProcessError
as
e
:
event
.
fail
(
"Action failed: {}"
.
format
(
e
))
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_interface_relation_changed
(
self
,
event
):
logger
.
debug
(
"RELATION DATA: {}"
.
format
(
dict
(
event
.
relation
.
data
[
event
.
unit
])))
parameter
=
event
.
relation
.
data
[
event
.
unit
].
get
(
"parameter"
)
if
parameter
:
self
.
model
.
unit
.
status
=
ActiveStatus
(
"Parameter received: {}"
.
format
(
parameter
))
if
__name__
==
"__main__"
:
main
(
MyNativeCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/start
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
import
subprocess
import
logging
sys
.
path
.
append
(
"lib"
)
from
ops.charm
import
CharmBase
from
ops.main
import
main
from
ops.model
import
ActiveStatus
logger
=
logging
.
getLogger
(
__name__
)
class
MyNativeCharm
(
CharmBase
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
# Listen to relation changed
self
.
framework
.
observe
(
self
.
on
.
interface_relation_changed
,
self
.
on_interface_relation_changed
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
filename
=
event
.
params
[
"filename"
]
try
:
subprocess
.
run
([
"touch"
,
filename
],
check
=
True
)
event
.
set_results
({
"created"
:
True
,
"filename"
:
filename
})
except
subprocess
.
CalledProcessError
as
e
:
event
.
fail
(
"Action failed: {}"
.
format
(
e
))
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_interface_relation_changed
(
self
,
event
):
logger
.
debug
(
"RELATION DATA: {}"
.
format
(
dict
(
event
.
relation
.
data
[
event
.
unit
])))
parameter
=
event
.
relation
.
data
[
event
.
unit
].
get
(
"parameter"
)
if
parameter
:
self
.
model
.
unit
.
status
=
ActiveStatus
(
"Parameter received: {}"
.
format
(
parameter
))
if
__name__
==
"__main__"
:
main
(
MyNativeCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_requires/hooks/upgrade-charm
0 → 100755
View file @
50d57ac1
#!/usr/bin/env python3
##
# Copyright 2020 Canonical Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##
import
sys
import
subprocess
import
logging
sys
.
path
.
append
(
"lib"
)
from
ops.charm
import
CharmBase
from
ops.main
import
main
from
ops.model
import
ActiveStatus
logger
=
logging
.
getLogger
(
__name__
)
class
MyNativeCharm
(
CharmBase
):
def
__init__
(
self
,
framework
,
key
):
super
().
__init__
(
framework
,
key
)
# Listen to charm events
self
.
framework
.
observe
(
self
.
on
.
config_changed
,
self
.
on_config_changed
)
self
.
framework
.
observe
(
self
.
on
.
install
,
self
.
on_install
)
self
.
framework
.
observe
(
self
.
on
.
start
,
self
.
on_start
)
# Listen to the touch action event
self
.
framework
.
observe
(
self
.
on
.
touch_action
,
self
.
on_touch_action
)
# Listen to relation changed
self
.
framework
.
observe
(
self
.
on
.
interface_relation_changed
,
self
.
on_interface_relation_changed
)
def
on_config_changed
(
self
,
event
):
"""Handle changes in configuration"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_install
(
self
,
event
):
"""Called when the charm is being installed"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_start
(
self
,
event
):
"""Called when the charm is being started"""
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_touch_action
(
self
,
event
):
"""Touch a file."""
filename
=
event
.
params
[
"filename"
]
try
:
subprocess
.
run
([
"touch"
,
filename
],
check
=
True
)
event
.
set_results
({
"created"
:
True
,
"filename"
:
filename
})
except
subprocess
.
CalledProcessError
as
e
:
event
.
fail
(
"Action failed: {}"
.
format
(
e
))
self
.
model
.
unit
.
status
=
ActiveStatus
()
def
on_interface_relation_changed
(
self
,
event
):
logger
.
debug
(
"RELATION DATA: {}"
.
format
(
dict
(
event
.
relation
.
data
[
event
.
unit
])))
parameter
=
event
.
relation
.
data
[
event
.
unit
].
get
(
"parameter"
)
if
parameter
:
self
.
model
.
unit
.
status
=
ActiveStatus
(
"Parameter received: {}"
.
format
(
parameter
))
if
__name__
==
"__main__"
:
main
(
MyNativeCharm
)
charm-packages/proxy_native_relation_vnf/charms/simple_requires/lib/ops
0 → 120000
View file @
50d57ac1
../mod/operator/ops/
\ No newline at end of file
Prev
1
2
Next
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