OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
docker_instance_adapter.cc
Go to the documentation of this file.
3 #include "oper/instance_task.h"
4 
6  if (docker_cmd_.length() == 0) {
7  return NULL;
8  }
9  std::stringstream cmd_str;
10  cmd_str << "sudo " << docker_cmd_ << " create";
11  cmd_str << " " << UuidToString(props.instance_id);
12  cmd_str << " --image " << props.image_name;
13 
14  if (props.vmi_inside != boost::uuids::nil_uuid()) {
15  cmd_str << " --vmi-left-id " << UuidToString(props.vmi_inside);
16  if (props.ip_prefix_len_inside != -1 && !props.ip_addr_inside.empty()) {
17  cmd_str << " --vmi-left-ip " << props.ip_addr_inside << "/";
18  cmd_str << props.ip_prefix_len_inside;
19  } else {
20  cmd_str << " --vmi-left-ip 0.0.0.0/0";
21  }
22  if (!props.mac_addr_inside.empty()) {
23  cmd_str << " --vmi-left-mac " << props.mac_addr_inside;
24  } else {
25  cmd_str << " --vmi-left-mac 00:00:00:00:00:00";
26  }
27  }
28  if (props.vmi_outside != boost::uuids::nil_uuid()) {
29  cmd_str << " --vmi-right-id " << UuidToString(props.vmi_outside);
30  if (props.ip_prefix_len_outside != -1 && !props.ip_addr_outside.empty()) {
31  cmd_str << " --vmi-right-ip " << props.ip_addr_outside << "/";
32  cmd_str << props.ip_prefix_len_outside;
33  } else {
34  cmd_str << " --vmi-right-ip 0.0.0.0/0";
35  }
36  if (!props.mac_addr_outside.empty()) {
37  cmd_str << " --vmi-right-mac " << props.mac_addr_outside;
38  } else {
39  cmd_str << " --vmi-right-mac 00:00:00:00:00:00";
40  }
41  }
42  if (props.vmi_management != boost::uuids::nil_uuid()) {
43  cmd_str << " --vmi-management-id " << UuidToString(props.vmi_management);
44  if (props.ip_prefix_len_management != -1 && !props.ip_addr_management.empty()) {
45  cmd_str << " --vmi-management-ip " << props.ip_addr_management << "/";
46  cmd_str << props.ip_prefix_len_management;
47  } else {
48  cmd_str << " --vmi-management-ip 0.0.0.0/0";
49  }
50  if (!props.mac_addr_management.empty()) {
51  cmd_str << " --vmi-management-mac " << props.mac_addr_management;
52  } else {
53  cmd_str << " --vmi-management-mac 00:00:00:00:00:00";
54  }
55  }
56 
57  if (!props.instance_data.empty()) {
58  cmd_str << " --instance-data " << props.instance_data;
59  }
60 
61  if (update) {
62  cmd_str << " --update";
63  }
64 
65 
66  return new InstanceTaskExecvp("NetNS", cmd_str.str(), START,
68 }
69 
71  if (docker_cmd_.length() == 0) {
72  return NULL;
73  }
74 
75  std::stringstream cmd_str;
76  cmd_str << "sudo " << docker_cmd_ << " destroy";
77  cmd_str << " " << UuidToString(props.instance_id);
78 
79  if (props.vmi_inside != boost::uuids::nil_uuid()) {
80  cmd_str << " --vmi-left-id " << UuidToString(props.vmi_inside);
81  }
82  if (props.vmi_outside != boost::uuids::nil_uuid()) {
83  cmd_str << " --vmi-right-id " << UuidToString(props.vmi_outside);
84  }
85  if (props.vmi_management != boost::uuids::nil_uuid()) {
86  cmd_str << " --vmi-management-id " << UuidToString(props.vmi_management);
87  }
88  return new InstanceTaskExecvp("NetNS", cmd_str.str(), STOP,
90 }
91 
95 }
InstanceTask * CreateStartTask(const ServiceInstance::Properties &props, bool update)
InstanceTask * CreateStopTask(const ServiceInstance::Properties &props)
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:138
bool isApplicable(const ServiceInstance::Properties &props)
boost::uuids::uuid instance_id
EventManager * event_manager() const
Definition: agent.h:1103
boost::uuids::uuid vmi_outside
boost::uuids::uuid vmi_management
boost::uuids::uuid vmi_inside