How to get ip addresses of all units in a service in Juju charm? - juju

I am new to Juju and trying to write a charm. I need ip address of all units deployed in a service. I am using
e.g.I have 3 units of wordpress with--
juju deploy -n 3 cs:wordpress
I deployed my charm from local repo -- juju deploy local:trusty/X
I add relation between the two-- juju add-relation X wordpress
Now, I need list of all 3 ip addresses of wordpress service in one of the hook in my charm(X)
I set relation-keys in wordpress and tried using relation-ids -> relation-list -> relation-get hook tools in my charm.
But it gives me just one ip and not all three.
relation-ids --gives one id.
relation-list id --gives just one unit.
relation-get --gives corresponding ip.
what should I do to get expected result?

Try something like this:
from charmhelpers.contrib.openstack.utils import get_host_ip
from charmhelpers.core.hookenv import (
relation_ids,
related_units,
relation_get,
)
def _get_ips(rel_name):
return [get_host_ip(rdata['private-address'])
for rid in relation_ids(rel_name)
for rdata in
(relation_get(rid=rid, unit=unit) for unit in related_units(rid))
if rdata]
ips = _get_ips("wordpress")
The relation name might be different in your case. Do confirm that.

you can get a unit's address using
get_host_ip(unit_get('private-address')
where get_host_ip can be imported from charmhelpers
from charmhelpers.contrib.openstack.utils import get_host_ip
To get IP addresses of all units of charms, you have to add peer relation. You can read about relations from here

Related

Change multiples IP and MAC with tcprewrite

I'm working with tcpreplay and I have a question. Let's say I have three hosts on the same network, for example 172.16.25.0/24. While these hosts exchange messages with each other, I capture the data on the interface of one of them through tcpdump, generating a .pcap file. How do I change the IP and MAC addresses of the three hosts using tcprewrite?
Following the changes I want to achieve:
172.16.25.151 (00:00:00:00:00:a1) -> 10.10.10.151 (00:00:00:00:00:51)
172.16.25.152 (00:00:00:00:00:b1) -> 10.10.10.152 (00:00:00:00:00:52)
172.16.25.153 (00:00:00:00:00:c1) -> 10.10.10.153 (00:00:00:00:00:53)
For the cache file:
tcpprep --auto=bridge --pcap=ping.pcap --cachefile=case1.cache
My problem is when I try rewrite the endpoints MAC address.
I used:
tcprewrite --endpoints=172.16.25.151:172.16.25.152 --enet-smac=00:00:00:00:00:a1,00:00:00:00:00:51 --enet-dmac=00:00:00:00:00:b1,00:00:00:00:00:52 -i ping.pcap -o ping.pcap-rw-mac.pcap --cachefile=case1.cache
And this replace all flows with 00:00:00:00:00:51,172.16.25.151->00:00:00:00:00:52,172.16.25.152, inclusive those with the host_153.
What am I doing wrong?

Is any way to start go_binary before java_test?

Our project has a few GRPC servers defined as go_binary targets. We develop client SDKs for Java and Python applications and we would like to use java_test and py_test. Is any way to start a specific go_binary target before java_test or py_test?
You can create a test harness that starts the gRPC server before running the tests. For example, you could add the binary to the data attribute of the test, and then started it beforehand:
go_binary(
name = "my_grpc_server",
[...]
)
py_test(
name = "my_test",
[...]
data = [":my_grpc_server"],
)
and then inside the test file:
class ClientTestCase(unittest.TestCase):
def setUp(self):
r = runfiles.Create()
self.server = subprocess.Popen([r.Rlocation("path/to/my_grpc_server")])
def tearDown(self):
self.server.terminate()
self.server.wait()
This example is very simple, you'll probably run into issues regarding the availability of the port the server listens on, or waiting for the server to start up. You could add flags to your gRPC server to allow communication over a domain socket, or make it listen on an unused port and have the test parse the port number from the server's log output.
For details on finding the server with runfiles: https://github.com/bazelbuild/bazel/blob/a7a0d48fbeb059ee60e77580e5d05baeefdd5699/tools/python/runfiles/runfiles.py#L16-L58
If you find yourself copy-pasting this pattern a lot, or having to implement it in multiple languages, you could try using an sh_test() rule to wrap the underlying py_test or java_test, and to start the server, then start the test with an environment variable telling it how to reach the server (eg MY_GRPC_SERVER_ADDRESS=localhost:${test_port}.

Change default freeradius auth and acct port in CoovaChilli

So I have two freeradius / radiusdesk installations on the server.
First one is old one and uses default freeradius ports: 1812/1813 for Auth/Acct.
The second one is the new once and using ports: 10001/10002 for Auth/Acct.
The issue now is that on my router, CoovaChili is always connection to the first one ( old one ) and communicating on the ports 1812/1813. I want to change it's ports. But it doesn't seems to be working. The OS is OpenWrt.
In my /etc/config/chilli i have added the following lines:
option radiusauthport 10001
option radiusacctport 10002
But is is not working. CoovaChilli still sends request to the old 1812/1813 ports. I want to know how to change that so it communicates with my defined port numbers, rather than the default ones.
Looking for the configurations to fix it.
Thanks
Looking at the OpernWRT guide at https://openwrt.org/docs/guide-user/services/captive-portal/wireless.hotspot.coova-chilli, it seems that you need to put the value parameter inside double quotes.
Specifically
option radiusauthport "10001"
option radiusacctport "10002

How to obtain bluetooth port direction with pyserial?

I'm trying to connect to an RN42, module through python. When the RN42 pairs with W10 it creates two virtual COM ports(outgoing and incoming). I need to connect to the outgoing port.
I'm trying to do this automatically. I've tried:
import serial
import serial.tools.list_ports as port_lst
ports = list(port_lst.comports())
bluetooth_ports = []
for p in ports:
if 'Bluetooth' in p.description:
bluetooth_ports += [p.device]
bluetooth_com = serial.Serial(bluetooth_ports[0],115200)
I thought that the first port was usually the outgoing one, but I've paired the module to another computer, and this didn't apply (the second port was the outgoing one). Is there a way to find out the direction of the COM ports?
Thanks!!!
Although this is an antique question, I have been searching for the answer to this for some time myself and since I finally figured it out I wanted others to be able to find the answer. With help from a blog entry at in the hand and its accompanying gist:
The trick is to acquire the hwid using pySerial, then parse the address. The incoming port in a pair has an address of zero and the outgoing port has a nonzero address. Here is some ugly Python code that decodes it:
import serial.tools.list_ports
cp=serial.tools.list_ports.comports()
for p in cp:
if "BTHENUM" in p.hwid:
start_of_address=p.hwid.rfind("&")
end_of_address=p.hwid.rfind("_")
address=p.hwid[start_of_address+1:end_of_address]
if int(address,16)==0:
port_type="incoming"
else:
port_type="outgoing"
print(p.hwid)
print(p.name, address, port_type)
And the output:
BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&CC47540&0&000000000000_000000A8
COM4 000000000000 incoming
BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&CC47540&0&209BA5420081_C00000000
COM5 209BA5420081 outgoing

OpenWrt/network - Configuring dnsmasq for ad-blocking fails with "bad address at"

Trying to get ad blocking working in OpenWrt router firmware 10.03.1
I've prepared a file /etc/hosts.ads contain harmless entries like
address=/eviladserver1.com/127.0.0.1
address=/eviladserver2.com/127.0.0.1
in /etc/dnsmasq.conf I added the following line:
addn-hosts=/etc/hosts.ads
and restarted dnsmasq.
Now on restart I see the log being filled with error messages:
Jun 3 22:52:33 OpenWrt daemon.err dnsmasq[13056]: bad address at /etc/hosts.ads line 1
about every single line in the hosts.ads
I googled it but with no luck. Everything seems right syntax-wise, why the dnsmasq does not like it?
(all lines in hosts.ads end with [LF] only)
Appropriate format for /etc/hosts.ads is a standard HOSTS format such as:
127.0.0.1 eviladserver1.com
127.0.0.1 eviladserver2.com
Look at my implementation of adblock for OpenWRT at http://jazz.tvtom.pl/adblock-w-openwrt/ (polish).
Per the dnsmasq documentation, addn-hosts= specifies additional addresses in /etc/hosts format. It looks like you're trying to add an additional dnsmasq configuration file instead. For that, you want conf-file= to specify the file directly, or you want to put the file in a directory specified by conf-dir=.

Resources