forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#525 from vladikr/virt-dhcp
Introduce virt-dhcp
- Loading branch information
Showing
12 changed files
with
985 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2017 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt, | ||
syscall.SIGQUIT, | ||
) | ||
|
||
fmt.Printf("Started fake dnsmasq process\n") | ||
|
||
timeout := time.After(60 * time.Second) | ||
select { | ||
case <-timeout: | ||
case <-c: | ||
time.Sleep(2 * time.Second) | ||
} | ||
|
||
fmt.Printf("Exit fake dnsmasq process\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# This file is part of the KubeVirt project | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Copyright 2017 Red Hat, Inc. | ||
# | ||
|
||
FROM fedora:26 | ||
|
||
MAINTAINER "The KubeVirt Project" <[email protected]> | ||
|
||
RUN dnf -y install dnsmasq | ||
|
||
COPY virt-dhcp /virt-dhcp | ||
|
||
ENTRYPOINT [ "/virt-dhcp" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2017 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
|
||
"kubevirt.io/kubevirt/pkg/log" | ||
dhcp "kubevirt.io/kubevirt/pkg/virt-dhcp" | ||
) | ||
|
||
const defaultDhcpSocket = "/var/run/kubevirt/virt_dhcp_sock" | ||
|
||
func main() { | ||
log.InitializeLogging("virt-dhcp") | ||
virtDhcpSocket := flag.String("virtdhcp-socket", defaultDhcpSocket, "Virt-DHCP socket.") | ||
if *virtDhcpSocket == "" { | ||
*virtDhcpSocket = defaultDhcpSocket | ||
} | ||
dhcp.Run(*virtDhcpSocket) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package virtdhcp | ||
|
||
import ( | ||
"fmt" | ||
"net/rpc" | ||
|
||
"kubevirt.io/kubevirt/pkg/log" | ||
) | ||
|
||
type VirtDHCPClient struct { | ||
client *rpc.Client | ||
} | ||
|
||
func GetClient() (*VirtDHCPClient, error) { | ||
conn, err := rpc.Dial("unix", DhcpSocket) | ||
if err != nil { | ||
log.Log.Reason(err).Errorf("client failed to connect to virt-dhcp socket: %s", DhcpSocket) | ||
return nil, err | ||
} | ||
|
||
return &VirtDHCPClient{client: conn}, nil | ||
} | ||
|
||
func (dhcp *VirtDHCPClient) AddIP(mac string, ip string, lease int) error { | ||
addArgs := &AddArgs{ip, mac, lease} | ||
addReply := &DhcpReply{} | ||
|
||
dhcp.client.Call("DHCP.AddIP", addArgs, addReply) | ||
if addReply.Success != true { | ||
msg := fmt.Sprintf("failed to add interface to dhcp, ip: %s, mac: %s - %s", ip, mac, addReply.Message) | ||
return fmt.Errorf(msg) | ||
} | ||
return nil | ||
} | ||
|
||
func (dhcp *VirtDHCPClient) RemoveIP(mac string, ip string) error { | ||
removeArgs := &RemoveArgs{ip, mac} | ||
removeReply := &DhcpReply{} | ||
|
||
dhcp.client.Call("DHCP.RemoveIP", removeArgs, removeReply) | ||
if removeReply.Success != true { | ||
msg := fmt.Sprintf("failed to remove interface from dhcp, ip: %s, mac: %s - %s", ip, mac, removeReply.Message) | ||
return fmt.Errorf(msg) | ||
} | ||
return nil | ||
} | ||
|
||
func (dhcp *VirtDHCPClient) SetIPs(hosts *[]AddArgs, reply *DhcpReply) error { | ||
addReply := &DhcpReply{} | ||
|
||
dhcp.client.Call("DHCP.SetIPs", hosts, addReply) | ||
if addReply.Success != true { | ||
msg := fmt.Sprintf("failed to set known hosts to dhcp: %s", addReply.Message) | ||
return fmt.Errorf(msg) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.