Skip to content

Commit 5210c66

Browse files
committed
Merge branch 'master' into vm-ingestion
2 parents 04b9cd7 + c01ce7b commit 5210c66

142 files changed

Lines changed: 278 additions & 146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/bindir/cloud-guest-tool.in

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env python
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
#
20+
# Talk to a KVM guest through Libvirt and the Qemu Guest Agent
21+
# to retrieve information from the guest
22+
#
23+
# System VMs have the Qemu Guest Agent installed by default
24+
# and should properly respond to such commands
25+
26+
#
27+
# Talk to KVM Instances through the Qemu Guest Agent
28+
#
29+
30+
import argparse
31+
import json
32+
import sys
33+
import libvirt
34+
import libvirt_qemu
35+
36+
COMMANDS = ["info", "ping", "fstrim"]
37+
38+
39+
class Libvirt:
40+
def __init__(self, uri=None, timeout=5):
41+
self.timeout = timeout
42+
self.conn = libvirt.open(uri)
43+
if not self.conn:
44+
raise Exception('Failed to open connection to the hypervisor')
45+
46+
def get_domain(self, name):
47+
return self.conn.lookupByName(name)
48+
49+
def agent_command(self, dom, cmd, flags=0, raw=False):
50+
ret = libvirt_qemu.qemuAgentCommand(dom, json.dumps({'execute': cmd}),
51+
self.timeout, flags)
52+
if raw:
53+
return ret
54+
55+
return json.loads(ret)['return']
56+
57+
class GuestCommand:
58+
def __init__(self, domain, timeout):
59+
self.domain = domain
60+
self.timeout = timeout
61+
self.virt = Libvirt(timeout=self.timeout)
62+
self.dom = self.virt.get_domain(self.domain)
63+
64+
def ping(self):
65+
result = self.virt.agent_command(self.dom, 'guest-ping')
66+
67+
res = False
68+
code = 1
69+
if len(result) == 0:
70+
res = True
71+
code = 0
72+
73+
return {'result': res}, code
74+
75+
def info(self):
76+
info = dict()
77+
info['filesystem'] = 'guest-get-fsinfo'
78+
info['network'] = 'guest-network-get-interfaces'
79+
80+
result = dict()
81+
for key, cmd in info.items():
82+
result[key] = self.virt.agent_command(self.dom, cmd)
83+
84+
return result, 0
85+
86+
def fstrim(self):
87+
result = self.virt.agent_command(self.dom, 'guest-fstrim')
88+
89+
res = False
90+
code = 1
91+
if len(result) > 0:
92+
res = True
93+
code = 0
94+
95+
return {'result': result}, code
96+
97+
98+
def main(args):
99+
command = args.command
100+
101+
try:
102+
guestcmd = GuestCommand(args.instance, args.timeout)
103+
result = {'error': 'Command not implemented'}
104+
code = 255
105+
106+
if command == 'info':
107+
result, code = guestcmd.info()
108+
elif command == 'ping':
109+
result, code = guestcmd.ping()
110+
elif command == 'fstrim':
111+
result, code = guestcmd.fstrim()
112+
113+
print(json.dumps(result))
114+
sys.exit(code)
115+
except libvirt.libvirtError as exc:
116+
print(json.dumps({'error': str(exc)}))
117+
sys.exit(255)
118+
119+
if __name__ == '__main__':
120+
parser = argparse.ArgumentParser(description='CloudStack Guest Tool')
121+
parser.add_argument('instance', type=str,
122+
help='Instance Name')
123+
parser.add_argument('--command', type=str, required=False,
124+
help='Command to execute', default='info',
125+
choices=COMMANDS)
126+
parser.add_argument('--timeout', type=int, required=False,
127+
help='timeout in seconds', default=5)
128+
args = parser.parse_args()
129+
main(args)

