MCPcopy Create free account
hub / github.com/apache/cloudstack / CsPassword

Class CsPassword

systemvm/debian/opt/cloud/bin/configure.py:84–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82
83
84class CsPassword(CsDataBag):
85
86 TOKEN_FILE = "/tmp/passwdsrvrtoken"
87
88 def process(self):
89 for item in self.dbag:
90 if item == "id":
91 continue
92 self.__update(item, self.dbag[item])
93
94 def __update(self, vm_ip, password):
95 token = ""
96 try:
97 tokenFile = open(self.TOKEN_FILE)
98 token = tokenFile.read()
99 except IOError:
100 logging.debug("File %s does not exist" % self.TOKEN_FILE)
101
102 server_ip = None
103 guest_ip = None
104 for interface in self.config.address().get_interfaces():
105 if interface.ip_in_subnet(vm_ip) and interface.is_added():
106 if self.config.cl.is_redundant():
107 server_ip = interface.get_gateway()
108 guest_ip = interface.get_ip()
109 else:
110 server_ip = interface.get_ip()
111 break
112
113 if server_ip is not None:
114 if guest_ip is None:
115 proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip])
116 else:
117 proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip + "," + guest_ip])
118 if proc.find():
119 url = "http://%s:8080/" % server_ip
120 payload = {"ip": vm_ip, "password": password, "token": token}
121 data = urllib.parse.urlencode(payload).encode()
122 request = urllib.request.Request(url, data=data, headers={"DomU_Request": "save_password"})
123 try:
124 resp = urllib.request.urlopen(request, data)
125 logging.debug("Update password server result: http:%s, content:%s" % (resp.code, resp.read()))
126 except Exception as e:
127 logging.error("Failed to update password server due to: %s" % e)
128
129
130class CsAcl(CsDataBag):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected