From nobody Fri May 16 07:15:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498583293067882.9351086504018; Tue, 27 Jun 2017 10:08:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D16F43DBEB; Tue, 27 Jun 2017 17:08:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9268517100; Tue, 27 Jun 2017 17:08:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0403C3FADE; Tue, 27 Jun 2017 17:08:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RH3aK9026662 for ; Tue, 27 Jun 2017 13:03:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id E19BD17CC0; Tue, 27 Jun 2017 17:03:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9FEA95341 for ; Tue, 27 Jun 2017 17:03:34 +0000 (UTC) Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49467FB9F for ; Tue, 27 Jun 2017 17:03:31 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id z6so5500969pfk.3 for ; Tue, 27 Jun 2017 10:03:31 -0700 (PDT) Received: from venkat-ThinkPad-E450.domain.name ([103.69.20.53]) by smtp.gmail.com with ESMTPSA id y72sm5825455pfk.72.2017.06.27.10.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jun 2017 10:03:29 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D16F43DBEB Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D16F43DBEB Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o90XwJeu" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 49467FB9F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nhvenkatdatta@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 49467FB9F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pGkix35BTJUCp1T60InwwAwZl5owa2pF+9Svw/JkqU8=; b=o90XwJeu2BRhL3CWcCPU9kwNr33Wt6GELYl42IcXiSYgGm6Q1RqkcSVSeKEc6EbzNQ z1wm6q47QhWTQI7AZj1x/Wq8YXXSTZl46U8It4vsDs1RHXTje+9DyTfz1hECHM3kLH6h +jt2N9fcoLYSSHSS0RBQft3QbWYLnJn2BeGF1JhnjyfhQfhAhj8sSPEDVgvQiF8eIo1g dRe/pyaFcHN0YvuDT3rch0Tbmz6agpndz+59IdePlRuAcxDRHn+x5/c+If1ZfH/PiEDW KiGx7O2IlDvg1wuXoIRcGOsDdyo4LFSABJ8fkU0xnRKJam+tMyZL670euWGQBj4KFqaE +KSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pGkix35BTJUCp1T60InwwAwZl5owa2pF+9Svw/JkqU8=; b=MBwFfjBpRVfZbgRGZ1QSW2rIqDIvTfeNwOOYArvoTzEblulF9Ho2vQhL7mMOvv8M5s OW/FDZauTVTzk3XLw4MxJNNJBbCgvXgnlU5xBIZBGkG+Pze8Jk5TkVTv05+l2Wamqsbu f/lIBowqDutXPl+hk1MQiTJ5T4g+RprpmXIZGFEFkXZzZF2jLVTOCqoOaQTP2nxUVnb0 EhX+61IP8yqlWTM9IyrY8XpmjGND1KEjjsbz+KnoAoPx4+giWsXIL5h0yGRdnTqvRYSt /Y2s/c9BUs/pz/aesRIy7f9nutkkmF3WLu6ADY/e8RgSkArM1putTa68W8epVyVGJiQW Ykgw== X-Gm-Message-State: AKS2vOxxP2p1HwJJgOH5/aUIg6/0xUzXkCEH+5lNtE3JYZf2go5PAGQJ OGt4diceEBhs8iWq X-Received: by 10.98.43.7 with SMTP id r7mr6183039pfr.202.1498583010165; Tue, 27 Jun 2017 10:03:30 -0700 (PDT) From: Venkat Datta N H To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 22:32:42 +0530 Message-Id: <1498582962-12970-3-git-send-email-nhvenkatdatta@gmail.com> In-Reply-To: <1498582962-12970-1-git-send-email-nhvenkatdatta@gmail.com> References: <1498582962-12970-1-git-send-email-nhvenkatdatta@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 27 Jun 2017 17:03:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 27 Jun 2017 17:03:31 +0000 (UTC) for IP:'209.85.192.196' DOMAIN:'mail-pf0-f196.google.com' HELO:'mail-pf0-f196.google.com' FROM:'nhvenkatdatta@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.247 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.192.196 mail-pf0-f196.google.com 209.85.192.196 mail-pf0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Venkat Datta N H Subject: [libvirt] [PATCHv2 2/2] lxc: add support for docker-json command conversion X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Jun 2017 17:08:09 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Docker Json command is split between entrypoint and command properties. Com= pute a command out of those to fit the LXC container XML configuration. --- src/lxc/lxc_docker.c | 65 ++++++++++++++++++= ++++ .../lxcdocker2xmldata-command.json | 47 ++++++++++++++++ .../lxcdocker2xmldata-command.xml | 17 ++++++ tests/lxcdocker2xmltest.c | 1 + 4 files changed, 130 insertions(+) create mode 100644 tests/lxcdocker2xmldata/lxcdocker2xmldata-command.json create mode 100644 tests/lxcdocker2xmldata/lxcdocker2xmldata-command.xml diff --git a/src/lxc/lxc_docker.c b/src/lxc/lxc_docker.c index dbb2a81..b3e25f7 100644 --- a/src/lxc/lxc_docker.c +++ b/src/lxc/lxc_docker.c @@ -70,12 +70,70 @@ static int virLXCDockerParseMem(virDomainDefPtr dom, return 0; } =20 +struct virLXCDockerCmdArgsIteratorArgs { + virDomainDefPtr vmdef; + size_t ninitargs; +}; + +static int virLXCDockerCmdArgsIterator(size_t pos ATTRIBUTE_UNUSED, + virJSONValuePtr item, + void *opaque) +{ + struct virLXCDockerCmdArgsIteratorArgs *args =3D opaque; + const char *value =3D virJSONValueGetString(item); + + if (!args->vmdef->os.init) { + if (VIR_STRDUP(args->vmdef->os.init, value) < 0) + return -1; + else + return 1; + } + + if (VIR_EXPAND_N(args->vmdef->os.initargv, args->ninitargs, 1) < 0) + return -1; + + if (VIR_STRDUP(args->vmdef->os.initargv[args->ninitargs - 1], value) <= 0) + return -1; + + return 1; +} + + +static int virLXCDockerBuildInitCmd(virDomainDefPtr vmdef, + virJSONValuePtr config) +{ + virJSONValuePtr entry_point =3D virJSONValueObjectGetArray(config, "En= trypoint"); + virJSONValuePtr command =3D virJSONValueObjectGetArray(config, "Cmd"); + struct virLXCDockerCmdArgsIteratorArgs iterator_args =3D { vmdef, 0 }; + + if (entry_point && virJSONValueArrayForeachSteal(entry_point, + &virLXCDockerCmdArgsI= terator, + &iterator_args) < 0) + goto error; + + if (command && virJSONValueArrayForeachSteal(command, + &virLXCDockerCmdArgsItera= tor, + &iterator_args) < 0) + goto error; + + /* Append NULL element at the end */ + if (iterator_args.ninitargs > 0 && + VIR_EXPAND_N(vmdef->os.initargv, iterator_args.ninitargs, 1) < 0) + goto error; + + return 0; + + error: + return -1; +} + virDomainDefPtr virLXCDockerParseJSONConfig(virCapsPtr caps ATTRIBUTE_UNUS= ED, virDomainXMLOptionPtr xmlopt, const char *config) { virJSONValuePtr json_obj; virJSONValuePtr host_config; + virJSONValuePtr docker_config; =20 if (!(json_obj =3D virJSONValueFromString(config))) return NULL; @@ -101,6 +159,13 @@ virDomainDefPtr virLXCDockerParseJSONConfig(virCapsPtr= caps ATTRIBUTE_UNUSED, } } =20 + if ((docker_config =3D virJSONValueObjectGetObject(json_obj, "Config")= ) !=3D NULL) { + if (virLXCDockerBuildInitCmd(def, docker_config) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to pars= e Command")); + goto error; + } + } + def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_UTC; def->onReboot =3D VIR_DOMAIN_LIFECYCLE_RESTART; def->onCrash =3D VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY; diff --git a/tests/lxcdocker2xmldata/lxcdocker2xmldata-command.json b/tests= /lxcdocker2xmldata/lxcdocker2xmldata-command.json new file mode 100644 index 0000000..14e4d92 --- /dev/null +++ b/tests/lxcdocker2xmldata/lxcdocker2xmldata-command.json @@ -0,0 +1,47 @@ +{ + "Id": "618a2e773b84976ca2736e443a0c98eeeecdcfb2584e3dab1a3cafa313a= 936da", + "Created": "2017-06-07T00:46:07.149971669Z", + "Path": "/bin/ping", + "Args": [ + "localhost" + ], + "HostConfig": { + "LogConfig": { + "Type": "json-file", + "Config": {} + }, + "NetworkMode": "default", + "PortBindings": {}, + "RestartPolicy": { + "Name": "no", + "MaximumRetryCount": 0 + }, + "ShmSize": 67108864, + "CpuShares": 0, + "Memory": 0, + "MemorySwap": 0, + "MemorySwappiness": -1, + "CpuCount": 0, + "CpuPercent": 0, + "IOMaximumBandwidth": 0 + }, + "GraphDriver": { + "Name": "aufs", + "Data": null + }, + "Mounts": [], + "Config": { + "Hostname": "618a2e773b84", + "Domainname": "", + "User": "", + "Cmd": [ + "/bin/ping", + "localhost" + ], + "WorkingDir": "", + "Entrypoint": null, + "OnBuild": null, + "Labels": {} + } + +} diff --git a/tests/lxcdocker2xmldata/lxcdocker2xmldata-command.xml b/tests/= lxcdocker2xmldata/lxcdocker2xmldata-command.xml new file mode 100644 index 0000000..52155d1 --- /dev/null +++ b/tests/lxcdocker2xmldata/lxcdocker2xmldata-command.xml @@ -0,0 +1,17 @@ + + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 0 + 0 + 0 + + exe + /bin/ping + localhost + + + destroy + restart + destroy + + + diff --git a/tests/lxcdocker2xmltest.c b/tests/lxcdocker2xmltest.c index ccac4c4..dc7778a 100644 --- a/tests/lxcdocker2xmltest.c +++ b/tests/lxcdocker2xmltest.c @@ -129,6 +129,7 @@ mymain(void) } while (0) =20 DO_TEST("simple", true); + DO_TEST("command", true); =20 virObjectUnref(xmlopt); virObjectUnref(caps); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list