Skip to content

[WIP ]VR agent #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

package org.apache.cloudstack.agent;

import org.apache.cloudstack.api.command.admin.agent.LivePatchCmd;

public interface ApplianceAgentService {
String livePatch(LivePatchCmd cmd);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

package org.apache.cloudstack.api.command.admin.agent;


import javax.inject.Inject;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.agent.ApplianceAgentService;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.SystemVmResponse;

import com.cloud.user.Account;
import com.google.common.base.Strings;

@APICommand(name = LivePatchCmd.APINAME,
description = "Live Patches Appliance Agent",
responseObject = SuccessResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
since = "4.13.0",
authorized = {RoleType.Admin})
public class LivePatchCmd extends BaseCmd {
public static final String APINAME = "livePatch";

@Inject
ApplianceAgentService applianceAgentService;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = true, entityType = SystemVmResponse.class,
validations = {ApiArgValidator.PositiveNumber},
description = "The ID of the system VM appliance to live patch")
private Long id;

@Parameter(name = ApiConstants.TOKEN, type = CommandType.STRING,
description = "Ping token")
private String token;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public Long getId() {
return id;
}

public String getToken() {
return token;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

@Override
public void execute() {
String reply = applianceAgentService.livePatch(this);
SuccessResponse response = new SuccessResponse();
response.setDisplayText(reply);
response.setSuccess(!Strings.isNullOrEmpty(reply));
response.setResponseName(getCommandName());
setResponseObject(response);
}
}
34 changes: 34 additions & 0 deletions framework/appliance-agent/agent/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Virtual Appliance Agent
package main

import (
"context"
"log"
"net"

"google.golang.org/grpc"
pb "./virtualappliance"
)

const (
port = ":8200"
)

type server struct{}

func (s *server) Ping(ctx context.Context, in *pb.PingRequest) (*pb.PingResponse, error) {
log.Printf("Received: %v", in.Message)
return &pb.PingResponse{Message: "Pong " + in.Message}, nil
}

func main() {
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterApplianceAgentServer(s, &server{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
37 changes: 37 additions & 0 deletions framework/appliance-agent/agent/testclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"context"
"log"
"os"
"time"

"google.golang.org/grpc"
pb "./virtualappliance"
)

const (
address = "localhost:50051"
defaultName = "client123"
)

func main() {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewApplianceAgentClient(conn)

name := defaultName
if len(os.Args) > 1 {
name = os.Args[1]
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.Ping(ctx, &pb.PingRequest{Message: name})
if err != nil {
log.Fatalf("could not ping due to: %v", err)
}
log.Printf("Pinging: %s", r.Message)
}
Loading