agent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.apache.cloudstack</groupId>
2626
<artifactId>cloudstack</artifactId>
27-
<version>4.13.0.0-SNAPSHOT</version>
27+
<version>4.14.0.0-SNAPSHOT</version>
2828
</parent>
2929
<dependencies>
3030
<dependency>

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.apache.cloudstack</groupId>
2626
<artifactId>cloudstack</artifactId>
27-
<version>4.13.0.0-SNAPSHOT</version>
27+
<version>4.14.0.0-SNAPSHOT</version>
2828
</parent>
2929
<dependencies>
3030
<dependency>

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>org.apache.cloudstack</groupId>
2727
<artifactId>cloudstack</artifactId>
28-
<version>4.13.0.0-SNAPSHOT</version>
28+
<version>4.14.0.0-SNAPSHOT</version>
2929
</parent>
3030
<repositories>
3131
<repository>

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.apache.cloudstack</groupId>
2626
<artifactId>cloudstack</artifactId>
27-
<version>4.13.0.0-SNAPSHOT</version>
27+
<version>4.14.0.0-SNAPSHOT</version>
2828
</parent>
2929
<dependencies>
3030
<dependency>

debian/changelog

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
cloudstack (4.13.0.0-SNAPSHOT) unstable; urgency=low
1+
cloudstack (4.14.0.0-SNAPSHOT) unstable; urgency=low
22

3-
* Update the version to 4.13.0.0-SNAPSHOT
3+
* Update the version to 4.14.0.0-SNAPSHOT
44

55
-- the Apache CloudStack project <dev@cloudstack.apache.org> Thu, 14 Mar 2019 10:11:46 -0300
66

7-
cloudstack (4.13.0.0-SNAPSHOT-SNAPSHOT) unstable; urgency=low
7+
cloudstack (4.14.0.0-SNAPSHOT-SNAPSHOT) unstable; urgency=low
88

9-
* Update the version to 4.13.0.0-SNAPSHOT-SNAPSHOT
9+
* Update the version to 4.14.0.0-SNAPSHOT-SNAPSHOT
1010

1111
-- the Apache CloudStack project <dev@cloudstack.apache.org> Mon, 15 Jan 2018 17:42:30 +0530
1212

debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ override_dh_auto_install:
5252
install -D agent/target/transformed/cloud-ssh $(DESTDIR)/usr/bin/cloudstack-ssh
5353
install -D agent/target/transformed/cloudstack-agent-profile.sh $(DESTDIR)/$(SYSCONFDIR)/profile.d/cloudstack-agent-profile.sh
5454
install -D agent/target/transformed/cloudstack-agent-upgrade $(DESTDIR)/usr/bin/cloudstack-agent-upgrade
55+
install -D agent/target/transformed/cloud-guest-tool $(DESTDIR)/usr/bin/cloudstack-guest-tool
5556
install -D agent/target/transformed/libvirtqemuhook $(DESTDIR)/usr/share/$(PACKAGE)-agent/lib/
5657
install -D agent/target/transformed/* $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/agent
5758

developer/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>org.apache.cloudstack</groupId>
2727
<artifactId>cloudstack</artifactId>
28-
<version>4.13.0.0-SNAPSHOT</version>
28+
<version>4.14.0.0-SNAPSHOT</version>
2929
</parent>
3030
<dependencies>
3131
<dependency>

engine/api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.apache.cloudstack</groupId>
2626
<artifactId>cloud-engine</artifactId>
27-
<version>4.13.0.0-SNAPSHOT</version>
27+
<version>4.14.0.0-SNAPSHOT</version>
2828
<relativePath>../pom.xml</relativePath>
2929
</parent>
3030
<dependencies>

engine/components-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.apache.cloudstack</groupId>
2626
<artifactId>cloud-engine</artifactId>
27-
<version>4.13.0.0-SNAPSHOT</version>
27+
<version>4.14.0.0-SNAPSHOT</version>
2828
<relativePath>../pom.xml</relativePath>
2929
</parent>
3030
<dependencies>

0 commit comments

Comments
 (0)