Merge juju-bmc:juju-bmc-strict into juju-bmc:master

Proposed by Jose Guedez
Status: Merged
Approved by: Jose Guedez
Approved revision: 8386ac9ee8cb2cb711bcd7c93a2b3250de406aee
Merged at revision: 6ddecd86f6b22d2ab31cf7a30507a6789cd27471
Proposed branch: juju-bmc:juju-bmc-strict
Merge into: juju-bmc:master
Diff against target: 126 lines (+54/-14)
4 files modified
juju-bmc/__init__.py (+0/-0)
juju-bmc/juju-bmc (+21/-7)
setup.py (+17/-0)
snap/snapcraft.yaml (+16/-7)
Reviewer Review Type Date Requested Status
Joe Guo (community) Approve
Canonical IS CREs Pending
Review via email: mp+385169@code.launchpad.net

Commit message

add support for strict snap confinement

Description of the change

Add support for strict snap confinement

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joe Guo (guoqiao) :
Revision history for this message
Jose Guedez (jfguedez) wrote :

replied to comment inline

Revision history for this message
Joe Guo (guoqiao) wrote :

LGTM, +1.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 6ddecd86f6b22d2ab31cf7a30507a6789cd27471

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/juju-bmc/__init__.py b/juju-bmc/__init__.py
2new file mode 100644
3index 0000000..e69de29
4--- /dev/null
5+++ b/juju-bmc/__init__.py
6diff --git a/src/juju-bmc b/juju-bmc/juju-bmc
7similarity index 85%
8rename from src/juju-bmc
9rename to juju-bmc/juju-bmc
10index 5194ff4..70a1953 100755
11--- a/src/juju-bmc
12+++ b/juju-bmc/juju-bmc
13@@ -35,6 +35,9 @@ import logging
14 import os
15 import subprocess
16
17+from juju.model import Model
18+from juju import loop
19+
20 # `__name__` will show `__main__`
21 LOG = logging.getLogger('juju-bmc')
22
23@@ -72,6 +75,23 @@ def parse_args():
24 return parser.parse_args()
25
26
27+async def get_machine_instance_id(machine_id):
28+ """
29+ Connects to the juju controller using default credentials in $HOME
30+ to obtain the instance id of the provided machine_id
31+ """
32+ # connect to the current juju controller/model
33+ model = Model()
34+ await model.connect()
35+
36+ machine = model.machines.get(machine_id)
37+ if not machine:
38+ LOG.error('juju machine %s not found, exit', machine_id)
39+ sys.exit(-1)
40+
41+ return machine.data["instance-id"]
42+
43+
44 def main():
45 args = parse_args()
46
47@@ -86,13 +106,7 @@ def main():
48
49 # machine_id --> instance_id/system_id
50 machine_id = str(args.machine_id)
51- cmd = ['juju', 'show-machine', machine_id, '--format', 'json']
52- data = json.loads(get_cmd_output(cmd))
53- machines = data['machines']
54- if not machines:
55- LOG.error('juju machine %s not found, exit', machine_id)
56- sys.exit(-1)
57- instance_id = machines[str(machine_id)]['instance-id']
58+ instance_id = loop.run(get_machine_instance_id(machine_id))
59 LOG.info('find juju instance-id(maas system_id) for machine %s: %s', machine_id, instance_id)
60
61 # find maas api name
62diff --git a/setup.py b/setup.py
63new file mode 100644
64index 0000000..3dd7f92
65--- /dev/null
66+++ b/setup.py
67@@ -0,0 +1,17 @@
68+#!/usr/bin/env python3
69+
70+from setuptools import setup, find_packages
71+
72+setup(
73+ name='juju-bmc',
74+ version='0.11',
75+ url='https://launchpad.net/juju-bmc',
76+ author='Canonical Bootstack',
77+ author_email="bootstack@canonical.com",
78+ description="juju plugin that adds a command to access a server out band management",
79+ packages=find_packages(),
80+ install_requires=['juju >= 2.8.1'],
81+ scripts=[
82+ "juju-bmc/juju-bmc",
83+ ],
84+)
85diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
86index 866e08f..0522094 100644
87--- a/snap/snapcraft.yaml
88+++ b/snap/snapcraft.yaml
89@@ -8,21 +8,30 @@ description: |
90 and establishes a connection to the BMC console of a bare metal server.
91
92 grade: devel # must be 'stable' to release into candidate/stable channels
93-confinement: devmode # use 'strict' once you have the right plugs and slots
94+confinement: strict
95+
96+plugs:
97+ config-files:
98+ interface: personal-files
99+ read:
100+ - $HOME/.maascli.db
101+ - $HOME/.local/share/juju
102+ write:
103+ - $HOME/.maascli.db
104
105 apps:
106 juju-bmc:
107 command: bin/juju-bmc
108+ plugs:
109+ - network
110+ - config-files
111+ - ssh-keys
112
113 parts:
114 juju-bmc:
115- plugin: dump
116- source: ./src
117- organize:
118- juju-bmc: bin/
119+ plugin: python
120+ source: ./
121 stage-packages:
122 - maas-cli
123 - ipmitool
124 - sshpass
125- stage-snaps:
126- - juju/latest/stable

Subscribers

People subscribed via source and target branches

to all changes: