Feature/api version support (#109)
[osm/N2VC.git] / juju / machine.py
1 import logging
2
3 from . import model
4 from .client import client
5
6 log = logging.getLogger(__name__)
7
8
9 class Machine(model.ModelEntity):
10 async def destroy(self, force=False):
11 """Remove this machine from the model.
12
13 Blocks until the machine is actually removed.
14
15 """
16 facade = client.ClientFacade.from_connection(self.connection)
17
18 log.debug(
19 'Destroying machine %s', self.id)
20
21 await facade.DestroyMachines(force, [self.id])
22 return await self.model._wait(
23 'machine', self.id, 'remove')
24 remove = destroy
25
26 def run(self, command, timeout=None):
27 """Run command on this machine.
28
29 :param str command: The command to run
30 :param int timeout: Time to wait before command is considered failed
31
32 """
33 raise NotImplementedError()
34
35 async def set_annotations(self, annotations):
36 """Set annotations on this machine.
37
38 :param annotations map[string]string: the annotations as key/value
39 pairs.
40
41 """
42 log.debug('Updating annotations on machine %s', self.id)
43
44 self.ann_facade = client.AnnotationsFacade.from_connection(
45 self.connection)
46
47 ann = client.EntityAnnotations(
48 entity=self.id,
49 annotations=annotations,
50 )
51 return await self.ann_facade.Set([ann])
52
53 def scp(
54 self, source_path, user=None, destination_path=None, proxy=False,
55 scp_opts=None):
56 """Transfer files to this machine.
57
58 :param str source_path: Path of file(s) to transfer
59 :param str user: Remote username
60 :param str destination_path: Destination of transferred files on
61 remote machine
62 :param bool proxy: Proxy through the Juju API server
63 :param str scp_opts: Additional options to the `scp` command
64
65 """
66 raise NotImplementedError()
67
68 def ssh(
69 self, command, user=None, proxy=False, ssh_opts=None):
70 """Execute a command over SSH on this machine.
71
72 :param str command: Command to execute
73 :param str user: Remote username
74 :param bool proxy: Proxy through the Juju API server
75 :param str ssh_opts: Additional options to the `ssh` command
76
77 """
78 raise NotImplementedError()
79
80 def status_history(self, num=20, utc=False):
81 """Get status history for this machine.
82
83 :param int num: Size of history backlog
84 :param bool utc: Display time as UTC in RFC3339 format
85
86 """
87 raise NotImplementedError()