libvirt API for domain migration - libvirt

Libvirt provide way to migrate guest domain, syntax as follows:
syntax: virsh migrate GUESTNAME DEST-LIBVIRT-URI [HV-URI
I am wondering whether there's API to migrate?
Thanks

From doc:
virDomainPtr virDomainMigrate (virDomainPtr domain,
virConnectPtr dconn,
unsigned long flags,
const char * dname,
const char * uri,
unsigned long bandwidth)
Migrate the domain object from its current host to the destination
host given by dconn (a connection to the destination host).
Click the link for details.

Related

Error reading credential file from location in xamarin.forms while connecting to Cloud Firestore

I am developing a mobile application in xamarin.forms. I will use Google CloudFirestore as Cloud Database. When I want to connect to the database, I get the following error:
One or more errors occurred. (Error reading credential file from location D:\ yemekbagisiyapbucak.json: Could not find file "/D:\ yemekbagisiyapbucak.json"
Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS)
public static FirestoreDb db;
path = "D:\\yemekbagisiyapbucak.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
db = FirestoreDb.Create("yemekbagisiyapbucak");
At first, please make sure the .josn file is in the path you set. var path = Path.Combine(FileSystem.AppDataDirectory, "yemekbagisiyapbucak.json"); get different path on different platforms.
So you can debug it and check the value of the path, and then copy the .josn file to the path.
If you need more information, please check the following link:Connecting to Google cloud firestore in a cross platform mobile app (xamarin c#)

ejabberd: How to use "ldap_tls_certfile"

According to the ejabberd docs, you can use ldap_tls_certfile in order to verify the TLS connection to the LDAP server. But which certificate is expected here?
Quoting the docs:
A path to a file containing PEM encoded certificate along with PEM
encoded private key. This certificate will be provided by ejabberd
when TLS enabled for LDAP connections. There is no default value,
which means no client certificate will be sent.
Sooo.... I tried to use a concatenated PEM file containing first the host certificate of the ejabberd server, then second the host key. But this leads to the following errors:
<0.471.0>#eldap:connect_bind:1073 LDAP connection to
ldap1.example.com:636 failed: received CLIENT ALERT: Fatal - Handshake
Failure - {bad_cert,hostname_check_failed}
<0.1975.0> TLS client: In state certify at ssl_handshake.erl:1372 generated CLIENT ALERT: Fatal - Handshake Failure - {bad_cert,hostname_check_failed}
This obviously is not what is expected. Is it the public certificate of the LDAP server? But then, what private key is expected?
I'm a bit lost here. Anyone mind to lend me a hand?
Disclaimer: I never used LDAP TLS.
Looking at the ejabberd source code, the value of ejabberd's option ldap_tls_certfile
is copied into eldap's option tls_certfile
https://github.com/processone/ejabberd/blob/e4d600729396a8539e48ac0cbd97ea1b210941cd/include/eldap.hrl#L72
And later the value of eldap's tls_certfile is copied into ssl's option certfile
https://github.com/processone/ejabberd/blob/e4d600729396a8539e48ac0cbd97ea1b210941cd/src/eldap.erl#L580
That option, among others, is provided as an argument when calling ssl:connect/4
https://github.com/processone/ejabberd/blob/e4d600729396a8539e48ac0cbd97ea1b210941cd/src/eldap.erl#L1140
So, the option that you set in ejabberd is named 'certfile' in ssl:connect, you can see here its documentation:
https://erlang.org/doc/man/ssl.html#connect-4
Searching for certfile in that page, it shows this description:
Path to a file containing the user certificate on PEM format.
Is it the public certificate of the LDAP server?
Try that one and comment here.
But then, what private key is expected?
Try not putting any private key. In any case, when the LDAP certificate was created, it produced a private key file, too.

How to Support SSL in Airflow MySQLHook (in particular AWS 2019CA)

I have been using MySQLHook happily in my Airflow DAG but now the MySQL server (AWS RDS) will have SSL connection mandatory. My backend engineer told me that in particular AWS 2019 CA should be used. I looked into the MySQLHook documentation and found the following snippet from https://airflow.readthedocs.io/en/stable/_modules/airflow/hooks/mysql_hook.html:
if conn.extra_dejson.get('ssl', False):
# SSL parameter for MySQL has to be a dictionary and in case
# of extra/dejson we can get string if extra is passed via
# URL parameters
dejson_ssl = conn.extra_dejson['ssl']
if isinstance(dejson_ssl, six.string_types):
dejson_ssl = json.loads(dejson_ssl)
conn_config['ssl'] = dejson_ssl
It looks like I need to specify some configuration in the form of JSON ("SSL" key) in the extra section of the MySQL connection in Airflow but I couldn't find any examples of this. Can someone enlighten me? Any pointer or an example of such JSON would be very appreciated.
Your Connection.extra data should be a JSON string containing a ssl object suitable for passing to the mysql_ssl_set function, according to the "Functions and attributes" section on this page:
This parameter takes a dictionary or mapping, where the keys are parameter names used by the mysql_ssl_set MySQL C API call. If this is set, it initiates an SSL connection to the server; if there is no SSL support in the client, an exception is raised. This must be a keyword parameter.
Presumably something like this would work: {"ssl": {"cert": "PATH TO YOUR PUBLIC CERT FILE ON THE AIRFLOW SERVER"}}

Unable to connect to MySQL from Ballerina.io on Mac OS X

I want to build a simple app that connects to remote MySQL server. However, I can't make it work.
import ballerina/io;
import ballerina/jdbc;
import ballerina/mysql;
endpoint jdbc:Client jiraDB {
host: "jdbc:mysql://DB-SERVER:3306/jira",
username: "jira",
password: "PWD",
poolOptions: { maximumPoolSize: 5 }
};
type Domain record {
string domain,
string jira,
};
function main(string... args) {
var ret = jiraDB->select("SELECT * FROM `domains`", ());
table domainTable;
match ret {
table tableReturned => domainTable = tableReturned;
error e => io:println("Select data from domains table failed: " + e.message);
}
while(domainTable.hasNext()) {
var domain = <Domain>domainTable.getNext();
match domain {
Domain d => io:println("Domain: " + d.domain);
error e => io:println("Error in get employee from table: "
+ e.message);
}
}
}
The structure of MySQL is not really important. I think it has to do with missing / wrongly used JDBC/MySQL library.
Do you please have any ideas how to make it work on Mac OS X ?
$ ballerina run hello.bal
error: ballerina/runtime:CallFailedException, message: call failed
at ..<stop>(hello.bal:5)
caused by error
at ballerina/jdbc:stop(endpoint.bal:66)
I'm using latest Mac OS X with:
$ ballerina --version
Ballerina 0.980.1
First, the latest ballerina version is 0.981.0. It would be great if you could use the latest version since it would include latest bug fixes and improvements.
In Ballerina, there is a generic jdbc client which can be used to connect to any database which has a jdbc driver. In addition, for mysql and h2 there are two clients implemented specifically for those two databases.
When connecting to mysql, you could either use the generic jdbc client or the mysql specific client. The recommendation is to use the mysql specific client.
In your code snippet, I can see you are using jdbc client. As Anoukh mentioned above, the endpoint configuration is incorrect.
Following is a sample configuration for generic jdbc client endpoint.
endpoint jdbc:Client testDB {
url: "jdbc:mysql://localhost:3306/testdb",
username: "user1",
password: "pass1",
poolOptions: { maximumPoolSize: 5 }
};
And following is a sample configuration of mysql client endpoint.
endpoint mysql:Client testDB {
host: "localhost",
port: 3306,
name: "testDB",
username: "user1",
password: "pass1",
poolOptions: { maximumPoolSize: 5 }
};
In order to use either of the clients, you need to copy the mysql jdbc driver to ${BALLERINA_HOME}/bre/lib.
Even after correcting your configuration and copying the driver, if you still face the issue, please check whether file named ballerina-internal.log is created where you are running your bal file and share. Also please share the mysql database and driver version you are using.
Have you copied the MySQL JDBC driver to the BALLERINA_HOME/bre/lib folder?
You can find the ballerina home using which ballerina command.
You can download the mysql jdbc driver from http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
The issue might be in the jiraDB endpoint configurations. As per the API docs, the config for the URL of the database is to be given as url instead of host.
I was not able to connect to Mysql and I faced a driver instance error. I solved it! I'm not sure to post my answer at the good place but I think it will be a good resource to fix some problems with Mysql connections issues in Ballerina.
In my terminal : echo $BALLERINA_HOME
/Library/Ballerina/ballerina-0.990.2
Copy the good jar in the right place !
Go to : http://central.maven.org/maven2/mysql/mysql-connector-java/
I have downloaded the latest stable version (at the time of writing 8.0.15).
Copy the jar in $BALLERINA_HOME/bre/lib/
I had an error with a prior version.
Be careful that your jar have the right extension (the .jar not the repository with the same name).
Also be sure to have fulfilled the recommandations (see the doc of Oracle when installing a jar, i.e setting the classpath)
In your terminal, set the class path :
export CLASSPATH=$CLASSPATH:/Library/Ballerina/ballerina-0.990.2/bre/lib/mysql-connector-java-8.0.15
Then it will work !

Not able to create accounts for Private Ethereum Blockchain using Geth and Web3 API

I am unable to create accounts for Private Ethereum Blockchain using Geth and Web3 API.
personal.newAccount(passwd) is not working for me. Please explain how to create account using above command.
And also, I am unable to install "ethereumjs-accounts".
If you try to search the internet why the "geth json rpc personal api" is not working, you will find an excellent answer on Ethereum Stack Exchange which I'd like to quote in full:
First, a note on safety:
You should not make the personal API available over RPC
If you are on a local, trusted machine, you should use IPC instead of RPC. Otherwise, anyone who can connect to your node via RPC can try to brute-force your passwords and steal your Ether.
All administrative APIs are available by default over IPC, so no need to use any flags with geth
To connect via IPC:
Install my library:
npm install web3_extended
var web3_extended = require('web3_extended');
var options = {
host: '/home/user/.ethereum/geth.ipc',
ipc:true,
personal: true,
admin: false,
debug: false
};
var web3 = web3_extended.create(options);
web3.personal.newAccount("password",function(error,result){
if(!error){
console.log(result);
}
});
Replace the host variable with the proper path for your system.
Note: All requests via IPC must be asynchronous.
Some Alternatives:
I don't know why you want to create new accounts via web3, but it's likely not the best way to do what you're trying to achieve. It is much safer and more modular to use a hooked web3 provider with a client-side light wallet or to simply use the Mist browser which handles all accounts for you.
Now for the technique (don't do this)
You need to enable the personal API over RPC. Do this by starting geth with
geth --rpc --rpcapi "db,eth,net,web3,personal"
Then you can use the personal_newAccount method via RPC. It's not implemented in web3.js, so you need to manually issue the RPC request. For example with curl:
curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["password"],"id":1}' localhost:8545
creates a new account with password password and returns the address:
{"id":1,"jsonrpc":"2.0","result":"0x05ca0ddf7e7506672f745b2b567f1d33b7b55f4f"}
There is some basic documentation
Alternatively:
Use the unofficial extended web3.js
this allows you to use the personal, admin and miner APIs via a standard web3.js interface.
Published on Feb 16 at 8:34 and released under terms of CC BY-SA 3.0 by Tjaden Hess.
The command must be personal.newAccount()
Then the console asks for passphrase, give your required password then it again asks for confirmation.
An output in the form of Address("0x----------------------------") will appear.It is 1 account/address for your private network.