Skip to content

Commit

Permalink
Merge branch 'master' into gabe-416-default-address-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Conradi committed Mar 14, 2017
2 parents 64dd543 + 1d8997e commit ac0dfa1
Show file tree
Hide file tree
Showing 17 changed files with 519 additions and 36 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ _site
RUNNING_PID
conf/solr/cores/collins/data
.DS_Store
Gemfile.lock

.cache-main
.cache-tests
Expand Down
13 changes: 8 additions & 5 deletions app/collins/models/LshwHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ object LshwHelper extends CommonHelper[LshwRepresentation] {
val baseDescription = amfinder(seq, BaseDescription, _.toString, "")
val baseProduct = amfinder(seq, BaseProduct, _.toString, "")
val baseVendor = amfinder(seq, BaseVendor, _.toString, "")
val baseSerial = amfinder(seq, BaseSerial, _.toString, "")
val baseSerial = amfinder(seq, BaseSerial, x => if (x.isEmpty) { None } else { Some(x) }, None)
Seq(ServerBase(baseDescription, baseProduct, baseVendor, baseSerial))
}.getOrElse(Nil)

val filteredMeta = meta.map { case(groupId, metaSeq) =>
val newSeq = filterNot(
metaSeq,
Set(BaseDescription.id, BaseProduct.id, BaseVendor.id)
Set(BaseDescription.id, BaseProduct.id, BaseVendor.id, BaseSerial.id)
)
groupId -> newSeq
}
Expand All @@ -229,12 +229,15 @@ object LshwHelper extends CommonHelper[LshwRepresentation] {

protected def collectBase(asset: Asset, lshw: LshwRepresentation): Seq[AssetMetaValue] = {
val base = lshw.base
Seq(
val expectedAttrs = Seq(
AssetMetaValue(asset, BaseDescription.id, base.description),
AssetMetaValue(asset, BaseProduct.id, base.product),
AssetMetaValue(asset, BaseVendor.id, base.vendor),
AssetMetaValue(asset, BaseSerial.id, base.serial)
AssetMetaValue(asset, BaseVendor.id, base.vendor)
)
base.serial match {
case Some(x) => expectedAttrs ++ Seq(AssetMetaValue(asset, BaseSerial.id, base.serial.get))
case None => expectedAttrs
}
}

}
4 changes: 2 additions & 2 deletions app/collins/models/lshw/ServerBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object ServerBase {
(json \ "DESCRIPTION").as[String],
(json \ "PRODUCT").as[String],
(json \ "VENDOR").as[String],
(json \ "SERIAL").as[String]))
(json \ "SERIAL").asOpt[String]))
override def writes(serverbase: ServerBase) = JsObject(Seq(
"DESCRIPTION" -> Json.toJson(serverbase.description),
"PRODUCT" -> Json.toJson(serverbase.product),
Expand All @@ -22,7 +22,7 @@ object ServerBase {
}

case class ServerBase(
description: String = "", product: String = "", vendor: String = "", serial: String = "") extends LshwAsset {
description: String = "", product: String = "", vendor: String = "", serial: Option[String] = None) extends LshwAsset {
import ServerBase._
override def toJsValue() = Json.toJson(this)

Expand Down
2 changes: 2 additions & 0 deletions app/collins/util/config/LldpConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ object LldpConfig extends Configurable {
override val referenceConfigFilename = "lldp_reference.conf"

def requireVlanName = getBoolean("requireVlanName", true)
def requireVlanId = getBoolean("requireVlanId", false)

override protected def validateConfig() {
requireVlanName
requireVlanId
}
}
15 changes: 10 additions & 5 deletions app/collins/util/parsers/LldpParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ class LldpParser(txt: String) extends CommonParser[LldpRepresentation](txt) {
}

protected def findVlans(seq: NodeSeq): Seq[Vlan] = {
// TODO(gabe): make this less brittle and handle missing vlan-id
(seq \\ "vlan").foldLeft(Seq[Vlan]()) {
// some switches don't report a vlan-id, despite a VLAN being configured
// on an interface. Lets be flexible here and allow it to be empty.
case (vseq, vlan) =>
val id = Option(vlan \ "@vlan-id" text).filter(_.nonEmpty).getOrElse("")
val idOpt = Option(vlan \ "@vlan-id" text).filter(_.nonEmpty)
val name = vlan.text
if (LldpConfig.requireVlanName) {
requireNonEmpty((id -> "vlan-id"), (name -> "vlan name"))
} else {
requireNonEmpty((id -> "vlan-id"))
requireNonEmpty((name -> "vlan name"))
}
Vlan(id.toInt, name) +: vseq
if (LldpConfig.requireVlanId) {
requireNonEmpty((idOpt.getOrElse("") -> "vlan id"))
}
val id = idOpt.map(_.toInt).getOrElse(0)
Vlan(id, name) +: vseq
}
}

Expand Down
5 changes: 3 additions & 2 deletions app/collins/util/parsers/LshwParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ class LshwParser(txt: String) extends CommonParser[LshwRepresentation](txt) {
// the correct element
if ((elem \ "@class" text).toString == "system") {
val asset = getAsset(elem)
val serial = (elem \ "serial" text)
// serial may be missing, so be flexible here and allow it to be absent
val serial = (elem \ "serial" headOption).map(_.text)
ServerBase(asset.description, asset.product, asset.vendor, serial)
} // To spice things up, sometimes we get <list>$everything</list>
// instead of just $everything
else if (((elem \ "node") \ "@class" text) == "system") {
val asset = getAsset(elem \ "node")
val serial = (elem \ "serial" text)
val serial = (elem \ "serial" headOption).map(_.text)
ServerBase(asset.description, asset.product, asset.vendor, serial)
} else {
throw MalformedAttributeException("Expected root class=system node attribute")
Expand Down
21 changes: 14 additions & 7 deletions app/views/asset/show_overview.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ <h3>Asset Overview <small>System and user attributes</small></h3>
}
@if(aa.addresses.size > 0) {
<tr>
<th>Ip Addresses</th>
<th><strong>IP Addresses</strong></th>
<td>@TagDecorator.decorate("IP_ADDRESS", aa.addresses.map(_.dottedAddress).toList, ", ")</td>
<td>Primary IP Addresses</td>
</tr>
}
<tr>
<th>Asset Tag</th>
<th>
<strong data-rel="tooltip" title="" data-original-title="TAG">Asset Tag</strong>
</th>
@if(SoftLayerConfig.enabled && SoftLayer.isSoftLayerAsset(aa.asset)) {
@slLink(aa.asset, aa.asset.tag)
} else {
Expand All @@ -40,7 +42,7 @@ <h3>Asset Overview <small>System and user attributes</small></h3>
</tr>
<tr>
@defining(aa.asset.nodeClass){ nodeclass =>
<th>Classification</th>
<th><strong>Classification</strong> <a href="https://tumblr.github.io/collins/configuration.html#node classifier"><i class="glyphicon glyphicon-question-sign" data-rel="tooltip" title="" data-original-title="Asset classification according to node classifier"></i></a></th>
<td>
<span>
@nodeclass.map { nc =>
Expand All @@ -60,12 +62,12 @@ <h3>Asset Overview <small>System and user attributes</small></h3>
}
</tr>
<tr>
<th>Asset Type</th>
<th><strong>Asset Type<strong> <a href="https://tumblr.github.io/collins/concepts.html#assets"><i class="glyphicon glyphicon-question-sign"></i></a></th>
<td>@aa.asset.assetType.label</td>
<td></td>
</tr>
<tr class="@statusClassFromAsset(aa.asset)">
<td><strong>Asset Status</strong></td>
<td><strong>Asset Status</strong> <a href="https://tumblr.github.io/collins/concepts.html#status & state"><i class="glyphicon glyphicon-question-sign"></i></a></td>
<td>@aa.asset.getStatusName</td>
@if(aa.asset.isMaintenance) {
<td><a href="#user-log-section"><span class="label label-primary">See Notes</span></a> @aa.asset.status.description</td>
Expand All @@ -76,7 +78,7 @@ <h3>Asset Overview <small>System and user attributes</small></h3>
@if(aa.asset.stateId != 0) {
@State.findById(aa.asset.stateId).map { state =>
<tr>
<th>Asset State</th>
<th><strong>Asset State</strong> <a href="https://tumblr.github.io/collins/concepts.html#status & state"><i class="glyphicon glyphicon-question-sign"></i></a></th>
<td>@state.label</td>
<td>@state.description</td>
</tr>
Expand All @@ -94,7 +96,12 @@ <h3>Asset Overview <small>System and user attributes</small></h3>
</tr>
@MetaValueOrderer.order(aa.mvs.filter(_.getName() != "HOSTNAME")).map { case(size, mv) =>
<tr>
<th>@mv.getLabel() @if(size > 1 || mv.getGroupId() != 0){(@mv.getGroupId())}</th>
<th>
<span @if(mv.getLabel().toUpperCase != mv.getName()){
data-rel="tooltip" title="" data-original-title="@mv.getName() @if(size > 1 || mv.getGroupId() != 0){(@mv.getGroupId())}"
}>@mv.getLabel() @if(size > 1 || mv.getGroupId() != 0){(@mv.getGroupId())}
</span>
</th>
<td>
@{
mv.getName match {
Expand Down
20 changes: 20 additions & 0 deletions conf/docker/permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ permissions:
- "g=infra"
- "g=ops"
- "g=sre"
feature.canWriteEncryptedTags:
- "u=admins"
controllers.Admin:
- "g=infra"
- "g=ops"
Expand Down Expand Up @@ -43,6 +45,12 @@ permissions:
- "g=sre"
- "u=admins"
- "u=tools"
controllers.AssetApi.updateAssetStatus:
- "g=infra"
- "g=ops"
- "g=sre"
- "u=admins"
- "u=tools"
controllers.AssetApi.updateAssetForMaintenance:
- "g=infra"
- "g=ops"
Expand Down Expand Up @@ -105,3 +113,15 @@ permissions:
- "g=platform"
- "u=admins"
- "u=tools"
controllers.IpmiApi.updateIpmi:
- "g=infra"
- "g=ops"
- "g=sre"
- "u=admins"
- "u=tools"
controllers.Firehose.stream:
- "g=infra"
- "g=ops"
- "g=sre"
- "u=admins"
- "u=tools"
3 changes: 3 additions & 0 deletions conf/reference/lldp_reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ lldp {
# Refuse to accept lldp information with no name (aka
# description)
requireVlanName = true
# allow VLANs to omit vlan-id, to support odd devices and layer 2
# deployments
requireVlanId = false
}
57 changes: 57 additions & 0 deletions support/ruby/collins-client/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
PATH
remote: .
specs:
collins_client (0.2.19)
httparty (~> 0.11.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
hashdiff (0.3.2)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
json (2.0.3)
multi_json (1.12.1)
multi_xml (0.6.0)
public_suffix (2.0.5)
rake (10.5.0)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
safe_yaml (1.0.4)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
webmock (1.24.6)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.9.8)

PLATFORMS
ruby

DEPENDENCIES
collins_client!
rake (~> 10.4)
rspec (~> 2.99)
simplecov (~> 0.10)
webmock (~> 1.21)
yard (~> 0.8)

BUNDLED WITH
1.13.6
2 changes: 1 addition & 1 deletion support/ruby/collins-notify/collins_notify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rdoc','~> 3.12')
s.add_development_dependency('bundler','>= 1.2.0')
s.add_development_dependency('simplecov','~> 0.9.1')
s.add_development_dependency('rake')
s.add_development_dependency('rake', '~> 10.5')

end

64 changes: 64 additions & 0 deletions support/ruby/collins-state/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
PATH
remote: .
specs:
collins_state (0.2.13)
collins_client (~> 0.2.7)
escape (~> 0.0.4)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
collins_client (0.2.19)
httparty (~> 0.11.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
escape (0.0.4)
hashdiff (0.3.2)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
json (2.0.3)
multi_json (1.12.1)
multi_xml (0.6.0)
public_suffix (2.0.5)
rake (10.5.0)
redcarpet (3.4.0)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
safe_yaml (1.0.4)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
webmock (1.24.6)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.8.7.6)

PLATFORMS
ruby

DEPENDENCIES
bundler
collins_state!
rake (~> 10.5)
redcarpet (~> 3.2)
rspec (~> 2.99)
simplecov
webmock (~> 1.21)
yard (~> 0.8.7)

BUNDLED WITH
1.13.6
6 changes: 3 additions & 3 deletions support/ruby/collins-state/collins_state.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'escape', '~> 0.0.4'

s.add_development_dependency 'rspec', '~> 2.99'
s.add_development_dependency 'yard'
s.add_development_dependency 'redcarpet'
s.add_development_dependency 'webmock'
s.add_development_dependency 'yard', '~> 0.8.7'
s.add_development_dependency 'redcarpet', '~> 3.2'
s.add_development_dependency 'webmock', '~> 1.21'
s.add_development_dependency 'bundler'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'rake', '~> 10.5'
Expand Down
Loading

0 comments on commit ac0dfa1

Please sign in to comment.